Changeset 7390 for code/branches
- Timestamp:
- Sep 9, 2010, 4:30:50 PM (14 years ago)
- Location:
- code/branches/ipv6/src/external/enet
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ipv6/src/external/enet/CMakeLists.txt
r7385 r7390 27 27 include/enet/unix.h 28 28 include/enet/utility.h 29 #include/enet/win32.h29 include/enet/win32.h 30 30 31 31 COMPILATION_BEGIN ENetCompilation.cpp … … 38 38 protocol.c 39 39 unix.c 40 #win32.c40 win32.c 41 41 COMPILATION_END 42 42 ) -
code/branches/ipv6/src/external/enet/include/enet/enet.h
r7389 r7390 78 78 { 79 79 ENetHostAddress host; 80 enet_uint32 scopeID; //FIXME: this is of different size on Windows 80 #ifdef WIN32 81 u_long scopeID; 82 #else 83 uint32_t scopeID; 84 #endif 81 85 enet_uint16 port; 82 86 } ENetAddress; -
code/branches/ipv6/src/external/enet/include/enet/win32.h
r7328 r7390 15 15 #include <stdlib.h> 16 16 #include <winsock2.h> 17 #include <ws2tcpip.h> 17 18 18 19 typedef SOCKET ENetSocket; -
code/branches/ipv6/src/external/enet/patches/0001-use-getaddrinfo-for-lookup-in-unix.c.patch
r7378 r7390 2 2 From: Adrian Friedli <adi@koalatux.ch> 3 3 Date: Thu, 2 Sep 2010 14:26:42 +0200 4 Subject: [PATCH 1/ 4] use getaddrinfo for lookup in unix.c4 Subject: [PATCH 1/5] use getaddrinfo for lookup in unix.c 5 5 6 6 --- -
code/branches/ipv6/src/external/enet/patches/0002-basic-IPv6-support-on-Linux-systems.patch
r7378 r7390 2 2 From: Adrian Friedli <adi@koalatux.ch> 3 3 Date: Thu, 2 Sep 2010 14:27:07 +0200 4 Subject: [PATCH 2/ 4] basic IPv6 support on Linux systems4 Subject: [PATCH 2/5] basic IPv6 support on Linux systems 5 5 6 6 this uses IPv4-mapped IPv6 addresses -
code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch
r7389 r7390 1 From af3c0910bd25d73b1a3c06bbfa4e0a3c6b96ddc5Mon Sep 17 00:00:00 20011 From b26e4ef3fa9c0139fc2ec086d2243b809365d683 Mon Sep 17 00:00:00 2001 2 2 From: Adrian Friedli <adi@koalatux.ch> 3 3 Date: Mon, 6 Sep 2010 14:58:50 +0200 4 Subject: [PATCH 3/ 4] using address family in functions4 Subject: [PATCH 3/5] using address family in functions 5 5 6 6 --- … … 8 8 include/enet/enet.h | 22 +++++++++--- 9 9 protocol.c | 5 ++- 10 unix.c | 8 7++++++++++++++++++++++++++++++++------------------11 4 files changed, 7 7insertions(+), 41 deletions(-)10 unix.c | 86 ++++++++++++++++++++++++++++++++------------------ 11 4 files changed, 76 insertions(+), 41 deletions(-) 12 12 13 13 diff --git a/host.c b/host.c … … 91 91 92 92 diff --git a/unix.c b/unix.c 93 index de032bb.. 13a24d810064493 index de032bb..475c6e3 100644 94 94 --- a/unix.c 95 95 +++ b/unix.c 96 @@ -71,7 +71,2 8@@ enet_time_set (enet_uint32 newTimeBase)96 @@ -71,7 +71,27 @@ enet_time_set (enet_uint32 newTimeBase) 97 97 timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase; 98 98 } … … 119 119 +} 120 120 + 121 +122 121 +static ENetAddressFamily 123 122 enet_address_set_address (ENetAddress * address, const struct sockaddr * sin) 124 123 { 125 124 memset (address, 0, sizeof (ENetAddress)); 126 @@ -80,32 +10 1,31 @@ enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)125 @@ -80,32 +100,31 @@ enet_address_set_address (ENetAddress * address, const struct sockaddr * sin) 127 126 address -> host = enet_address_map4 ((((struct sockaddr_in *) sin) -> sin_addr.s_addr)); 128 127 //address -> scopeID = 0; … … 164 163 ((struct sockaddr_in6 *) sin) -> sin6_addr = * (struct in6_addr *) & address -> host; 165 164 ((struct sockaddr_in6 *) sin) -> sin6_scope_id = address -> scopeID; 166 @@ -132,7 +15 2,7 @@ enet_address_set_host (ENetAddress * address, const char * name)165 @@ -132,7 +151,7 @@ enet_address_set_host (ENetAddress * address, const char * name) 167 166 168 167 for (res = result; res != NULL; res = res -> ai_next) … … 173 172 } 174 173 175 @@ -147,9 +16 7,9 @@ static int174 @@ -147,9 +166,9 @@ static int 176 175 enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags) 177 176 { … … 185 184 186 185 return 0; 187 @@ -168,21 +18 8,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng186 @@ -168,21 +187,21 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng 188 187 } 189 188 … … 211 210 212 211 int 213 @@ -192,13 +21 2,16 @@ enet_socket_listen (ENetSocket socket, int backlog)212 @@ -192,13 +211,16 @@ enet_socket_listen (ENetSocket socket, int backlog) 214 213 } 215 214 … … 232 231 233 232 return sock; 234 @@ -241,25 +26 4,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)233 @@ -241,25 +263,25 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value) 235 234 } 236 235 … … 264 263 return ENET_SOCKET_NULL; 265 264 266 @@ -281,7 +30 4,8 @@ int265 @@ -281,7 +303,8 @@ int 267 266 enet_socket_send (ENetSocket socket, 268 267 const ENetAddress * address, … … 274 273 struct msghdr msgHdr; 275 274 struct sockaddr_storage sin; 276 @@ -291,9 +31 5,9 @@ enet_socket_send (ENetSocket socket,275 @@ -291,9 +314,9 @@ enet_socket_send (ENetSocket socket, 277 276 278 277 if (address != NULL) … … 286 285 287 286 msgHdr.msg_iov = (struct iovec *) buffers; 288 @@ -316,7 +3 40,8 @@ int287 @@ -316,7 +339,8 @@ int 289 288 enet_socket_receive (ENetSocket socket, 290 289 ENetAddress * address, … … 296 295 struct msghdr msgHdr; 297 296 struct sockaddr_storage sin; 298 @@ -327,7 +35 2,7 @@ enet_socket_receive (ENetSocket socket,297 @@ -327,7 +351,7 @@ enet_socket_receive (ENetSocket socket, 299 298 if (address != NULL) 300 299 { -
code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch
r7389 r7390 1 From 9801a6bcd072870248a6b07245fc09a9492f8f51Mon Sep 17 00:00:00 20011 From 73fa28a84ce456561d3912578121a30bc8263c50 Mon Sep 17 00:00:00 2001 2 2 From: Adrian Friedli <adi@koalatux.ch> 3 3 Date: Wed, 8 Sep 2010 12:50:04 +0200 4 Subject: [PATCH 4/ 4] using two separate sockets for IPv4 and IPv64 Subject: [PATCH 4/5] using two separate sockets for IPv4 and IPv6 5 5 6 6 --- 7 host.c | 53 +++++++++++++++++++++++++++ ++++++++++-------------8 include/enet/enet.h | 11 ++++++ ++-9 protocol.c | 47 ++++++++++++++++++++++++++++ +++++++++++-----10 unix.c | 47 ++++++++++++++++++++++++++++++++------------11 4 files changed, 1 23 insertions(+), 35deletions(-)7 host.c | 53 +++++++++++++++++++++++++++--------- 8 include/enet/enet.h | 11 ++++++- 9 protocol.c | 47 ++++++++++++++++++++++++++++---- 10 unix.c | 74 +++++++++++++++++++++++++++++++++++++------------- 11 4 files changed, 144 insertions(+), 41 deletions(-) 12 12 13 13 diff --git a/host.c b/host.c … … 233 233 host -> serviceTime = enet_time_get (); 234 234 diff --git a/unix.c b/unix.c 235 index 13a24d8..22ffb76100644235 index 475c6e3..751cb6f 100644 236 236 --- a/unix.c 237 237 +++ b/unix.c 238 @@ -11 7,7 +117,9 @@ static int238 @@ -116,7 +116,9 @@ static int 239 239 enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, ENetAddressFamily family) 240 240 { … … 247 247 ((struct sockaddr_in *) sin) -> sin_family = AF_INET; 248 248 ((struct sockaddr_in *) sin) -> sin_addr = * (struct in_addr *) & address -> host.addr[12]; 249 @@ -21 9,7 +221,7 @@ enet_socket_create (ENetSocketType type, ENetAddressFamily family)249 @@ -218,7 +220,7 @@ enet_socket_create (ENetSocketType type, ENetAddressFamily family) 250 250 #ifdef IPV6_V6ONLY 251 251 if (family == ENET_IPV6) … … 256 256 } 257 257 #endif // IPV6_V6ONLY 258 @@ -39 3,22 +395,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket258 @@ -392,22 +394,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket 259 259 } 260 260 … … 263 263 +enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout) 264 264 { 265 -#ifdef HAS_POLL265 #ifdef HAS_POLL 266 266 - struct pollfd pollSocket; 267 +//#ifdef HAS_POLL268 267 + struct pollfd pollSocket[2]; 269 268 int pollCount; … … 304 303 if (pollCount < 0) 305 304 return -1; 306 @@ -41 8,13 +436,15@@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou305 @@ -417,10 +435,10 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou 307 306 if (pollCount == 0) 308 307 return 0; … … 317 316 318 317 return 0; 319 +/* 320 +FIXME: implement or remove this 321 #else 322 fd_set readSet, writeSet; 323 struct timeval timeVal; 324 @@ -460,6 +480,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou 318 @@ -436,12 +454,28 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou 319 FD_ZERO (& writeSet); 320 321 if (* condition & ENET_SOCKET_WAIT_SEND) 322 - FD_SET (socket, & writeSet); 323 + { 324 + if (socket4 != ENET_SOCKET_NULL) 325 + FD_SET (socket4, & writeSet); 326 + if (socket6 != ENET_SOCKET_NULL) 327 + FD_SET (socket6, & writeSet); 328 + } 329 330 if (* condition & ENET_SOCKET_WAIT_RECEIVE) 331 - FD_SET (socket, & readSet); 332 + { 333 + if (socket4 != ENET_SOCKET_NULL) 334 + FD_SET (socket4, & readSet); 335 + if (socket6 != ENET_SOCKET_NULL) 336 + FD_SET (socket6, & readSet); 337 + } 338 + 339 + ENetSocket maxSocket = 0; 340 + if (socket4 != ENET_SOCKET_NULL) 341 + maxSocket = socket4; 342 + if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket) 343 + maxSocket = socket6; 344 345 - selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal); 346 + selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal); 347 348 if (selectCount < 0) 349 return -1; 350 @@ -451,11 +485,13 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou 351 if (selectCount == 0) 352 return 0; 353 354 - if (FD_ISSET (socket, & writeSet)) 355 - * condition |= ENET_SOCKET_WAIT_SEND; 356 + if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) || 357 + (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) ) 358 + * condition |= ENET_SOCKET_WAIT_SEND; 359 360 - if (FD_ISSET (socket, & readSet)) 361 - * condition |= ENET_SOCKET_WAIT_RECEIVE; 362 + if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) || 363 + (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) ) 364 + * condition |= ENET_SOCKET_WAIT_RECEIVE; 325 365 326 366 return 0; 327 #endif328 +*/329 }330 331 367 #endif 332 368 -- -
code/branches/ipv6/src/external/enet/unix.c
r7389 r7390 92 92 } 93 93 94 95 94 static ENetAddressFamily 96 95 enet_address_set_address (ENetAddress * address, const struct sockaddr * sin) … … 398 397 enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout) 399 398 { 400 //#ifdef HAS_POLL399 #ifdef HAS_POLL 401 400 struct pollfd pollSocket[2]; 402 401 int pollCount; … … 444 443 445 444 return 0; 446 /*447 FIXME: implement or remove this448 445 #else 449 446 fd_set readSet, writeSet; … … 458 455 459 456 if (* condition & ENET_SOCKET_WAIT_SEND) 460 FD_SET (socket, & writeSet); 457 { 458 if (socket4 != ENET_SOCKET_NULL) 459 FD_SET (socket4, & writeSet); 460 if (socket6 != ENET_SOCKET_NULL) 461 FD_SET (socket6, & writeSet); 462 } 461 463 462 464 if (* condition & ENET_SOCKET_WAIT_RECEIVE) 463 FD_SET (socket, & readSet); 464 465 selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal); 465 { 466 if (socket4 != ENET_SOCKET_NULL) 467 FD_SET (socket4, & readSet); 468 if (socket6 != ENET_SOCKET_NULL) 469 FD_SET (socket6, & readSet); 470 } 471 472 ENetSocket maxSocket = 0; 473 if (socket4 != ENET_SOCKET_NULL) 474 maxSocket = socket4; 475 if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket) 476 maxSocket = socket6; 477 478 selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal); 466 479 467 480 if (selectCount < 0) … … 473 486 return 0; 474 487 475 if (FD_ISSET (socket, & writeSet)) 476 * condition |= ENET_SOCKET_WAIT_SEND; 477 478 if (FD_ISSET (socket, & readSet)) 479 * condition |= ENET_SOCKET_WAIT_RECEIVE; 480 481 return 0; 482 #endif 483 */ 484 } 485 486 #endif 487 488 if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) || 489 (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) ) 490 * condition |= ENET_SOCKET_WAIT_SEND; 491 492 if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) || 493 (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) ) 494 * condition |= ENET_SOCKET_WAIT_RECEIVE; 495 496 return 0; 497 #endif 498 } 499 500 #endif 501 -
code/branches/ipv6/src/external/enet/win32.c
r7328 r7390 53 53 } 54 54 55 static enet_uint16 56 enet_af (ENetAddressFamily family) 57 { 58 if (family == ENET_IPV4) 59 return AF_INET; 60 if (family == ENET_IPV6) 61 return AF_INET6; 62 return 0; 63 } 64 65 static socklen_t 66 enet_sa_size (ENetAddressFamily family) 67 { 68 if (family == ENET_IPV4) 69 return sizeof (SOCKADDR_IN); 70 if (family == ENET_IPV6) 71 return sizeof (SOCKADDR_IN6); 72 return 0; 73 } 74 75 static ENetAddressFamily 76 enet_address_set_address (ENetAddress * address, const SOCKADDR * sin) 77 { 78 memset (address, 0, sizeof (ENetAddress)); 79 if (sin -> sa_family == AF_INET) 80 { 81 address -> host = enet_address_map4 ((((SOCKADDR_IN *) sin) -> sin_addr.s_addr)); 82 //address -> scopeID = 0; 83 address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN *) sin) -> sin_port); 84 return ENET_IPV4; 85 } 86 if (sin -> sa_family == AF_INET6) 87 { 88 address -> host = * (ENetHostAddress *) & ((SOCKADDR_IN6 *) sin) -> sin6_addr; 89 address -> scopeID = ((SOCKADDR_IN6 *) sin) -> sin6_scope_id; 90 address -> port = ENET_NET_TO_HOST_16 (((SOCKADDR_IN6 *) sin) -> sin6_port); 91 return ENET_IPV6; 92 } 93 return ENET_NO_ADDRESS_FAMILY; 94 } 95 96 static int 97 enet_address_set_sin (SOCKADDR * sin, const ENetAddress * address, ENetAddressFamily family) 98 { 99 memset (sin, 0, enet_sa_size(family)); 100 if (family == ENET_IPV4 && 101 (enet_get_address_family (address) == ENET_IPV4 || 102 !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress)))) 103 { 104 ((SOCKADDR_IN *) sin) -> sin_family = AF_INET; 105 ((SOCKADDR_IN *) sin) -> sin_addr = * (IN_ADDR *) & address -> host.addr[12]; 106 ((SOCKADDR_IN *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port); 107 return 0; 108 } 109 else if (family == ENET_IPV6) 110 { 111 ((SOCKADDR_IN6 *) sin) -> sin6_family = AF_INET6; 112 ((SOCKADDR_IN6 *) sin) -> sin6_addr = * (IN6_ADDR *) & address -> host; 113 ((SOCKADDR_IN6 *) sin) -> sin6_scope_id = address -> scopeID; 114 ((SOCKADDR_IN6 *) sin) -> sin6_port = ENET_HOST_TO_NET_16 (address -> port); 115 return 0; 116 } 117 return -1; 118 } 119 55 120 int 56 121 enet_address_set_host (ENetAddress * address, const char * name) 57 122 { 58 struct hostent * hostEntry; 59 60 hostEntry = gethostbyname (name); 61 if (hostEntry == NULL || 62 hostEntry -> h_addrtype != AF_INET) 63 { 64 unsigned long host = inet_addr (name); 65 if (host == INADDR_NONE) 66 return -1; 67 address -> host = host; 68 return 0; 69 } 70 71 address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; 123 enet_uint16 port = address -> port; 124 ADDRINFO hints; 125 ADDRINFO * result; 126 ADDRINFO * res; 127 128 memset(& hints, 0, sizeof (hints)); 129 hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG; 130 hints.ai_family = AF_UNSPEC; 131 132 if ( getaddrinfo(name, NULL, &hints, &result) ) 133 return -1; 134 135 for (res = result; res != NULL; res = res -> ai_next) 136 { 137 if ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY ) 138 break; 139 } 140 141 address -> port = port; 142 freeaddrinfo(result); 143 if (res == NULL) return -1; 144 145 return 0; 146 } 147 148 static int 149 enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags) 150 { 151 SOCKADDR_STORAGE sin; 152 enet_address_set_sin((SOCKADDR *) & sin, address, ENET_IPV6); 153 154 if ( getnameinfo((SOCKADDR *) & sin, enet_sa_size (ENET_IPV6), name, nameLength, NULL, 0, flags)) 155 return -1; 72 156 73 157 return 0; … … 77 161 enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength) 78 162 { 79 char * addr = inet_ntoa (* (struct in_addr *) & address -> host); 80 if (addr == NULL) 81 return -1; 82 strncpy (name, addr, nameLength); 83 return 0; 163 return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST); 84 164 } 85 165 … … 87 167 enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength) 88 168 { 89 struct in_addr in; 90 struct hostent * hostEntry; 91 92 in.s_addr = address -> host; 93 94 hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET); 95 if (hostEntry == NULL) 96 return enet_address_get_host_ip (address, name, nameLength); 97 98 strncpy (name, hostEntry -> h_name, nameLength); 99 100 return 0; 101 } 102 103 int 104 enet_socket_bind (ENetSocket socket, const ENetAddress * address) 105 { 106 struct sockaddr_in sin; 107 108 memset (& sin, 0, sizeof (struct sockaddr_in)); 109 110 sin.sin_family = AF_INET; 169 return enet_address_get_host_x(address, name, nameLength, 0); 170 } 171 172 int 173 enet_socket_bind (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family) 174 { 175 SOCKADDR_STORAGE sin; 111 176 112 177 if (address != NULL) 113 178 { 114 sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); 115 sin.sin_addr.s_addr = address -> host; 179 enet_address_set_sin((SOCKADDR *) & sin, address, family); 116 180 } 117 181 else 118 182 { 119 sin.sin_port = 0; 120 sin.sin_addr.s_addr = INADDR_ANY; 121 } 122 123 return bind (socket, 124 (struct sockaddr *) & sin, 125 sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0; 183 ENetAddress address_ = { ENET_HOST_ANY, 0, 0 }; 184 enet_address_set_sin((SOCKADDR *) & sin, & address_, family); 185 } 186 187 return bind (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0; 126 188 } 127 189 … … 133 195 134 196 ENetSocket 135 enet_socket_create (ENetSocketType type )197 enet_socket_create (ENetSocketType type, ENetAddressFamily family) 136 198 { 137 199 return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); … … 174 236 175 237 int 176 enet_socket_connect (ENetSocket socket, const ENetAddress * address) 177 { 178 struct sockaddr_in sin; 179 180 memset (& sin, 0, sizeof (struct sockaddr_in)); 181 182 sin.sin_family = AF_INET; 183 sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); 184 sin.sin_addr.s_addr = address -> host; 185 186 return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0; 238 enet_socket_connect (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family) 239 { 240 SOCKADDR_STORAGE sin; 241 enet_address_set_sin((SOCKADDR *) & sin, address, family); 242 243 return connect (socket, (SOCKADDR *) & sin, enet_sa_size(family)) == SOCKET_ERROR ? -1 : 0; 187 244 } 188 245 189 246 ENetSocket 190 enet_socket_accept (ENetSocket socket, ENetAddress * address )247 enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family) 191 248 { 192 249 SOCKET result; 193 struct sockaddr_insin;194 int sinLength = sizeof (struct sockaddr_in);250 SOCKADDR_STORAGE sin; 251 int sinLength = enet_sa_size (family); 195 252 196 253 result = accept (socket, 197 address != NULL ? ( struct sockaddr *) & sin : NULL,254 address != NULL ? (SOCKADDR *) & sin : NULL, 198 255 address != NULL ? & sinLength : NULL); 199 256 … … 203 260 if (address != NULL) 204 261 { 205 address -> host = (enet_uint32) sin.sin_addr.s_addr; 206 address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); 262 enet_address_set_address(address, (SOCKADDR *) & sin); 207 263 } 208 264 … … 220 276 const ENetAddress * address, 221 277 const ENetBuffer * buffers, 222 size_t bufferCount) 223 { 224 struct sockaddr_in sin; 278 size_t bufferCount, 279 ENetAddressFamily family) 280 { 281 SOCKADDR_STORAGE sin; 225 282 DWORD sentLength; 226 283 227 284 if (address != NULL) 228 285 { 229 memset (& sin, 0, sizeof (struct sockaddr_in)); 230 231 sin.sin_family = AF_INET; 232 sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); 233 sin.sin_addr.s_addr = address -> host; 286 enet_address_set_sin((SOCKADDR *) & sin, address, family); 234 287 } 235 288 … … 239 292 & sentLength, 240 293 0, 241 address != NULL ? ( struct sockaddr*) & sin : 0,242 address != NULL ? sizeof (struct sockaddr_in) : 0,294 address != NULL ? (SOCKADDR *) & sin : 0, 295 address != NULL ? enet_sa_size (family) : 0, 243 296 NULL, 244 297 NULL) == SOCKET_ERROR) … … 257 310 ENetAddress * address, 258 311 ENetBuffer * buffers, 259 size_t bufferCount) 260 { 261 INT sinLength = sizeof (struct sockaddr_in); 312 size_t bufferCount, 313 ENetAddressFamily family) 314 { 315 INT sinLength = enet_sa_size (family); 262 316 DWORD flags = 0, 263 317 recvLength; 264 struct sockaddr_insin;318 SOCKADDR_STORAGE sin; 265 319 266 320 if (WSARecvFrom (socket, … … 269 323 & recvLength, 270 324 & flags, 271 address != NULL ? ( struct sockaddr*) & sin : NULL,325 address != NULL ? (SOCKADDR *) & sin : NULL, 272 326 address != NULL ? & sinLength : NULL, 273 327 NULL, … … 289 343 if (address != NULL) 290 344 { 291 address -> host = (enet_uint32) sin.sin_addr.s_addr; 292 address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); 345 enet_address_set_address(address, (SOCKADDR *) & sin); 293 346 } 294 347 … … 308 361 309 362 int 310 enet_socket_wait (ENetSocket socket , enet_uint32 * condition, enet_uint32 timeout)363 enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout) 311 364 { 312 365 fd_set readSet, writeSet; 313 366 struct timeval timeVal; 314 367 int selectCount; 315 368 316 369 timeVal.tv_sec = timeout / 1000; 317 370 timeVal.tv_usec = (timeout % 1000) * 1000; 318 371 319 372 FD_ZERO (& readSet); 320 373 FD_ZERO (& writeSet); 321 374 322 375 if (* condition & ENET_SOCKET_WAIT_SEND) 323 FD_SET (socket, & writeSet); 376 { 377 if (socket4 != ENET_SOCKET_NULL) 378 FD_SET (socket4, & writeSet); 379 if (socket6 != ENET_SOCKET_NULL) 380 FD_SET (socket6, & writeSet); 381 } 324 382 325 383 if (* condition & ENET_SOCKET_WAIT_RECEIVE) 326 FD_SET (socket, & readSet); 327 328 selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal); 384 { 385 if (socket4 != ENET_SOCKET_NULL) 386 FD_SET (socket4, & readSet); 387 if (socket6 != ENET_SOCKET_NULL) 388 FD_SET (socket6, & readSet); 389 } 390 391 ENetSocket maxSocket = 0; 392 if (socket4 != ENET_SOCKET_NULL) 393 maxSocket = socket4; 394 if (socket6 != ENET_SOCKET_NULL && socket6 > maxSocket) 395 maxSocket = socket6; 396 397 selectCount = select (maxSocket + 1, & readSet, & writeSet, NULL, & timeVal); 329 398 330 399 if (selectCount < 0) … … 336 405 return 0; 337 406 338 if (FD_ISSET (socket, & writeSet)) 339 * condition |= ENET_SOCKET_WAIT_SEND; 340 341 if (FD_ISSET (socket, & readSet)) 342 * condition |= ENET_SOCKET_WAIT_RECEIVE; 343 344 return 0; 345 } 407 if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & writeSet)) || 408 (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & writeSet)) ) 409 * condition |= ENET_SOCKET_WAIT_SEND; 410 411 if ( (socket4 != ENET_SOCKET_NULL && FD_ISSET (socket4, & readSet)) || 412 (socket6 != ENET_SOCKET_NULL && FD_ISSET (socket6, & readSet)) ) 413 * condition |= ENET_SOCKET_WAIT_RECEIVE; 414 415 return 0; 416 } 346 417 347 418 #endif
Note: See TracChangeset
for help on using the changeset viewer.