From 2c5dd69b176f1a3089bc10affc0c65d7fcbbab07 Mon Sep 17 00:00:00 2001 From: lsalzman Date: Fri, 27 Sep 2013 09:42:37 +0300 Subject: [PATCH] fix RCVTIMEO and SNDTIMEO options on unix and also add NODELAY --- include/enet/enet.h | 3 ++- unix.c | 19 +++++++++++++++++-- win32.c | 4 ++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/enet/enet.h b/include/enet/enet.h index 162b0f8..c690e42 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -61,7 +61,8 @@ typedef enum _ENetSocketOption ENET_SOCKOPT_REUSEADDR = 5, ENET_SOCKOPT_RCVTIMEO = 6, ENET_SOCKOPT_SNDTIMEO = 7, - ENET_SOCKOPT_ERROR = 8 + ENET_SOCKOPT_ERROR = 8, + ENET_SOCKOPT_NODELAY = 9 } ENetSocketOption; typedef enum _ENetSocketShutdown diff --git a/unix.c b/unix.c index f04bb6d..3fdce96 100644 --- a/unix.c +++ b/unix.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -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: diff --git a/win32.c b/win32.c index 057f82c..c441841 100644 --- a/win32.c +++ b/win32.c @@ -195,6 +195,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) result = setsockopt (socket, SOL_SOCKET, SO_SNDTIMEO, (char *) & value, sizeof (int)); break; + case ENET_SOCKOPT_NODELAY: + result = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (char *) & value, sizeof (int)); + break; + default: break; }