lib update

This commit is contained in:
Olaf Rempel 2007-07-14 15:28:02 +02:00
parent 0b68a8b0f9
commit cfb173889b
2 changed files with 17 additions and 20 deletions

36
event.c
View File

@ -87,12 +87,12 @@ struct event_fd * event_add_fd(
} }
if (type & FD_READ) { 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_cb = callback;
entry->read_priv = privdata; entry->read_priv = privdata;
} else if (type & FD_WRITE) { } 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_cb = callback;
entry->write_priv = privdata; entry->write_priv = privdata;
} }
@ -221,7 +221,7 @@ int event_loop(void)
continue; 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) if (cmp_timeval(&entry->nextrun, &now) == -1)
break; break;
@ -255,15 +255,19 @@ int event_loop(void)
if (entry->flags & EVENT_DELETE) { if (entry->flags & EVENT_DELETE) {
list_del(&entry->list); list_del(&entry->list);
free(entry); free(entry);
continue;
} else if (entry->flags & FD_READ) { }
if (entry->flags & FD_READ) {
if (readfds == NULL) { if (readfds == NULL) {
readfds = &fdsets[0]; readfds = &fdsets[0];
FD_ZERO(readfds); FD_ZERO(readfds);
} }
FD_SET(entry->fd, readfds); FD_SET(entry->fd, readfds);
}
} else if (entry->flags & FD_WRITE) { if (entry->flags & FD_WRITE) {
if (writefds == NULL) { if (writefds == NULL) {
writefds = &fdsets[1]; writefds = &fdsets[1];
FD_ZERO(writefds); FD_ZERO(writefds);
@ -280,22 +284,16 @@ int event_loop(void)
* after an error. * after an error.
*/ */
continue; continue;
}
} else { list_for_each_entry(entry, &event_fd_list, list) {
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->flags & EVENT_NEW) != 0) { if (entry->read_cb(entry->fd, entry->read_priv) != 0)
/* entry has just been added, execute it next round */ entry->flags |= EVENT_DELETE;
continue;
}
if ((entry->flags & FD_READ) && FD_ISSET(entry->fd, readfds)) if (((entry->flags & (FD_WRITE | EVENT_NEW)) == FD_WRITE) && FD_ISSET(entry->fd, writefds))
if (entry->read_cb(entry->fd, entry->read_priv) != 0) if (entry->write_cb(entry->fd, entry->write_priv) != 0)
entry->flags |= EVENT_DELETE; 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;
}
} }
} }
free(fdsets); free(fdsets);

View File

@ -110,7 +110,6 @@ int tcp_connect_error(int fd)
if (err) { if (err) {
errno = err; errno = err;
log_print(LOG_ERROR, "tcp_connect_error()");
return -1; return -1;
} }