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)
|
||||
{
|
||||
while(!lwevent_loop_exit) {
|
||||
if(lwevent_wait(-1)) {
|
||||
if(lwevent_wait(-1) == -1) {
|
||||
if(errno == EINTR) continue;
|
||||
return -1;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ static void _lwevent_invalid(struct lwevent* ev)
|
|||
*/
|
||||
int lwevent_wait(int timeout_ms)
|
||||
{
|
||||
int ret, i;
|
||||
int ret, i, revents;
|
||||
struct lwevent* ev;
|
||||
|
||||
_lwevent_invalid_head = 0;
|
||||
|
@ -123,13 +123,13 @@ int lwevent_wait(int timeout_ms)
|
|||
ev = (struct lwevent*)(_lw_revents[i].data.ptr);
|
||||
if(ev->fd == -1) continue; /* skip invalid events */
|
||||
|
||||
ret = _lw_revents[i].events;
|
||||
if(ret & ev->autodestroy) {
|
||||
revents = _lw_revents[i].events;
|
||||
if(revents & ev->autodestroy) {
|
||||
lwevent_free(ev);
|
||||
continue;
|
||||
}
|
||||
|
||||
ev->callback(ev, ret);
|
||||
ev->callback(ev, revents);
|
||||
}
|
||||
|
||||
/* free any invalid struct lwevent objects */
|
||||
|
@ -138,7 +138,9 @@ int lwevent_wait(int timeout_ms)
|
|||
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,
|
||||
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).
|
||||
|
||||
This function will run the event loop once, returning as soon as events are available (or the
|
||||
|
|
Loading…
Reference in New Issue