diff options
author | eihrul <eihrul> | 2007-10-03 04:10:09 +0000 |
---|---|---|
committer | eihrul <eihrul> | 2007-10-03 04:10:09 +0000 |
commit | 01087850127f68584078e8e366ba7489d17128d5 (patch) | |
tree | f93dd482675796e63dc38a77464d815dc32a2f2d /win32.c | |
parent | 506095210430f4581ff5027f70d395530686b85b (diff) | |
download | enet-01087850127f68584078e8e366ba7489d17128d5.tar.gz enet-01087850127f68584078e8e366ba7489d17128d5.zip |
*** empty log message ***
Diffstat (limited to 'win32.c')
-rw-r--r-- | win32.c | 44 |
1 files changed, 31 insertions, 13 deletions
@@ -104,24 +104,11 @@ ENetSocket enet_socket_create (ENetSocketType type, const ENetAddress * address) { ENetSocket newSocket = socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); - u_long nonBlocking = 1; - int receiveBufferSize = ENET_HOST_RECEIVE_BUFFER_SIZE, - sendBufferSize = ENET_HOST_SEND_BUFFER_SIZE, - allowBroadcasting = 1; struct sockaddr_in sin; if (newSocket == ENET_SOCKET_NULL) return ENET_SOCKET_NULL; - if (type == ENET_SOCKET_TYPE_DATAGRAM) - { - ioctlsocket (newSocket, FIONBIO, & nonBlocking); - - setsockopt (newSocket, SOL_SOCKET, SO_RCVBUF, (char *) & receiveBufferSize, sizeof (int)); - setsockopt (newSocket, SOL_SOCKET, SO_SNDBUF, (char *) & sendBufferSize, sizeof (int)); - setsockopt (newSocket, SOL_SOCKET, SO_BROADCAST, (char *) & allowBroadcasting, sizeof (int)); - } - memset (& sin, 0, sizeof (struct sockaddr_in)); sin.sin_family = AF_INET; @@ -154,6 +141,37 @@ enet_socket_create (ENetSocketType type, const ENetAddress * address) } int +enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) +{ + int result = SOCKET_ERROR; + switch (option) + { + case ENET_SOCKOPT_NONBLOCK: + { + u_long nonBlocking = (u_long) value; + result = ioctlsocket (socket, FIONBIO, & nonBlocking); + break; + } + + case ENET_SOCKOPT_BROADCAST: + result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int)); + break; + + case ENET_SOCKOPT_RCVBUF: + result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int)); + break; + + case ENET_SOCKOPT_SNDBUF: + result = setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (char *) & value, sizeof (int)); + break; + + default: + break; + } + return result == SOCKET_ERROR ? -1 : 0; +} + +int enet_socket_connect (ENetSocket socket, const ENetAddress * address) { struct sockaddr_in sin; |