Add support for lwevent_wait() returning number of events
This commit is contained in:
parent
3e33062dc4
commit
a34063b32f
|
@ -72,7 +72,7 @@ int lwevent_init(void)
|
||||||
int lwevent_loop(void)
|
int lwevent_loop(void)
|
||||||
{
|
{
|
||||||
while(!lwevent_loop_exit) {
|
while(!lwevent_loop_exit) {
|
||||||
if(lwevent_wait(-1)) {
|
if(lwevent_wait(-1) == -1) {
|
||||||
if(errno == EINTR) continue;
|
if(errno == EINTR) continue;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ static void _lwevent_invalid(struct lwevent* ev)
|
||||||
*/
|
*/
|
||||||
int lwevent_wait(int timeout_ms)
|
int lwevent_wait(int timeout_ms)
|
||||||
{
|
{
|
||||||
int ret, i;
|
int ret, i, revents;
|
||||||
struct lwevent* ev;
|
struct lwevent* ev;
|
||||||
|
|
||||||
_lwevent_invalid_head = 0;
|
_lwevent_invalid_head = 0;
|
||||||
|
@ -123,13 +123,13 @@ int lwevent_wait(int timeout_ms)
|
||||||
ev = (struct lwevent*)(_lw_revents[i].data.ptr);
|
ev = (struct lwevent*)(_lw_revents[i].data.ptr);
|
||||||
if(ev->fd == -1) continue; /* skip invalid events */
|
if(ev->fd == -1) continue; /* skip invalid events */
|
||||||
|
|
||||||
ret = _lw_revents[i].events;
|
revents = _lw_revents[i].events;
|
||||||
if(ret & ev->autodestroy) {
|
if(revents & ev->autodestroy) {
|
||||||
lwevent_free(ev);
|
lwevent_free(ev);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ev->callback(ev, ret);
|
ev->callback(ev, revents);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free any invalid struct lwevent objects */
|
/* free any invalid struct lwevent objects */
|
||||||
|
@ -138,7 +138,9 @@ int lwevent_wait(int timeout_ms)
|
||||||
free(ev);
|
free(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/* TODO: possibly resize returned events array */
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,8 @@ int lwevent_loop(void);
|
||||||
|
|
||||||
\param timeout_ms A timeout, in milliseconds. This function will return as soon as any events occur,
|
\param timeout_ms A timeout, in milliseconds. This function will return as soon as any events occur,
|
||||||
but will return after \a timeout_ms milliseconds have elapsed.
|
but will return after \a timeout_ms milliseconds have elapsed.
|
||||||
\retval 0 on success (events occurred, timeout occurred).
|
\returns Number of events processed.
|
||||||
|
\retval 0 on timeout.
|
||||||
\retval -1 on error (system call failed; see \a errno).
|
\retval -1 on error (system call failed; see \a errno).
|
||||||
|
|
||||||
This function will run the event loop once, returning as soon as events are available (or the
|
This function will run the event loop once, returning as soon as events are available (or the
|
||||||
|
|
Loading…
Reference in New Issue