aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32.c
diff options
context:
space:
mode:
authoreihrul <eihrul>2008-09-15 23:11:22 +0000
committereihrul <eihrul>2008-09-15 23:11:22 +0000
commitb846c47521bcf2978bf9f6c3a39e0e8a324664be (patch)
tree8faa2e1b7ec3d8fd8e9a18b15a21bd2c3d1eb31d /win32.c
parent6cf5ada45ceaff7c56a413b9c14d602a49d1c975 (diff)
downloadenet-b846c47521bcf2978bf9f6c3a39e0e8a324664be.tar.gz
enet-b846c47521bcf2978bf9f6c3a39e0e8a324664be.zip
added miscellaneous updates for broadcasting
Diffstat (limited to 'win32.c')
-rw-r--r--win32.c52
1 files changed, 32 insertions, 20 deletions
diff --git a/win32.c b/win32.c
index b8b2aa7..e1fae23 100644
--- a/win32.c
+++ b/win32.c
@@ -100,19 +100,15 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
return 0;
}
-ENetSocket
-enet_socket_create (ENetSocketType type, const ENetAddress * address)
+int
+enet_socket_bind (ENetSocket socket, const ENetAddress * address)
{
- ENetSocket newSocket = socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
struct sockaddr_in sin;
- if (newSocket == ENET_SOCKET_NULL)
- return ENET_SOCKET_NULL;
-
memset (& sin, 0, sizeof (struct sockaddr_in));
sin.sin_family = AF_INET;
-
+
if (address != NULL)
{
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
@@ -124,20 +120,21 @@ enet_socket_create (ENetSocketType type, const ENetAddress * address)
sin.sin_addr.s_addr = INADDR_ANY;
}
- if (bind (newSocket,
- (struct sockaddr *) & sin,
- sizeof (struct sockaddr_in)) == SOCKET_ERROR ||
- (type == ENET_SOCKET_TYPE_STREAM &&
- address != NULL &&
- address -> port != ENET_PORT_ANY &&
- listen (newSocket, SOMAXCONN) == SOCKET_ERROR))
- {
- closesocket (newSocket);
+ return bind (socket,
+ (struct sockaddr *) & sin,
+ sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
+}
- return ENET_SOCKET_NULL;
- }
+int
+enet_socket_listen (ENetSocket socket, int backlog)
+{
+ return listen (socket, backlog < 0 ? SOMAXCONN : backlog) == SOCKET_ERROR ? -1 : 0;
+}
- return newSocket;
+ENetSocket
+enet_socket_create (ENetSocketType type)
+{
+ return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
}
int
@@ -157,6 +154,10 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int));
break;
+ case ENET_SOCKOPT_REUSEADDR:
+ result = setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) & value, sizeof (int));
+ break;
+
case ENET_SOCKOPT_RCVBUF:
result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int));
break;
@@ -182,7 +183,7 @@ enet_socket_connect (ENetSocket socket, const ENetAddress * address)
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
sin.sin_addr.s_addr = address -> host;
- return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
+ return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
}
ENetSocket
@@ -295,6 +296,17 @@ enet_socket_receive (ENetSocket socket,
}
int
+enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocketSet * writeSet, enet_uint32 timeout)
+{
+ struct timeval timeVal;
+
+ timeVal.tv_sec = timeout / 1000;
+ timeVal.tv_usec = (timeout % 1000) * 1000;
+
+ return select (maxSocket + 1, readSet, writeSet, NULL, & timeVal);
+}
+
+int
enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
{
fd_set readSet, writeSet;