projects
/
project
/
libubox.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
df0968d
)
ustream: add a poll callback function defined by the ustream implementation
author
Felix Fietkau
<nbd@openwrt.org>
Mon, 29 Oct 2012 22:39:48 +0000
(23:39 +0100)
committer
Felix Fietkau
<nbd@openwrt.org>
Mon, 29 Oct 2012 22:39:48 +0000
(23:39 +0100)
ustream-fd.c
patch
|
blob
|
history
ustream.h
patch
|
blob
|
history
diff --git
a/ustream-fd.c
b/ustream-fd.c
index
c2e70db
..
6bb39e9
100644
(file)
--- a/
ustream-fd.c
+++ b/
ustream-fd.c
@@
-40,7
+40,7
@@
static void ustream_fd_set_uloop(struct ustream *s)
sf->fd.cb(&sf->fd, ULOOP_READ);
}
sf->fd.cb(&sf->fd, ULOOP_READ);
}
-static void ustream_fd_read_pending(struct ustream_fd *sf, bool *
updat
e)
+static void ustream_fd_read_pending(struct ustream_fd *sf, bool *
mor
e)
{
struct ustream *s = &sf->stream;
int buflen = 0;
{
struct ustream *s = &sf->stream;
int buflen = 0;
@@
-67,6
+67,7
@@
static void ustream_fd_read_pending(struct ustream_fd *sf, bool *update)
}
ustream_fill_read(s, len);
}
ustream_fill_read(s, len);
+ *more = true;
} while (1);
}
} while (1);
}
@@
-94,14
+95,14
@@
retry:
return len;
}
return len;
}
-static
void ustream_uloop_cb(struct uloop_fd *fd
, unsigned int events)
+static
bool __ustream_fd_poll(struct ustream_fd *sf
, unsigned int events)
{
{
- struct ustream_fd *sf = container_of(fd, struct ustream_fd, fd);
struct ustream *s = &sf->stream;
struct ustream *s = &sf->stream;
- bool update = false;
+ struct uloop_fd *fd = &sf->fd;
+ bool more = false;
if (events & ULOOP_READ)
if (events & ULOOP_READ)
- ustream_fd_read_pending(sf, &
updat
e);
+ ustream_fd_read_pending(sf, &
mor
e);
if (events & ULOOP_WRITE) {
if (ustream_write_pending(s))
if (events & ULOOP_WRITE) {
if (ustream_write_pending(s))
@@
-113,8
+114,23
@@
static void ustream_uloop_cb(struct uloop_fd *fd, unsigned int events)
ustream_fd_set_uloop(s);
ustream_state_change(s);
}
ustream_fd_set_uloop(s);
ustream_state_change(s);
}
+
+ return more;
}
}
+static bool ustream_fd_poll(struct ustream *s)
+{
+ struct ustream_fd *sf = container_of(s, struct ustream_fd, stream);
+
+ return __ustream_fd_poll(sf, ULOOP_READ);
+}
+
+static void ustream_uloop_cb(struct uloop_fd *fd, unsigned int events)
+{
+ struct ustream_fd *sf = container_of(fd, struct ustream_fd, fd);
+
+ __ustream_fd_poll(sf, events);
+}
static void ustream_fd_free(struct ustream *s)
{
static void ustream_fd_free(struct ustream *s)
{
@@
-134,5
+150,6
@@
void ustream_fd_init(struct ustream_fd *sf, int fd)
s->set_read_blocked = ustream_fd_set_uloop;
s->write = ustream_fd_write;
s->free = ustream_fd_free;
s->set_read_blocked = ustream_fd_set_uloop;
s->write = ustream_fd_write;
s->free = ustream_fd_free;
+ s->poll = ustream_fd_poll;
ustream_fd_set_uloop(s);
}
ustream_fd_set_uloop(s);
}
diff --git
a/ustream.h
b/ustream.h
index
29f370f
..
d9f98b7
100644
(file)
--- a/
ustream.h
+++ b/
ustream.h
@@
-101,6
+101,14
@@
struct ustream {
void (*set_read_blocked)(struct ustream *s);
/*
void (*set_read_blocked)(struct ustream *s);
/*
+ * poll: (optional)
+ * defined by the upstream implementation, called to request polling for
+ * available data.
+ * returns true if data was fetched.
+ */
+ bool (*poll)(struct ustream *s);
+
+ /*
* ustream user should set this if the input stream is expected
* to contain string data. the core will keep all data 0-terminated.
*/
* ustream user should set this if the input stream is expected
* to contain string data. the core will keep all data 0-terminated.
*/
@@
-182,4
+190,12
@@
static inline void ustream_state_change(struct ustream *s)
uloop_timeout_set(&s->state_change, 0);
}
uloop_timeout_set(&s->state_change, 0);
}
+static inline bool ustream_poll(struct ustream *s)
+{
+ if (!s->poll)
+ return false;
+
+ return s->poll(s);
+}
+
#endif
#endif