|
|
@@ -30,6 +30,7 @@ |
|
|
|
|
|
|
|
static LIST_HEAD(event_fd_list); |
|
|
|
static LIST_HEAD(event_timeout_list); |
|
|
|
static int leave_loop; |
|
|
|
|
|
|
|
struct event_fd { |
|
|
|
struct list_head list; |
|
|
@@ -198,6 +199,11 @@ void event_remove_timeout(struct event_timeout *entry) |
|
|
|
entry->flags |= EVENT_DELETE; |
|
|
|
} |
|
|
|
|
|
|
|
void event_loop_break(void) |
|
|
|
{ |
|
|
|
leave_loop = 1; |
|
|
|
} |
|
|
|
|
|
|
|
int event_loop(void) |
|
|
|
{ |
|
|
|
fd_set *fdsets = malloc(sizeof(fd_set) * 2); |
|
|
@@ -206,7 +212,8 @@ int event_loop(void) |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
while (1) { |
|
|
|
leave_loop = 0; |
|
|
|
while (!leave_loop) { |
|
|
|
struct timeval timeout, *timeout_p = NULL; |
|
|
|
if (!list_empty(&event_timeout_list)) { |
|
|
|
struct timeval now; |
|
|
@@ -247,6 +254,7 @@ int event_loop(void) |
|
|
|
|
|
|
|
fd_set *readfds = NULL, *writefds = NULL; |
|
|
|
struct event_fd *entry, *tmp; |
|
|
|
int maxfd = -1; |
|
|
|
|
|
|
|
list_for_each_entry_safe(entry, tmp, &event_fd_list, list) { |
|
|
|
entry->flags &= ~EVENT_NEW; |
|
|
@@ -272,9 +280,11 @@ int event_loop(void) |
|
|
|
} |
|
|
|
FD_SET(entry->fd, writefds); |
|
|
|
} |
|
|
|
|
|
|
|
maxfd = (entry->fd > maxfd) ? entry->fd : maxfd; |
|
|
|
} |
|
|
|
|
|
|
|
int i = select(FD_SETSIZE, readfds, writefds, NULL, timeout_p); |
|
|
|
int i = select(maxfd +1, readfds, writefds, NULL, timeout_p); |
|
|
|
if (i <= 0) { |
|
|
|
/* On error, -1 is returned, and errno is set |
|
|
|
* appropriately; the sets and timeout become |
|
|
@@ -295,4 +305,5 @@ int event_loop(void) |
|
|
|
} |
|
|
|
} |
|
|
|
free(fdsets); |
|
|
|
return 0; |
|
|
|
} |