浏览代码

factor out socket_open_internal()

Oswald Buddenhagen 10 年之前
父节点
当前提交
f68e021b90
共有 1 个文件被更改,包括 10 次插入7 次删除
  1. 10 7
      src/socket.c

+ 10 - 7
src/socket.c

@@ -285,6 +285,14 @@ static void socket_connect_failed( conn_t * );
 static void socket_connected( conn_t * );
 static void socket_connected( conn_t * );
 static void socket_connect_bail( conn_t * );
 static void socket_connect_bail( conn_t * );
 
 
+static void
+socket_open_internal( conn_t *sock, int fd )
+{
+	sock->fd = fd;
+	fcntl( fd, F_SETFL, O_NONBLOCK );
+	add_fd( fd, socket_fd_cb, sock );
+}
+
 static void
 static void
 socket_close_internal( conn_t *sock )
 socket_close_internal( conn_t *sock )
 {
 {
@@ -322,10 +330,7 @@ socket_connect( conn_t *sock, void (*cb)( int ok, void *aux ) )
 		}
 		}
 
 
 		close( a[0] );
 		close( a[0] );
-		sock->fd = a[1];
-
-		fcntl( a[1], F_SETFL, O_NONBLOCK );
-		add_fd( a[1], socket_fd_cb, sock );
+		socket_open_internal( sock, a[1] );
 
 
 		info( "\vok\n" );
 		info( "\vok\n" );
 		socket_connected( sock );
 		socket_connected( sock );
@@ -417,9 +422,7 @@ socket_connect_one( conn_t *sock )
 		perror( "socket" );
 		perror( "socket" );
 		exit( 1 );
 		exit( 1 );
 	}
 	}
-	sock->fd = s;
-	fcntl( s, F_SETFL, O_NONBLOCK );
-	add_fd( s, socket_fd_cb, sock );
+	socket_open_internal( sock, s );
 
 
 	infon( "Connecting to %s... ", sock->name );
 	infon( "Connecting to %s... ", sock->name );
 #ifdef HAVE_IPV6
 #ifdef HAVE_IPV6