[Orxonox-commit 2685] r7390 - in code/branches/ipv6/src/external/enet: . include/enet patches
adrfried at orxonox.net
adrfried at orxonox.net
Thu Sep 9 16:30:50 CEST 2010
Author: adrfried
Date: 2010-09-09 16:30:50 +0200 (Thu, 09 Sep 2010)
New Revision: 7390
Added:
code/branches/ipv6/src/external/enet/patches/0005-IPv6-for-Windows.patch
Modified:
code/branches/ipv6/src/external/enet/CMakeLists.txt
code/branches/ipv6/src/external/enet/include/enet/enet.h
code/branches/ipv6/src/external/enet/include/enet/win32.h
code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch
code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch
code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch
code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch
code/branches/ipv6/src/external/enet/unix.c
code/branches/ipv6/src/external/enet/win32.c
Log:
IPv6 for Windows
I have not tested this, please test this and report issues to me.
Modified: code/branches/ipv6/src/external/enet/CMakeLists.txt
===================================================================
--- code/branches/ipv6/src/external/enet/CMakeLists.txt 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/CMakeLists.txt 2010-09-09 14:30:50 UTC (rev 7390)
@@ -26,7 +26,7 @@
include/enet/types.h
include/enet/unix.h
include/enet/utility.h
- #include/enet/win32.h
+ include/enet/win32.h
COMPILATION_BEGIN ENetCompilation.cpp
callbacks.c
@@ -37,7 +37,7 @@
peer.c
protocol.c
unix.c
- #win32.c
+ win32.c
COMPILATION_END
)
Modified: code/branches/ipv6/src/external/enet/include/enet/enet.h
===================================================================
--- code/branches/ipv6/src/external/enet/include/enet/enet.h 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/include/enet/enet.h 2010-09-09 14:30:50 UTC (rev 7390)
@@ -77,7 +77,11 @@
typedef struct _ENetAddress
{
ENetHostAddress host;
- enet_uint32 scopeID; //FIXME: this is of different size on Windows
+#ifdef WIN32
+ u_long scopeID;
+#else
+ uint32_t scopeID;
+#endif
enet_uint16 port;
} ENetAddress;
Modified: code/branches/ipv6/src/external/enet/include/enet/win32.h
===================================================================
--- code/branches/ipv6/src/external/enet/include/enet/win32.h 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/include/enet/win32.h 2010-09-09 14:30:50 UTC (rev 7390)
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <winsock2.h>
+#include <ws2tcpip.h>
typedef SOCKET ENetSocket;
Modified: code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch
===================================================================
--- code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch 2010-09-09 14:30:50 UTC (rev 7390)
@@ -1,7 +1,7 @@
From e4638515a1ade5a23f3b8eb9ca7dad249a3d6903 Mon Sep 17 00:00:00 2001
From: Adrian Friedli <adi at koalatux.ch>
Date: Thu, 2 Sep 2010 14:26:42 +0200
-Subject: [PATCH 1/4] use getaddrinfo for lookup in unix.c
+Subject: [PATCH 1/5] use getaddrinfo for lookup in unix.c
---
unix.c | 99 +++++++++++++++++++++++++--------------------------------------
Modified: code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch
===================================================================
--- code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch 2010-09-09 14:30:50 UTC (rev 7390)
@@ -1,7 +1,7 @@
From fc72c66f6b8a6b1d924ffa86861ce00a1c591839 Mon Sep 17 00:00:00 2001
From: Adrian Friedli <adi at koalatux.ch>
Date: Thu, 2 Sep 2010 14:27:07 +0200
-Subject: [PATCH 2/4] basic IPv6 support on Linux systems
+Subject: [PATCH 2/5] basic IPv6 support on Linux systems
this uses IPv4-mapped IPv6 addresses
---
Modified: code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch
===================================================================
--- code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch 2010-09-09 14:30:50 UTC (rev 7390)
@@ -1,14 +1,14 @@
-From af3c0910bd25d73b1a3c06bbfa4e0a3c6b96ddc5 Mon Sep 17 00:00:00 2001
+From b26e4ef3fa9c0139fc2ec086d2243b809365d683 Mon Sep 17 00:00:00 2001
From: Adrian Friedli <adi at koalatux.ch>
Date: Mon, 6 Sep 2010 14:58:50 +0200
-Subject: [PATCH 3/4] using address family in functions
+Subject: [PATCH 3/5] using address family in functions
---
host.c | 4 +-
include/enet/enet.h | 22 +++++++++---
protocol.c | 5 ++-
- unix.c | 87 ++++++++++++++++++++++++++++++++------------------
- 4 files changed, 77 insertions(+), 41 deletions(-)
+ unix.c | 86 ++++++++++++++++++++++++++++++++------------------
+ 4 files changed, 76 insertions(+), 41 deletions(-)
diff --git a/host.c b/host.c
index 8bb2433..9ccf894 100644
@@ -90,10 +90,10 @@
enet_protocol_remove_sent_unreliable_commands (currentPeer);
diff --git a/unix.c b/unix.c
-index de032bb..13a24d8 100644
+index de032bb..475c6e3 100644
--- a/unix.c
+++ b/unix.c
-@@ -71,7 +71,28 @@ enet_time_set (enet_uint32 newTimeBase)
+@@ -71,7 +71,27 @@ enet_time_set (enet_uint32 newTimeBase)
timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase;
}
@@ -118,12 +118,11 @@
+ return 0;
+}
+
-+
+static ENetAddressFamily
enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
{
memset (address, 0, sizeof (ENetAddress));
-@@ -80,32 +101,31 @@ enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
+@@ -80,32 +100,31 @@ enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
address -> host = enet_address_map4 ((((struct sockaddr_in *) sin) -> sin_addr.s_addr));
//address -> scopeID = 0;
address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in *) sin) -> sin_port);
@@ -163,7 +162,7 @@
((struct sockaddr_in6 *) sin) -> sin6_family = AF_INET6;
((struct sockaddr_in6 *) sin) -> sin6_addr = * (struct in6_addr *) & address -> host;
((struct sockaddr_in6 *) sin) -> sin6_scope_id = address -> scopeID;
-@@ -132,7 +152,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
+@@ -132,7 +151,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
for (res = result; res != NULL; res = res -> ai_next)
{
@@ -172,7 +171,7 @@
break;
}
-@@ -147,9 +167,9 @@ static int
+@@ -147,9 +166,9 @@ static int
enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
{
struct sockaddr_storage sin;
@@ -184,7 +183,7 @@
return -1;
return 0;
-@@ -168,21 +188,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
+@@ -168,21 +187,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng
}
int
@@ -210,7 +209,7 @@
}
int
-@@ -192,13 +212,16 @@ enet_socket_listen (ENetSocket socket, int backlog)
+@@ -192,13 +211,16 @@ enet_socket_listen (ENetSocket socket, int backlog)
}
ENetSocket
@@ -231,7 +230,7 @@
#endif // IPV6_V6ONLY
return sock;
-@@ -241,25 +264,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
+@@ -241,25 +263,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
}
int
@@ -263,7 +262,7 @@
if (result == -1)
return ENET_SOCKET_NULL;
-@@ -281,7 +304,8 @@ int
+@@ -281,7 +303,8 @@ int
enet_socket_send (ENetSocket socket,
const ENetAddress * address,
const ENetBuffer * buffers,
@@ -273,7 +272,7 @@
{
struct msghdr msgHdr;
struct sockaddr_storage sin;
-@@ -291,9 +315,9 @@ enet_socket_send (ENetSocket socket,
+@@ -291,9 +314,9 @@ enet_socket_send (ENetSocket socket,
if (address != NULL)
{
@@ -285,7 +284,7 @@
}
msgHdr.msg_iov = (struct iovec *) buffers;
-@@ -316,7 +340,8 @@ int
+@@ -316,7 +339,8 @@ int
enet_socket_receive (ENetSocket socket,
ENetAddress * address,
ENetBuffer * buffers,
@@ -295,7 +294,7 @@
{
struct msghdr msgHdr;
struct sockaddr_storage sin;
-@@ -327,7 +352,7 @@ enet_socket_receive (ENetSocket socket,
+@@ -327,7 +351,7 @@ enet_socket_receive (ENetSocket socket,
if (address != NULL)
{
msgHdr.msg_name = & sin;
Modified: code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch
===================================================================
--- code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch 2010-09-09 14:30:50 UTC (rev 7390)
@@ -1,14 +1,14 @@
-From 9801a6bcd072870248a6b07245fc09a9492f8f51 Mon Sep 17 00:00:00 2001
+From 73fa28a84ce456561d3912578121a30bc8263c50 Mon Sep 17 00:00:00 2001
From: Adrian Friedli <adi at koalatux.ch>
Date: Wed, 8 Sep 2010 12:50:04 +0200
-Subject: [PATCH 4/4] using two separate sockets for IPv4 and IPv6
+Subject: [PATCH 4/5] using two separate sockets for IPv4 and IPv6
---
- host.c | 53 +++++++++++++++++++++++++++++++++++++-------------
- include/enet/enet.h | 11 ++++++++-
- protocol.c | 47 +++++++++++++++++++++++++++++++++++++++-----
- unix.c | 47 ++++++++++++++++++++++++++++++++------------
- 4 files changed, 123 insertions(+), 35 deletions(-)
+ host.c | 53 +++++++++++++++++++++++++++---------
+ include/enet/enet.h | 11 ++++++-
+ protocol.c | 47 ++++++++++++++++++++++++++++----
+ unix.c | 74 +++++++++++++++++++++++++++++++++++++-------------
+ 4 files changed, 144 insertions(+), 41 deletions(-)
diff --git a/host.c b/host.c
index 9ccf894..46e52c9 100644
@@ -232,10 +232,10 @@
host -> serviceTime = enet_time_get ();
diff --git a/unix.c b/unix.c
-index 13a24d8..22ffb76 100644
+index 475c6e3..751cb6f 100644
--- a/unix.c
+++ b/unix.c
-@@ -117,7 +117,9 @@ static int
+@@ -116,7 +116,9 @@ static int
enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, ENetAddressFamily family)
{
memset (sin, 0, enet_sa_size(family));
@@ -246,7 +246,7 @@
{
((struct sockaddr_in *) sin) -> sin_family = AF_INET;
((struct sockaddr_in *) sin) -> sin_addr = * (struct in_addr *) & address -> host.addr[12];
-@@ -219,7 +221,7 @@ enet_socket_create (ENetSocketType type, ENetAddressFamily family)
+@@ -218,7 +220,7 @@ enet_socket_create (ENetSocketType type, ENetAddressFamily family)
#ifdef IPV6_V6ONLY
if (family == ENET_IPV6)
{
@@ -255,16 +255,15 @@
setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, & value, sizeof (int));
}
#endif // IPV6_V6ONLY
-@@ -393,22 +395,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
+@@ -392,22 +394,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
}
int
-enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
+enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
{
--#ifdef HAS_POLL
+ #ifdef HAS_POLL
- struct pollfd pollSocket;
-+//#ifdef HAS_POLL
+ struct pollfd pollSocket[2];
int pollCount;
-
@@ -303,7 +302,7 @@
if (pollCount < 0)
return -1;
-@@ -418,13 +436,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+@@ -417,10 +435,10 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
if (pollCount == 0)
return 0;
@@ -316,19 +315,56 @@
* condition |= ENET_SOCKET_WAIT_RECEIVE;
return 0;
-+/*
-+FIXME: implement or remove this
- #else
- fd_set readSet, writeSet;
- struct timeval timeVal;
-@@ -460,6 +480,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+@@ -436,12 +454,28 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+ FD_ZERO (& writeSet);
+ if (* condition & ENET_SOCKET_WAIT_SEND)
+- FD_SET (socket, & writeSet);
++ {
++ if (socket4 != ENET_SOCKET_NULL)
++ FD_SET (socket4, & writeSet);
++ if (socket6 != ENET_SOCKET_NULL)
++ FD_SET (socket6, & writeSet);
++ }
+
+ if (* condition & ENET_SOCKET_WAIT_RECEIVE)
+- FD_SET (socket, & readSet);
++ {
++ if (socket4 != ENET_SOCKET_NULL)
++ FD_SET (socket4, & readSet);
++ if (socket6 != ENET_SOCKET_NULL)
++ FD_SET (socket6, & readSet);
++ }
++
++ ENetSocket maxSocket = 0;
++ if (socket4 != ENET_SOCKET_NULL)
++ maxSocket = socket4;
++ if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
++ maxSocket = socket6;
+
+- selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
++ selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
+
+ if (selectCount < 0)
+ return -1;
+@@ -451,11 +485,13 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+ if (selectCount == 0)
+ return 0;
+
+- if (FD_ISSET (socket, & writeSet))
+- * condition |= ENET_SOCKET_WAIT_SEND;
++ if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
++ (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
++ * condition |= ENET_SOCKET_WAIT_SEND;
+
+- if (FD_ISSET (socket, & readSet))
+- * condition |= ENET_SOCKET_WAIT_RECEIVE;
++ if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
++ (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
++ * condition |= ENET_SOCKET_WAIT_RECEIVE;
+
return 0;
#endif
-+*/
- }
-
- #endif
--
1.7.1
Added: code/branches/ipv6/src/external/enet/patches/0005-IPv6-for-Windows.patch
===================================================================
--- code/branches/ipv6/src/external/enet/patches/0005-IPv6-for-Windows.patch (rev 0)
+++ code/branches/ipv6/src/external/enet/patches/0005-IPv6-for-Windows.patch 2010-09-09 14:30:50 UTC (rev 7390)
@@ -0,0 +1,423 @@
+From 93248e1cd75da47980e0d69428747ff6471be1ed Mon Sep 17 00:00:00 2001
+From: Adrian Friedli <adi at koalatux.ch>
+Date: Thu, 9 Sep 2010 16:02:21 +0200
+Subject: [PATCH 5/5] IPv6 for Windows
+
+---
+ include/enet/enet.h | 6 +-
+ include/enet/win32.h | 1 +
+ win32.c | 237 ++++++++++++++++++++++++++++++++------------------
+ 3 files changed, 160 insertions(+), 84 deletions(-)
+
+diff --git a/include/enet/enet.h b/include/enet/enet.h
+index 616fe7f..54e3b3b 100644
+--- a/include/enet/enet.h
++++ b/include/enet/enet.h
+@@ -77,7 +77,11 @@ extern const ENetHostAddress ENET_HOST_BROADCAST; /**< specifies a IPv4 subne
+ typedef struct _ENetAddress
+ {
+ ENetHostAddress host;
+- enet_uint32 scopeID; //FIXME: this is of different size on Windows
++#ifdef WIN32
++ u_long scopeID;
++#else
++ uint32_t scopeID;
++#endif
+ enet_uint16 port;
+ } ENetAddress;
+
+diff --git a/include/enet/win32.h b/include/enet/win32.h
+index 0e1cf0c..9f3f6e5 100644
+--- a/include/enet/win32.h
++++ b/include/enet/win32.h
+@@ -14,6 +14,7 @@
+
+ #include <stdlib.h>
+ #include <winsock2.h>
++#include <ws2tcpip.h>
+
+ typedef SOCKET ENetSocket;
+
+diff --git a/win32.c b/win32.c
+index e1fae23..dbbe85a 100644
+--- a/win32.c
++++ b/win32.c
+@@ -52,77 +52,139 @@ enet_time_set (enet_uint32 newTimeBase)
+ timeBase = (enet_uint32) timeGetTime () - newTimeBase;
+ }
+
+-int
+-enet_address_set_host (ENetAddress * address, const char * name)
++static enet_uint16
++enet_af (ENetAddressFamily family)
+ {
+- struct hostent * hostEntry;
++ if (family == ENET_IPV4)
++ return AF_INET;
++ if (family == ENET_IPV6)
++ return AF_INET6;
++ return 0;
++}
++
++static socklen_t
++enet_sa_size (ENetAddressFamily family)
++{
++ if (family == ENET_IPV4)
++ return sizeof (SOCKADDR_IN);
++ if (family == ENET_IPV6)
++ return sizeof (SOCKADDR_IN6);
++ return 0;
++}
+
+- hostEntry = gethostbyname (name);
+- if (hostEntry == NULL ||
+- hostEntry -> h_addrtype != AF_INET)
++static ENetAddressFamily
++enet_address_set_address (ENetAddress * address, const SOCKADDR * sin)
++{
++ memset (address, 0, sizeof (ENetAddress));
++ if (sin -> sa_family == AF_INET)
+ {
+- unsigned long host = inet_addr (name);
+- if (host == INADDR_NONE)
+- return -1;
+- address -> host = host;
+- return 0;
++ address -> host = enet_address_map4 ((((SOCKADDR_IN *) sin) -> sin_addr.s_addr));
++ //address -> scopeID = 0;
++ address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN *) sin) -> sin_port);
++ return ENET_IPV4;
+ }
++ if (sin -> sa_family == AF_INET6)
++ {
++ address -> host = * (ENetHostAddress *) & ((SOCKADDR_IN6 *) sin) -> sin6_addr;
++ address -> scopeID = ((SOCKADDR_IN6 *) sin) -> sin6_scope_id;
++ address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN6 *) sin) -> sin6_port);
++ return ENET_IPV6;
++ }
++ return ENET_NO_ADDRESS_FAMILY;
++}
+
+- address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
+-
+- return 0;
++static int
++enet_address_set_sin (SOCKADDR * sin, const ENetAddress * address, ENetAddressFamily family)
++{
++ memset (sin, 0, enet_sa_size(family));
++ if (family == ENET_IPV4 &&
++ (enet_get_address_family (address) == ENET_IPV4 ||
++ !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
++ {
++ ((SOCKADDR_IN *) sin) -> sin_family = AF_INET;
++ ((SOCKADDR_IN *) sin) -> sin_addr = * (IN_ADDR *) & address -> host.addr[12];
++ ((SOCKADDR_IN *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
++ return 0;
++ }
++ else if (family == ENET_IPV6)
++ {
++ ((SOCKADDR_IN6 *) sin) -> sin6_family = AF_INET6;
++ ((SOCKADDR_IN6 *) sin) -> sin6_addr = * (IN6_ADDR *) & address -> host;
++ ((SOCKADDR_IN6 *) sin) -> sin6_scope_id = address -> scopeID;
++ ((SOCKADDR_IN6 *) sin) -> sin6_port = ENET_HOST_TO_NET_16 (address -> port);
++ return 0;
++ }
++ return -1;
+ }
+
+ int
+-enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
++enet_address_set_host (ENetAddress * address, const char * name)
+ {
+- char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
+- if (addr == NULL)
++ enet_uint16 port = address -> port;
++ ADDRINFO hints;
++ ADDRINFO * result;
++ ADDRINFO * res;
++
++ memset(& hints, 0, sizeof (hints));
++ hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG;
++ hints.ai_family = AF_UNSPEC;
++
++ if ( getaddrinfo(name, NULL, &hints, &result) )
+ return -1;
+- strncpy (name, addr, nameLength);
++
++ for (res = result; res != NULL; res = res -> ai_next)
++ {
++ if ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY )
++ break;
++ }
++
++ address -> port = port;
++ freeaddrinfo(result);
++ if (res == NULL) return -1;
++
+ return 0;
+ }
+
+-int
+-enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
++static int
++enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
+ {
+- struct in_addr in;
+- struct hostent * hostEntry;
+-
+- in.s_addr = address -> host;
+-
+- hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
+- if (hostEntry == NULL)
+- return enet_address_get_host_ip (address, name, nameLength);
++ SOCKADDR_STORAGE sin;
++ enet_address_set_sin((SOCKADDR *) & sin, address, ENET_IPV6);
+
+- strncpy (name, hostEntry -> h_name, nameLength);
++ if ( getnameinfo((SOCKADDR *) & sin, enet_sa_size (ENET_IPV6), name, nameLength, NULL, 0, flags))
++ return -1;
+
+ return 0;
+ }
+
+ int
+-enet_socket_bind (ENetSocket socket, const ENetAddress * address)
++enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
+ {
+- struct sockaddr_in sin;
++ return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST);
++}
+
+- memset (& sin, 0, sizeof (struct sockaddr_in));
++int
++enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
++{
++ return enet_address_get_host_x(address, name, nameLength, 0);
++}
+
+- sin.sin_family = AF_INET;
++int
++enet_socket_bind (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
++{
++ SOCKADDR_STORAGE sin;
+
+ if (address != NULL)
+ {
+- sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
+- sin.sin_addr.s_addr = address -> host;
++ enet_address_set_sin((SOCKADDR *) & sin, address, family);
+ }
+ else
+ {
+- sin.sin_port = 0;
+- sin.sin_addr.s_addr = INADDR_ANY;
++ ENetAddress address_ = { ENET_HOST_ANY, 0, 0 };
++ enet_address_set_sin((SOCKADDR *) & sin, & address_, family);
+ }
+
+- return bind (socket,
+- (struct sockaddr *) & sin,
+- sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
++ return bind (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
+ }
+
+ int
+@@ -132,7 +194,7 @@ enet_socket_listen (ENetSocket socket, int backlog)
+ }
+
+ ENetSocket
+-enet_socket_create (ENetSocketType type)
++enet_socket_create (ENetSocketType type, ENetAddressFamily family)
+ {
+ return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
+ }
+@@ -173,28 +235,23 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
+ }
+
+ int
+-enet_socket_connect (ENetSocket socket, const ENetAddress * address)
++enet_socket_connect (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
+ {
+- struct sockaddr_in sin;
+-
+- memset (& sin, 0, sizeof (struct sockaddr_in));
++ SOCKADDR_STORAGE sin;
++ enet_address_set_sin((SOCKADDR *) & sin, address, family);
+
+- sin.sin_family = AF_INET;
+- 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)) == SOCKET_ERROR ? -1 : 0;
++ return connect (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
+ }
+
+ ENetSocket
+-enet_socket_accept (ENetSocket socket, ENetAddress * address)
++enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family)
+ {
+ SOCKET result;
+- struct sockaddr_in sin;
+- int sinLength = sizeof (struct sockaddr_in);
++ SOCKADDR_STORAGE sin;
++ int sinLength = enet_sa_size (family);
+
+ result = accept (socket,
+- address != NULL ? (struct sockaddr *) & sin : NULL,
++ address != NULL ? (SOCKADDR *) & sin : NULL,
+ address != NULL ? & sinLength : NULL);
+
+ if (result == INVALID_SOCKET)
+@@ -202,8 +259,7 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)
+
+ if (address != NULL)
+ {
+- address -> host = (enet_uint32) sin.sin_addr.s_addr;
+- address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
++ enet_address_set_address(address, (SOCKADDR *) & sin);
+ }
+
+ return result;
+@@ -219,18 +275,15 @@ int
+ enet_socket_send (ENetSocket socket,
+ const ENetAddress * address,
+ const ENetBuffer * buffers,
+- size_t bufferCount)
++ size_t bufferCount,
++ ENetAddressFamily family)
+ {
+- struct sockaddr_in sin;
++ SOCKADDR_STORAGE sin;
+ DWORD sentLength;
+
+ if (address != NULL)
+ {
+- memset (& sin, 0, sizeof (struct sockaddr_in));
+-
+- sin.sin_family = AF_INET;
+- sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
+- sin.sin_addr.s_addr = address -> host;
++ enet_address_set_sin((SOCKADDR *) & sin, address, family);
+ }
+
+ if (WSASendTo (socket,
+@@ -238,8 +291,8 @@ enet_socket_send (ENetSocket socket,
+ (DWORD) bufferCount,
+ & sentLength,
+ 0,
+- address != NULL ? (struct sockaddr *) & sin : 0,
+- address != NULL ? sizeof (struct sockaddr_in) : 0,
++ address != NULL ? (SOCKADDR *) & sin : 0,
++ address != NULL ? enet_sa_size (family) : 0,
+ NULL,
+ NULL) == SOCKET_ERROR)
+ {
+@@ -256,19 +309,20 @@ int
+ enet_socket_receive (ENetSocket socket,
+ ENetAddress * address,
+ ENetBuffer * buffers,
+- size_t bufferCount)
++ size_t bufferCount,
++ ENetAddressFamily family)
+ {
+- INT sinLength = sizeof (struct sockaddr_in);
++ INT sinLength = enet_sa_size (family);
+ DWORD flags = 0,
+ recvLength;
+- struct sockaddr_in sin;
++ SOCKADDR_STORAGE sin;
+
+ if (WSARecvFrom (socket,
+ (LPWSABUF) buffers,
+ (DWORD) bufferCount,
+ & recvLength,
+ & flags,
+- address != NULL ? (struct sockaddr *) & sin : NULL,
++ address != NULL ? (SOCKADDR *) & sin : NULL,
+ address != NULL ? & sinLength : NULL,
+ NULL,
+ NULL) == SOCKET_ERROR)
+@@ -288,8 +342,7 @@ enet_socket_receive (ENetSocket socket,
+
+ if (address != NULL)
+ {
+- address -> host = (enet_uint32) sin.sin_addr.s_addr;
+- address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
++ enet_address_set_address(address, (SOCKADDR *) & sin);
+ }
+
+ return (int) recvLength;
+@@ -307,25 +360,41 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
+ }
+
+ int
+-enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
++enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
+ {
+ fd_set readSet, writeSet;
+ struct timeval timeVal;
+ int selectCount;
+-
++
+ timeVal.tv_sec = timeout / 1000;
+ timeVal.tv_usec = (timeout % 1000) * 1000;
+-
++
+ FD_ZERO (& readSet);
+ FD_ZERO (& writeSet);
+
+ if (* condition & ENET_SOCKET_WAIT_SEND)
+- FD_SET (socket, & writeSet);
++ {
++ if (socket4 != ENET_SOCKET_NULL)
++ FD_SET (socket4, & writeSet);
++ if (socket6 != ENET_SOCKET_NULL)
++ FD_SET (socket6, & writeSet);
++ }
+
+ if (* condition & ENET_SOCKET_WAIT_RECEIVE)
+- FD_SET (socket, & readSet);
++ {
++ if (socket4 != ENET_SOCKET_NULL)
++ FD_SET (socket4, & readSet);
++ if (socket6 != ENET_SOCKET_NULL)
++ FD_SET (socket6, & readSet);
++ }
+
+- selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
++ ENetSocket maxSocket = 0;
++ if (socket4 != ENET_SOCKET_NULL)
++ maxSocket = socket4;
++ if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
++ maxSocket = socket6;
++
++ selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
+
+ if (selectCount < 0)
+ return -1;
+@@ -335,14 +404,16 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
+ if (selectCount == 0)
+ return 0;
+
+- if (FD_ISSET (socket, & writeSet))
+- * condition |= ENET_SOCKET_WAIT_SEND;
+-
+- if (FD_ISSET (socket, & readSet))
+- * condition |= ENET_SOCKET_WAIT_RECEIVE;
++ if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
++ (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
++ * condition |= ENET_SOCKET_WAIT_SEND;
++
++ if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
++ (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
++ * condition |= ENET_SOCKET_WAIT_RECEIVE;
+
+ return 0;
+-}
++}
+
+ #endif
+
+--
+1.7.1
+
Modified: code/branches/ipv6/src/external/enet/unix.c
===================================================================
--- code/branches/ipv6/src/external/enet/unix.c 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/unix.c 2010-09-09 14:30:50 UTC (rev 7390)
@@ -91,7 +91,6 @@
return 0;
}
-
static ENetAddressFamily
enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
{
@@ -397,7 +396,7 @@
int
enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
{
-//#ifdef HAS_POLL
+#ifdef HAS_POLL
struct pollfd pollSocket[2];
int pollCount;
@@ -443,8 +442,6 @@
* condition |= ENET_SOCKET_WAIT_RECEIVE;
return 0;
-/*
-FIXME: implement or remove this
#else
fd_set readSet, writeSet;
struct timeval timeVal;
@@ -457,13 +454,29 @@
FD_ZERO (& writeSet);
if (* condition & ENET_SOCKET_WAIT_SEND)
- FD_SET (socket, & writeSet);
+ {
+ if (socket4 != ENET_SOCKET_NULL)
+ FD_SET (socket4, & writeSet);
+ if (socket6 != ENET_SOCKET_NULL)
+ FD_SET (socket6, & writeSet);
+ }
if (* condition & ENET_SOCKET_WAIT_RECEIVE)
- FD_SET (socket, & readSet);
+ {
+ if (socket4 != ENET_SOCKET_NULL)
+ FD_SET (socket4, & readSet);
+ if (socket6 != ENET_SOCKET_NULL)
+ FD_SET (socket6, & readSet);
+ }
- selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
+ ENetSocket maxSocket = 0;
+ if (socket4 != ENET_SOCKET_NULL)
+ maxSocket = socket4;
+ if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
+ maxSocket = socket6;
+ selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
+
if (selectCount < 0)
return -1;
@@ -472,15 +485,16 @@
if (selectCount == 0)
return 0;
- if (FD_ISSET (socket, & writeSet))
- * condition |= ENET_SOCKET_WAIT_SEND;
+ if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
+ (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
+ * condition |= ENET_SOCKET_WAIT_SEND;
- if (FD_ISSET (socket, & readSet))
- * condition |= ENET_SOCKET_WAIT_RECEIVE;
+ if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
+ (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
+ * condition |= ENET_SOCKET_WAIT_RECEIVE;
return 0;
#endif
-*/
}
#endif
Modified: code/branches/ipv6/src/external/enet/win32.c
===================================================================
--- code/branches/ipv6/src/external/enet/win32.c 2010-09-08 23:09:09 UTC (rev 7389)
+++ code/branches/ipv6/src/external/enet/win32.c 2010-09-09 14:30:50 UTC (rev 7390)
@@ -52,77 +52,139 @@
timeBase = (enet_uint32) timeGetTime () - newTimeBase;
}
+static enet_uint16
+enet_af (ENetAddressFamily family)
+{
+ if (family == ENET_IPV4)
+ return AF_INET;
+ if (family == ENET_IPV6)
+ return AF_INET6;
+ return 0;
+}
+
+static socklen_t
+enet_sa_size (ENetAddressFamily family)
+{
+ if (family == ENET_IPV4)
+ return sizeof (SOCKADDR_IN);
+ if (family == ENET_IPV6)
+ return sizeof (SOCKADDR_IN6);
+ return 0;
+}
+
+static ENetAddressFamily
+enet_address_set_address (ENetAddress * address, const SOCKADDR * sin)
+{
+ memset (address, 0, sizeof (ENetAddress));
+ if (sin -> sa_family == AF_INET)
+ {
+ address -> host = enet_address_map4 ((((SOCKADDR_IN *) sin) -> sin_addr.s_addr));
+ //address -> scopeID = 0;
+ address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN *) sin) -> sin_port);
+ return ENET_IPV4;
+ }
+ if (sin -> sa_family == AF_INET6)
+ {
+ address -> host = * (ENetHostAddress *) & ((SOCKADDR_IN6 *) sin) -> sin6_addr;
+ address -> scopeID = ((SOCKADDR_IN6 *) sin) -> sin6_scope_id;
+ address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN6 *) sin) -> sin6_port);
+ return ENET_IPV6;
+ }
+ return ENET_NO_ADDRESS_FAMILY;
+}
+
+static int
+enet_address_set_sin (SOCKADDR * sin, const ENetAddress * address, ENetAddressFamily family)
+{
+ memset (sin, 0, enet_sa_size(family));
+ if (family == ENET_IPV4 &&
+ (enet_get_address_family (address) == ENET_IPV4 ||
+ !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
+ {
+ ((SOCKADDR_IN *) sin) -> sin_family = AF_INET;
+ ((SOCKADDR_IN *) sin) -> sin_addr = * (IN_ADDR *) & address -> host.addr[12];
+ ((SOCKADDR_IN *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
+ return 0;
+ }
+ else if (family == ENET_IPV6)
+ {
+ ((SOCKADDR_IN6 *) sin) -> sin6_family = AF_INET6;
+ ((SOCKADDR_IN6 *) sin) -> sin6_addr = * (IN6_ADDR *) & address -> host;
+ ((SOCKADDR_IN6 *) sin) -> sin6_scope_id = address -> scopeID;
+ ((SOCKADDR_IN6 *) sin) -> sin6_port = ENET_HOST_TO_NET_16 (address -> port);
+ return 0;
+ }
+ return -1;
+}
+
int
enet_address_set_host (ENetAddress * address, const char * name)
{
- struct hostent * hostEntry;
+ enet_uint16 port = address -> port;
+ ADDRINFO hints;
+ ADDRINFO * result;
+ ADDRINFO * res;
- hostEntry = gethostbyname (name);
- if (hostEntry == NULL ||
- hostEntry -> h_addrtype != AF_INET)
+ memset(& hints, 0, sizeof (hints));
+ hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG;
+ hints.ai_family = AF_UNSPEC;
+
+ if ( getaddrinfo(name, NULL, &hints, &result) )
+ return -1;
+
+ for (res = result; res != NULL; res = res -> ai_next)
{
- unsigned long host = inet_addr (name);
- if (host == INADDR_NONE)
- return -1;
- address -> host = host;
- return 0;
+ if ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY )
+ break;
}
- address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
+ address -> port = port;
+ freeaddrinfo(result);
+ if (res == NULL) return -1;
return 0;
}
-int
-enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
+static int
+enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
{
- char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
- if (addr == NULL)
+ SOCKADDR_STORAGE sin;
+ enet_address_set_sin((SOCKADDR *) & sin, address, ENET_IPV6);
+
+ if ( getnameinfo((SOCKADDR *) & sin, enet_sa_size (ENET_IPV6), name, nameLength, NULL, 0, flags))
return -1;
- strncpy (name, addr, nameLength);
+
return 0;
}
int
+enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
+{
+ return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST);
+}
+
+int
enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
{
- struct in_addr in;
- struct hostent * hostEntry;
-
- in.s_addr = address -> host;
-
- hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
- if (hostEntry == NULL)
- return enet_address_get_host_ip (address, name, nameLength);
-
- strncpy (name, hostEntry -> h_name, nameLength);
-
- return 0;
+ return enet_address_get_host_x(address, name, nameLength, 0);
}
int
-enet_socket_bind (ENetSocket socket, const ENetAddress * address)
+enet_socket_bind (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
{
- struct sockaddr_in sin;
+ SOCKADDR_STORAGE sin;
- 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);
- sin.sin_addr.s_addr = address -> host;
+ enet_address_set_sin((SOCKADDR *) & sin, address, family);
}
else
{
- sin.sin_port = 0;
- sin.sin_addr.s_addr = INADDR_ANY;
+ ENetAddress address_ = { ENET_HOST_ANY, 0, 0 };
+ enet_address_set_sin((SOCKADDR *) & sin, & address_, family);
}
- return bind (socket,
- (struct sockaddr *) & sin,
- sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
+ return bind (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
}
int
@@ -132,7 +194,7 @@
}
ENetSocket
-enet_socket_create (ENetSocketType type)
+enet_socket_create (ENetSocketType type, ENetAddressFamily family)
{
return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
}
@@ -173,28 +235,23 @@
}
int
-enet_socket_connect (ENetSocket socket, const ENetAddress * address)
+enet_socket_connect (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
{
- struct sockaddr_in sin;
+ SOCKADDR_STORAGE sin;
+ enet_address_set_sin((SOCKADDR *) & sin, address, family);
- memset (& sin, 0, sizeof (struct sockaddr_in));
-
- sin.sin_family = AF_INET;
- 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)) == SOCKET_ERROR ? -1 : 0;
+ return connect (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0;
}
ENetSocket
-enet_socket_accept (ENetSocket socket, ENetAddress * address)
+enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family)
{
SOCKET result;
- struct sockaddr_in sin;
- int sinLength = sizeof (struct sockaddr_in);
+ SOCKADDR_STORAGE sin;
+ int sinLength = enet_sa_size (family);
result = accept (socket,
- address != NULL ? (struct sockaddr *) & sin : NULL,
+ address != NULL ? (SOCKADDR *) & sin : NULL,
address != NULL ? & sinLength : NULL);
if (result == INVALID_SOCKET)
@@ -202,8 +259,7 @@
if (address != NULL)
{
- address -> host = (enet_uint32) sin.sin_addr.s_addr;
- address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
+ enet_address_set_address(address, (SOCKADDR *) & sin);
}
return result;
@@ -219,18 +275,15 @@
enet_socket_send (ENetSocket socket,
const ENetAddress * address,
const ENetBuffer * buffers,
- size_t bufferCount)
+ size_t bufferCount,
+ ENetAddressFamily family)
{
- struct sockaddr_in sin;
+ SOCKADDR_STORAGE sin;
DWORD sentLength;
if (address != NULL)
{
- memset (& sin, 0, sizeof (struct sockaddr_in));
-
- sin.sin_family = AF_INET;
- sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
- sin.sin_addr.s_addr = address -> host;
+ enet_address_set_sin((SOCKADDR *) & sin, address, family);
}
if (WSASendTo (socket,
@@ -238,8 +291,8 @@
(DWORD) bufferCount,
& sentLength,
0,
- address != NULL ? (struct sockaddr *) & sin : 0,
- address != NULL ? sizeof (struct sockaddr_in) : 0,
+ address != NULL ? (SOCKADDR *) & sin : 0,
+ address != NULL ? enet_sa_size (family) : 0,
NULL,
NULL) == SOCKET_ERROR)
{
@@ -256,19 +309,20 @@
enet_socket_receive (ENetSocket socket,
ENetAddress * address,
ENetBuffer * buffers,
- size_t bufferCount)
+ size_t bufferCount,
+ ENetAddressFamily family)
{
- INT sinLength = sizeof (struct sockaddr_in);
+ INT sinLength = enet_sa_size (family);
DWORD flags = 0,
recvLength;
- struct sockaddr_in sin;
+ SOCKADDR_STORAGE sin;
if (WSARecvFrom (socket,
(LPWSABUF) buffers,
(DWORD) bufferCount,
& recvLength,
& flags,
- address != NULL ? (struct sockaddr *) & sin : NULL,
+ address != NULL ? (SOCKADDR *) & sin : NULL,
address != NULL ? & sinLength : NULL,
NULL,
NULL) == SOCKET_ERROR)
@@ -288,8 +342,7 @@
if (address != NULL)
{
- address -> host = (enet_uint32) sin.sin_addr.s_addr;
- address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
+ enet_address_set_address(address, (SOCKADDR *) & sin);
}
return (int) recvLength;
@@ -307,26 +360,42 @@
}
int
-enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
+enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
{
fd_set readSet, writeSet;
struct timeval timeVal;
int selectCount;
-
+
timeVal.tv_sec = timeout / 1000;
timeVal.tv_usec = (timeout % 1000) * 1000;
-
+
FD_ZERO (& readSet);
FD_ZERO (& writeSet);
if (* condition & ENET_SOCKET_WAIT_SEND)
- FD_SET (socket, & writeSet);
+ {
+ if (socket4 != ENET_SOCKET_NULL)
+ FD_SET (socket4, & writeSet);
+ if (socket6 != ENET_SOCKET_NULL)
+ FD_SET (socket6, & writeSet);
+ }
if (* condition & ENET_SOCKET_WAIT_RECEIVE)
- FD_SET (socket, & readSet);
+ {
+ if (socket4 != ENET_SOCKET_NULL)
+ FD_SET (socket4, & readSet);
+ if (socket6 != ENET_SOCKET_NULL)
+ FD_SET (socket6, & readSet);
+ }
- selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
+ ENetSocket maxSocket = 0;
+ if (socket4 != ENET_SOCKET_NULL)
+ maxSocket = socket4;
+ if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket)
+ maxSocket = socket6;
+ selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal);
+
if (selectCount < 0)
return -1;
@@ -335,14 +404,16 @@
if (selectCount == 0)
return 0;
- if (FD_ISSET (socket, & writeSet))
- * condition |= ENET_SOCKET_WAIT_SEND;
-
- if (FD_ISSET (socket, & readSet))
- * condition |= ENET_SOCKET_WAIT_RECEIVE;
+ if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) ||
+ (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) )
+ * condition |= ENET_SOCKET_WAIT_SEND;
+ if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) ||
+ (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) )
+ * condition |= ENET_SOCKET_WAIT_RECEIVE;
+
return 0;
-}
+}
#endif
More information about the Orxonox-commit
mailing list