linux.c: Remove stray debugging code.
[yaid] / yaid.c
diff --git a/yaid.c b/yaid.c
index 1355019..fc6ddd4 100644 (file)
--- a/yaid.c
+++ b/yaid.c
@@ -165,6 +165,26 @@ static void disconnect_client(struct client *c)
   xfree(c);
 }
 
+static int fix_up_socket(int fd, const char *what)
+{
+  int yes = 1;
+
+  if (fdflags(fd, O_NONBLOCK, O_NONBLOCK, 0, 0)) {
+    logmsg(0, LOG_ERR, "failed to set %s connection nonblocking: %s",
+          what, strerror(errno));
+    return (-1);
+  }
+
+  if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &yes, sizeof(yes))) {
+    logmsg(0, LOG_ERR,
+          "failed to disable `out-of-band' data on %s connection: %s",
+          what, strerror(errno));
+    return (-1);
+  }
+
+  return (0);
+}
+
 static void done_client_write(int err, void *p)
 {
   struct client *c = p;
@@ -354,17 +374,14 @@ static void proxy_query(struct client *c)
           c->l->ao->name, strerror(errno));
     goto err_0;
   }
-
-  if (fdflags(fd, O_NONBLOCK, O_NONBLOCK, 0, 0)) {
-    logmsg(&c->q, LOG_ERR, "failed to set %s proxy socket nonblocking: %s",
-          c->l->ao->name, strerror(errno));
-    goto err_1;
-  }
+  if (fix_up_socket(fd, "proxy")) goto err_1;
 
   s = c->q.u.nat;
   s.port = 113;
   c->l->ao->socket_to_sockaddr(&s, &ss, &ssz);
   selbuf_disable(&c->b);
+  c->px = px; px->c = c;
+  px->fd = -1;
   if (conn_init(&px->cn, &sel, fd, (struct sockaddr *)&ss, ssz,
                proxy_connected, px)) {
     logmsg(&c->q, LOG_ERR, "failed to make %s proxy connection to %s: %s",
@@ -372,8 +389,6 @@ static void proxy_query(struct client *c)
     goto err_2;
   }
 
-  c->px = px; px->c = c;
-  px->fd = -1;
   return;
 
 err_2:
@@ -548,6 +563,7 @@ static void accept_client(int fd, unsigned mode, void *p)
     }
     return;
   }
+  if (fix_up_socket(sk, "incoming client")) { close(sk); return; }
 
   c = xmalloc(sizeof(*c));
   c->l = l;