lib update

This commit is contained in:
Olaf Rempel 2009-05-03 14:37:20 +02:00
parent 4da0b609eb
commit 3a379757b6
3 changed files with 21 additions and 4 deletions

View File

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

View File

@ -37,6 +37,7 @@ struct event_timeout * event_add_timeout(
void event_remove_timeout(struct event_timeout *entry); void event_remove_timeout(struct event_timeout *entry);
void event_loop_break(void);
int event_loop(void); int event_loop(void);
#endif /* _EVENT_H_ */ #endif /* _EVENT_H_ */

View File

@ -77,11 +77,15 @@ int log_print(int prio, const char *fmt, ...)
void log_close(void) void log_close(void)
{ {
if (buffer) if (buffer) {
free(buffer); free(buffer);
buffer = NULL;
}
if (log_fd) if (log_fd) {
fclose(log_fd); fclose(log_fd);
log_fd = NULL;
}
} }
int log_init(const char *logfile) int log_init(const char *logfile)
@ -100,6 +104,7 @@ int log_init(const char *logfile)
return -1; return -1;
} }
log_prio = LOG_EVERYTIME;
return 0; return 0;
} }