# HG changeset patch # User alex # Date 1177634510 0 # Node ID 857fbfeb2fa0c33b02117286cc1fcec3f97d490c # Parent eeea52739ff35870003b92495c391efc7ef9a2a8 implement ff_socket_nonblock and use it in networking code diff -r eeea52739ff3 -r 857fbfeb2fa0 network.h --- a/network.h Fri Apr 27 00:35:54 2007 +0000 +++ b/network.h Fri Apr 27 00:41:50 2007 +0000 @@ -32,6 +32,8 @@ #define ff_neterrno() errno #define FF_NETERROR(err) err +int ff_socket_nonblock(int socket, int enable); + #if !defined(HAVE_INET_ATON) /* in os_support.c */ int inet_aton (const char * str, struct in_addr * add); diff -r eeea52739ff3 -r 857fbfeb2fa0 os_support.c --- a/os_support.c Fri Apr 27 00:35:54 2007 +0000 +++ b/os_support.c Fri Apr 27 00:41:50 2007 +0000 @@ -114,6 +114,14 @@ } return 0; } + +int ff_socket_nonblock(int socket, int enable) +{ + if (enable) + return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK); + else + return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK); +} #endif /* CONFIG_NETWORK */ #ifdef CONFIG_FFSERVER diff -r eeea52739ff3 -r 857fbfeb2fa0 tcp.c --- a/tcp.c Fri Apr 27 00:35:54 2007 +0000 +++ b/tcp.c Fri Apr 27 00:41:50 2007 +0000 @@ -22,7 +22,6 @@ #include #include "network.h" #include -#include typedef struct TCPContext { int fd; @@ -62,7 +61,7 @@ fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) goto fail; - fcntl(fd, F_SETFL, O_NONBLOCK); + ff_socket_nonblock(fd, 1); redo: ret = connect(fd, (struct sockaddr *)&dest_addr,