X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fioset.c;h=33622af1c55e39f19a298a2702444163d875b074;hb=HEAD;hp=4b6225e523d967d231d33a85cdd705a34c6590f7;hpb=022bd2b4a123c7860a7c9529e253c569c1613933;p=srvx.git diff --git a/src/ioset.c b/src/ioset.c index 4b6225e..33622af 100644 --- a/src/ioset.c +++ b/src/ioset.c @@ -131,10 +131,10 @@ ioq_grow(struct ioq *ioq) { ioq->get = 0; ioq->buf = new_buf; ioq->size = new_size; - return new_size - ioq->put; + return new_size - ioq->put - 1; } -extern struct io_engine io_engine_kqueue; +extern struct io_engine io_engine_kevent; extern struct io_engine io_engine_epoll; extern struct io_engine io_engine_win32; extern struct io_engine io_engine_select; @@ -145,9 +145,9 @@ ioset_init(void) if (engine) /* someone beat us to it */ return; -#if WITH_IOSET_KQUEUE - if (!engine && io_engine_kqueue.init()) - engine = &io_engine_kqueue; +#if WITH_IOSET_KEVENT + if (!engine && io_engine_kevent.init()) + engine = &io_engine_kevent; #endif #if WITH_IOSET_EPOLL @@ -220,18 +220,18 @@ struct io_fd *ioset_listen(struct sockaddr *local, unsigned int sa_size, void *d } if (local && sa_size) { + opt = 1; + res = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(opt)); + if (res < 0) { + log_module(MAIN_LOG, LOG_WARNING, "Unable to mark listener address as re-usable: %s", strerror(errno)); + } + res = bind(fd, local, sa_size); if (res < 0) { log_module(MAIN_LOG, LOG_ERROR, "Unable to bind listening socket %d: %s", fd, strerror(errno)); close(fd); return NULL; } - - opt = 1; - res = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(opt)); - if (res < 0) { - log_module(MAIN_LOG, LOG_WARNING, "Unable to mark listener address as re-usable: %s", strerror(errno)); - } } res = listen(fd, 1); @@ -267,8 +267,9 @@ ioset_connect(struct sockaddr *local, unsigned int sa_size, const char *peer, un hints.ai_family = local ? local->sa_family : 0; hints.ai_socktype = SOCK_STREAM; snprintf(portnum, sizeof(portnum), "%u", port); - if (getaddrinfo(peer, portnum, &hints, &ai)) { - log_module(MAIN_LOG, LOG_ERROR, "getaddrinfo(%s, %s) failed.", peer, portnum); + res = getaddrinfo(peer, portnum, &hints, &ai); + if (res != 0) { + log_module(MAIN_LOG, LOG_ERROR, "getaddrinfo(%s, %s) failed: %s.", peer, portnum, gai_strerror(res)); return NULL; } @@ -438,7 +439,7 @@ ioset_find_line_length(struct io_fd *fd) { static void ioset_buffered_read(struct io_fd *fd) { - int put_avail, nbr, fdnum; + int put_avail, nbr; if (!(put_avail = ioq_put_avail(&fd->recv))) put_avail = ioq_grow(&fd->recv); @@ -473,7 +474,6 @@ ioset_buffered_read(struct io_fd *fd) { fd->recv.put += nbr; if (fd->recv.put == fd->recv.size) fd->recv.put = 0; - fdnum = fd->fd; while (fd->line_len > 0) { struct io_fd *old_active; int died = 0; @@ -577,7 +577,7 @@ void ioset_run(void) { extern struct io_fd *socket_io_fd; struct timeval timeout; - time_t wakey; + unsigned long wakey; while (!quit_services) { while (!socket_io_fd) @@ -585,7 +585,7 @@ ioset_run(void) { /* How long to sleep? (fill in select_timeout) */ wakey = timeq_next(); - if ((wakey - now) < 0) + if (wakey < now) timeout.tv_sec = 0; else timeout.tv_sec = wakey - now;