X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/ff3b058ac51e9caf5cf1fd310b8a401a97a85582..c0601d1e22c5c3749ea94c1c4359f9223b732fe4:/src/ioset.c diff --git a/src/ioset.c b/src/ioset.c index 4b6225e..b6269ac 100644 --- a/src/ioset.c +++ b/src/ioset.c @@ -5,7 +5,7 @@ * * srvx is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -134,7 +134,7 @@ ioq_grow(struct ioq *ioq) { return new_size - ioq->put; } -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,17 @@ 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 +266,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; } @@ -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; @@ -597,7 +597,7 @@ ioset_run(void) { /* Call any timeq events we need to call. */ timeq_run(); if (do_write_dbs) { - saxdb_write_all(); + saxdb_write_all(NULL); do_write_dbs = 0; } if (do_reopen) {