mirror of
https://github.com/lsalzman/enet
synced 2024-11-21 14:29:05 -07:00
fix RCVTIMEO and SNDTIMEO options on unix and also add NODELAY
This commit is contained in:
parent
bc8019aa15
commit
2c5dd69b17
3 changed files with 23 additions and 3 deletions
|
@ -61,7 +61,8 @@ typedef enum _ENetSocketOption
|
||||||
ENET_SOCKOPT_REUSEADDR = 5,
|
ENET_SOCKOPT_REUSEADDR = 5,
|
||||||
ENET_SOCKOPT_RCVTIMEO = 6,
|
ENET_SOCKOPT_RCVTIMEO = 6,
|
||||||
ENET_SOCKOPT_SNDTIMEO = 7,
|
ENET_SOCKOPT_SNDTIMEO = 7,
|
||||||
ENET_SOCKOPT_ERROR = 8
|
ENET_SOCKOPT_ERROR = 8,
|
||||||
|
ENET_SOCKOPT_NODELAY = 9
|
||||||
} ENetSocketOption;
|
} ENetSocketOption;
|
||||||
|
|
||||||
typedef enum _ENetSocketShutdown
|
typedef enum _ENetSocketShutdown
|
||||||
|
|
19
unix.c
19
unix.c
|
@ -9,6 +9,7 @@
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -258,11 +259,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENET_SOCKOPT_RCVTIMEO:
|
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;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ENET_SOCKOPT_SNDTIMEO:
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
4
win32.c
4
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));
|
result = setsockopt (socket, SOL_SOCKET, SO_SNDTIMEO, (char *) & value, sizeof (int));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ENET_SOCKOPT_NODELAY:
|
||||||
|
result = setsockopt (socket, IPPROTO_TCP, TCP_NODELAY, (char *) & value, sizeof (int));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue