chiark / gitweb /
File descriptor passing.
[mLib] / conn.c
diff --git a/conn.c b/conn.c
index e734f30459c0e0aa521f2fbd2580520b5e8b9853..1478fade1edc4178059286cfcd03eb5da8d487c6 100644 (file)
--- a/conn.c
+++ b/conn.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: conn.c,v 1.8 2003/10/12 14:47:10 mdw Exp $
+ * $Id: conn.c,v 1.9 2003/10/12 14:54:00 mdw Exp $
  *
  * Nonblocking connect handling
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: conn.c,v $
+ * Revision 1.9  2003/10/12 14:54:00  mdw
+ * Finish the work.
+ *
  * Revision 1.8  2003/10/12 14:47:10  mdw
  * New interface for messing with preconnected sockets.
  *
@@ -167,10 +170,8 @@ int conn_init(conn *c, sel_state *s, int fd,
 {
   int f;
 
-  if ((f = fcntl(fd, F_GETFL)) < 0 || fcntl(fd, F_SETFL, f | O_NONBLOCK)) {
-    close(fd);
-    return (-1);
-  }
+  if ((f = fcntl(fd, F_GETFL)) < 0 || fcntl(fd, F_SETFL, f | O_NONBLOCK))
+    goto fail;
 
   if (!connect(fd, dst, dsz))
     func(fd, p);
@@ -179,6 +180,10 @@ int conn_init(conn *c, sel_state *s, int fd,
   else
     conn_fd(c, s, fd, func, p);
   return (0);
+
+fail:
+  close(fd);
+  return (-1);
 }
 
 /* --- @conn_kill@ --- *