From f68e021b90f804b102f598856bf0f01ca36e95c3 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 7 Dec 2014 12:51:01 +0100 Subject: [PATCH] factor out socket_open_internal() --- src/socket.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/socket.c b/src/socket.c index 0108243..0ea4ae8 100644 --- a/src/socket.c +++ b/src/socket.c @@ -285,6 +285,14 @@ static void socket_connect_failed( conn_t * ); static void socket_connected( 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 socket_close_internal( conn_t *sock ) { @@ -322,10 +330,7 @@ socket_connect( conn_t *sock, void (*cb)( int ok, void *aux ) ) } 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" ); socket_connected( sock ); @@ -417,9 +422,7 @@ socket_connect_one( conn_t *sock ) perror( "socket" ); 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 ); #ifdef HAVE_IPV6