From cfb173889bceb7799a13586b28968e99b0bab332 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sat, 14 Jul 2007 15:28:02 +0200 Subject: [PATCH] lib update --- event.c | 36 +++++++++++++++++------------------- tcpsocket.c | 1 - 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/event.c b/event.c index 029c177..2e809fd 100644 --- a/event.c +++ b/event.c @@ -87,12 +87,12 @@ struct event_fd * event_add_fd( } if (type & FD_READ) { - entry->flags = (callback != NULL) ? (entry->flags | FD_READ) : (entry->flags & ~FD_READ); + entry->flags = (callback != NULL) ? (entry->flags | FD_READ | EVENT_NEW) : (entry->flags & ~FD_READ); entry->read_cb = callback; entry->read_priv = privdata; } else if (type & FD_WRITE) { - entry->flags = (callback != NULL) ? (entry->flags | FD_WRITE) : (entry->flags & ~FD_WRITE); + entry->flags = (callback != NULL) ? (entry->flags | FD_WRITE | EVENT_NEW) : (entry->flags & ~FD_WRITE); entry->write_cb = callback; entry->write_priv = privdata; } @@ -221,7 +221,7 @@ int event_loop(void) continue; } - /* timeout not elapsed, exit search (since list is sorted) */ + /* first timeout not elapsed, exit search (since list is sorted) */ if (cmp_timeval(&entry->nextrun, &now) == -1) break; @@ -255,15 +255,19 @@ int event_loop(void) if (entry->flags & EVENT_DELETE) { list_del(&entry->list); free(entry); + continue; - } else if (entry->flags & FD_READ) { + } + + if (entry->flags & FD_READ) { if (readfds == NULL) { readfds = &fdsets[0]; FD_ZERO(readfds); } FD_SET(entry->fd, readfds); + } - } else if (entry->flags & FD_WRITE) { + if (entry->flags & FD_WRITE) { if (writefds == NULL) { writefds = &fdsets[1]; FD_ZERO(writefds); @@ -280,22 +284,16 @@ int event_loop(void) * after an error. */ continue; + } - } else { - list_for_each_entry(entry, &event_fd_list, list) { - if ((entry->flags & EVENT_NEW) != 0) { - /* entry has just been added, execute it next round */ - continue; - } + list_for_each_entry(entry, &event_fd_list, list) { + if (((entry->flags & (FD_READ | EVENT_NEW)) == FD_READ) && FD_ISSET(entry->fd, readfds)) + if (entry->read_cb(entry->fd, entry->read_priv) != 0) + entry->flags |= EVENT_DELETE; - if ((entry->flags & FD_READ) && FD_ISSET(entry->fd, readfds)) - if (entry->read_cb(entry->fd, entry->read_priv) != 0) - entry->flags |= EVENT_DELETE; - - if ((entry->flags & FD_WRITE) && FD_ISSET(entry->fd, writefds)) - if (entry->write_cb(entry->fd, entry->write_priv) != 0) - entry->flags |= EVENT_DELETE; - } + if (((entry->flags & (FD_WRITE | EVENT_NEW)) == FD_WRITE) && FD_ISSET(entry->fd, writefds)) + if (entry->write_cb(entry->fd, entry->write_priv) != 0) + entry->flags |= EVENT_DELETE; } } free(fdsets); diff --git a/tcpsocket.c b/tcpsocket.c index 4c4a8c1..b5a33e9 100644 --- a/tcpsocket.c +++ b/tcpsocket.c @@ -110,7 +110,6 @@ int tcp_connect_error(int fd) if (err) { errno = err; - log_print(LOG_ERROR, "tcp_connect_error()"); return -1; }