closesocket(server_fd);
return -1;
}
- fcntl(server_fd, F_SETFL, O_NONBLOCK);
+ ff_socket_nonblock(server_fd, 1);
return server_fd;
}
&len);
if (fd < 0)
return;
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ ff_socket_nonblock(fd, 1);
/* XXX: should output a warning page when coming
close to the connection limit */
#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);
}
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
#include <unistd.h>
#include "network.h"
#include <sys/time.h>
-#include <fcntl.h>
typedef struct TCPContext {
int fd;
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,