1.1 --- a/src/network.c Wed Apr 09 11:12:04 2014 +0200 1.2 +++ b/src/network.c Wed Apr 09 12:07:47 2014 +0200 1.3 @@ -29,6 +29,7 @@ 1.4 1.5 #include <stdlib.h> 1.6 #include <string.h> 1.7 +#include <fcntl.h> 1.8 #include "network.h" 1.9 1.10 #define new_socket() socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 1.11 @@ -133,3 +134,21 @@ 1.12 void net_recieve_data(int socket, void *data, size_t len) { 1.13 recv(socket, data, len, 0); 1.14 } 1.15 + 1.16 +int net_setnonblocking(int socket, _Bool nonblocking) { 1.17 + int opts = fcntl(socket, F_GETFL); 1.18 + if (opts < 0) { 1.19 + return 1; 1.20 + } 1.21 + 1.22 + if (nonblocking) { 1.23 + opts |= O_NONBLOCK; 1.24 + } else { 1.25 + opts &= ~O_NONBLOCK; 1.26 + } 1.27 + if (fcntl(socket, F_SETFL, opts) < 0) { 1.28 + return 1; 1.29 + } 1.30 + 1.31 + return 0; 1.32 +}