diff options
author | lsalzman <[email protected]> | 2013-09-27 09:42:37 +0300 |
---|---|---|
committer | lsalzman <[email protected]> | 2013-09-27 09:42:37 +0300 |
commit | 2c5dd69b176f1a3089bc10affc0c65d7fcbbab07 (patch) | |
tree | 47d6f53e20b651ee1cdf14c2b46312ccb376f0b6 /unix.c | |
parent | bc8019aa15a1e9357d9246369e2c3db658f06085 (diff) | |
download | enet-2c5dd69b176f1a3089bc10affc0c65d7fcbbab07.tar.gz enet-2c5dd69b176f1a3089bc10affc0c65d7fcbbab07.zip |
fix RCVTIMEO and SNDTIMEO options on unix and also add NODELAY
Diffstat (limited to 'unix.c')
-rw-r--r-- | unix.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -9,6 +9,7 @@ #include <sys/ioctl.h> #include <sys/time.h> #include <arpa/inet.h> +#include <netinet/tcp.h> #include <netdb.h> #include <unistd.h> #include <string.h> @@ -258,11 +259,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) break; case ENET_SOCKOPT_RCVTIMEO: - result = setsockopt (socket, SOL_SOCKET, SO_RCVTIMEO, (char *) & value, sizeof (int)); + { + struct timeval timeVal; + timeVal.tv_sec = value / 1000; + timeVal.tv_usec = (value % 1000) * 1000; + result = setsockopt (socket, SOL_SOCKET, SO_RCVTIMEO, (char *) & timeVal, sizeof (struct timeval)); break; + } case ENET_SOCKOPT_SNDTIMEO: - result = setsockopt (socket, SOL_SOCKET, SO_SNDTIMEO, (char *) & value, sizeof (int)); + { + struct timeval timeVal; + timeVal.tv_sec = value / 1000; + timeVal.tv_usec = (value % 1000) * 1000; + result = setsockopt (socket, SOL_SOCKET, SO_SNDTIMEO, (char *) & timeVal, sizeof (struct timeval)); + break; + } + + case ENET_SOCKOPT_NODELAY: + result = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (char *) & value, sizeof (int)); break; default: |