changed TOKEN of FFAKEHOST2 to NFH
[srvx.git] / src / ioset.c
index ced561f72622fc82509a5298a28aa987949c0ef6..04cae40524e53a4f423b7d56cb117fcfcf25dccb 100644 (file)
@@ -131,7 +131,7 @@ 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_kevent;
@@ -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;
     }