Changeset 7389 for code/branches/ipv6/src
- Timestamp:
- Sep 9, 2010, 1:09:09 AM (14 years ago)
- Location:
- code/branches/ipv6/src/external/enet
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ipv6/src/external/enet/host.c
r7377 r7389 7 7 #include <time.h> 8 8 #include "enet/enet.h" 9 10 static ENetSocket 11 enet_socket_create_bind (const ENetAddress * address, ENetAddressFamily family) 12 { 13 ENetSocket socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, family); 14 if (socket == ENET_SOCKET_NULL) 15 return ENET_SOCKET_NULL; 16 17 if (address != NULL && enet_socket_bind (socket, address, family) < 0) 18 { 19 enet_socket_destroy (socket); 20 return ENET_SOCKET_NULL; 21 } 22 23 enet_socket_set_option (socket, ENET_SOCKOPT_NONBLOCK, 1); 24 enet_socket_set_option (socket, ENET_SOCKOPT_BROADCAST, 1); 25 enet_socket_set_option (socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE); 26 enet_socket_set_option (socket, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE); 27 28 return socket; 29 } 9 30 10 31 /** @defgroup host ENet host functions … … 49 70 memset (host -> peers, 0, peerCount * sizeof (ENetPeer)); 50 71 51 52 // FIXME: check address for ANY_ADRESS if not only bind to specific protocol 53 // FIXME: allow to fail one of the two protocols 54 /* IPv4 */ 55 host -> socket4 = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV4); 56 if (host -> socket4 == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket4, address, ENET_IPV4) < 0)) 57 { 58 if (host -> socket4 != ENET_SOCKET_NULL) 59 enet_socket_destroy (host -> socket4); 60 61 enet_free (host -> peers); 62 enet_free (host); 63 64 return NULL; 65 } 66 67 enet_socket_set_option (host -> socket4, ENET_SOCKOPT_NONBLOCK, 1); 68 enet_socket_set_option (host -> socket4, ENET_SOCKOPT_BROADCAST, 1); 69 enet_socket_set_option (host -> socket4, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE); 70 enet_socket_set_option (host -> socket4, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE); 71 72 /* IPv6 */ 73 host -> socket6 = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV6); 74 if (host -> socket6 == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket6, address, ENET_IPV6) < 0)) 75 { 76 if (host -> socket6 != ENET_SOCKET_NULL) 77 { 78 enet_socket_destroy (host -> socket4); 79 enet_socket_destroy (host -> socket6); 80 } 81 82 enet_free (host -> peers); 83 enet_free (host); 84 85 return NULL; 86 } 87 88 enet_socket_set_option (host -> socket6, ENET_SOCKOPT_NONBLOCK, 1); 89 enet_socket_set_option (host -> socket6, ENET_SOCKOPT_BROADCAST, 1); 90 enet_socket_set_option (host -> socket6, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE); 91 enet_socket_set_option (host -> socket6, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE); 92 72 int family = (address == NULL || !memcmp (& address -> host, & ENET_HOST_ANY, sizeof (ENetHostAddress))) ? 73 ENET_IPV4 | ENET_IPV6 : 74 enet_get_address_family (address); 75 76 host -> socket4 = (family & ENET_IPV4) ? 77 enet_socket_create_bind (address, ENET_IPV4) : 78 ENET_SOCKET_NULL; 79 host -> socket6 = (family & ENET_IPV6) ? 80 enet_socket_create_bind (address, ENET_IPV6) : 81 ENET_SOCKET_NULL; 82 83 if (host -> socket4 == ENET_SOCKET_NULL && host -> socket6 == ENET_SOCKET_NULL) 84 { 85 enet_free (host -> peers); 86 enet_free (host); 87 return NULL; 88 } 93 89 94 90 if (address != NULL) … … 160 156 ENetPeer * currentPeer; 161 157 162 enet_socket_destroy (host -> socket4); 163 enet_socket_destroy (host -> socket6); 158 if (host -> socket4 != ENET_SOCKET_NULL) 159 enet_socket_destroy (host -> socket4); 160 if (host -> socket6 != ENET_SOCKET_NULL) 161 enet_socket_destroy (host -> socket6); 164 162 165 163 for (currentPeer = host -> peers; -
code/branches/ipv6/src/external/enet/include/enet/enet.h
r7377 r7389 88 88 { 89 89 ENET_NO_ADDRESS_FAMILY = 0, 90 ENET_IPV4 = 1,91 ENET_IPV6 = 290 ENET_IPV4 = (1 << 0), 91 ENET_IPV6 = (1 << 1) 92 92 } ENetAddressFamily; 93 93 -
code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch
r7378 r7389 1 From 130babc6f69e07830f73f7757222597117eb1cbaMon Sep 17 00:00:00 20011 From af3c0910bd25d73b1a3c06bbfa4e0a3c6b96ddc5 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 … … 27 27 enet_socket_destroy (host -> socket); 28 28 diff --git a/include/enet/enet.h b/include/enet/enet.h 29 index d3ca971.. 97f055610064429 index d3ca971..7f5876f 100644 30 30 --- a/include/enet/enet.h 31 31 +++ b/include/enet/enet.h … … 39 39 +{ 40 40 + ENET_NO_ADDRESS_FAMILY = 0, 41 + ENET_IPV4 = 1,42 + ENET_IPV6 = 241 + ENET_IPV4 = (1 << 0), 42 + ENET_IPV6 = (1 << 1) 43 43 +} ENetAddressFamily; 44 44 + -
code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch
r7378 r7389 1 From d61448922c08e6801f07c38077623d3bcc513ad4Mon Sep 17 00:00:00 20011 From 9801a6bcd072870248a6b07245fc09a9492f8f51 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 … … 5 5 6 6 --- 7 host.c | 45 ++++++++++++++++++++++++++++++++++++---------8 include/enet/enet.h | 11 ++++++++ +--9 protocol.c | 4 2 ++++++++++++++++++++++++++++++++++++------10 unix.c | 38++++++++++++++++++++++++++------------11 4 files changed, 1 07 insertions(+), 29deletions(-)7 host.c | 53 +++++++++++++++++++++++++++++++++++++------------- 8 include/enet/enet.h | 11 ++++++++- 9 protocol.c | 47 +++++++++++++++++++++++++++++++++++++++----- 10 unix.c | 47 ++++++++++++++++++++++++++++++++------------ 11 4 files changed, 123 insertions(+), 35 deletions(-) 12 12 13 13 diff --git a/host.c b/host.c 14 index 9ccf894.. 85dfa3c10064414 index 9ccf894..46e52c9 100644 15 15 --- a/host.c 16 16 +++ b/host.c 17 @@ -48,11 +48,15 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL 17 @@ -7,6 +7,27 @@ 18 #include <time.h> 19 #include "enet/enet.h" 20 21 +static ENetSocket 22 +enet_socket_create_bind (const ENetAddress * address, ENetAddressFamily family) 23 +{ 24 + ENetSocket socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, family); 25 + if (socket == ENET_SOCKET_NULL) 26 + return ENET_SOCKET_NULL; 27 + 28 + if (address != NULL && enet_socket_bind (socket, address, family) < 0) 29 + { 30 + enet_socket_destroy (socket); 31 + return ENET_SOCKET_NULL; 32 + } 33 + 34 + enet_socket_set_option (socket, ENET_SOCKOPT_NONBLOCK, 1); 35 + enet_socket_set_option (socket, ENET_SOCKOPT_BROADCAST, 1); 36 + enet_socket_set_option (socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE); 37 + enet_socket_set_option (socket, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE); 38 + 39 + return socket; 40 +} 41 + 42 /** @defgroup host ENet host functions 43 @{ 44 */ 45 @@ -48,23 +69,24 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL 18 46 } 19 47 memset (host -> peers, 0, peerCount * sizeof (ENetPeer)); … … 21 49 - host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV6); 22 50 - if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address, ENET_IPV6) < 0)) 23 + 24 + // FIXME: check address for ANY_ADRESS if not only bind to specific protocol 25 + // FIXME: allow to fail one of the two protocols 26 + /* IPv4 */ 27 + host -> socket4 = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV4); 28 + if (host -> socket4 == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket4, address, ENET_IPV4) < 0)) 29 { 51 - { 30 52 - if (host -> socket != ENET_SOCKET_NULL) 31 53 - enet_socket_destroy (host -> socket); 32 + if (host -> socket4 != ENET_SOCKET_NULL) 33 + enet_socket_destroy (host -> socket4); 34 35 enet_free (host -> peers); 36 enet_free (host); 37 @@ -60,10 +64,32 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL 38 return NULL; 54 + int family = (address == NULL || !memcmp (& address -> host, & ENET_HOST_ANY, sizeof (ENetHostAddress))) ? 55 + ENET_IPV4 | ENET_IPV6 : 56 + enet_get_address_family (address); 57 58 - enet_free (host -> peers); 59 - enet_free (host); 60 + host -> socket4 = (family & ENET_IPV4) ? 61 + enet_socket_create_bind (address, ENET_IPV4) : 62 + ENET_SOCKET_NULL; 63 + host -> socket6 = (family & ENET_IPV6) ? 64 + enet_socket_create_bind (address, ENET_IPV6) : 65 + ENET_SOCKET_NULL; 66 67 - return NULL; 68 + if (host -> socket4 == ENET_SOCKET_NULL && host -> socket6 == ENET_SOCKET_NULL) 69 + { 70 + enet_free (host -> peers); 71 + enet_free (host); 72 + return NULL; 39 73 } 40 74 … … 43 77 - enet_socket_set_option (host -> socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE); 44 78 - enet_socket_set_option (host -> socket, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE); 45 + enet_socket_set_option (host -> socket4, ENET_SOCKOPT_NONBLOCK, 1); 46 + enet_socket_set_option (host -> socket4, ENET_SOCKOPT_BROADCAST, 1); 47 + enet_socket_set_option (host -> socket4, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE); 48 + enet_socket_set_option (host -> socket4, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE); 49 + 50 + /* IPv6 */ 51 + host -> socket6 = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV6); 52 + if (host -> socket6 == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket6, address, ENET_IPV6) < 0)) 53 + { 54 + if (host -> socket6 != ENET_SOCKET_NULL) 55 + { 56 + enet_socket_destroy (host -> socket4); 57 + enet_socket_destroy (host -> socket6); 58 + } 59 + 60 + enet_free (host -> peers); 61 + enet_free (host); 62 + 63 + return NULL; 64 + } 65 + 66 + enet_socket_set_option (host -> socket6, ENET_SOCKOPT_NONBLOCK, 1); 67 + enet_socket_set_option (host -> socket6, ENET_SOCKOPT_BROADCAST, 1); 68 + enet_socket_set_option (host -> socket6, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE); 69 + enet_socket_set_option (host -> socket6, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE); 70 + 71 79 - 72 80 if (address != NULL) 73 81 host -> address = * address; 74 @@ -133,7 +159,8 @@ enet_host_destroy (ENetHost * host) 82 83 @@ -133,7 +155,10 @@ enet_host_destroy (ENetHost * host) 75 84 { 76 85 ENetPeer * currentPeer; 77 86 78 87 - enet_socket_destroy (host -> socket); 79 + enet_socket_destroy (host -> socket4); 80 + enet_socket_destroy (host -> socket6); 88 + if (host -> socket4 != ENET_SOCKET_NULL) 89 + enet_socket_destroy (host -> socket4); 90 + if (host -> socket6 != ENET_SOCKET_NULL) 91 + enet_socket_destroy (host -> socket6); 81 92 82 93 for (currentPeer = host -> peers; 83 94 currentPeer < & host -> peers [host -> peerCount]; 84 95 diff --git a/include/enet/enet.h b/include/enet/enet.h 85 index 97f0556..39cf93e10064496 index 7f5876f..616fe7f 100644 86 97 --- a/include/enet/enet.h 87 98 +++ b/include/enet/enet.h … … 119 130 ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32); 120 131 diff --git a/protocol.c b/protocol.c 121 index 4c4850a.. 37f6387100644132 index 4c4850a..505c684 100644 122 133 --- a/protocol.c 123 134 +++ b/protocol.c … … 170 181 host -> receivedDataLength = receivedLength; 171 182 172 @@ -1510,7 +1521,1 2@@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch183 @@ -1510,7 +1521,15 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch 173 184 174 185 currentPeer -> lastSendTime = host -> serviceTime; … … 176 187 - sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount, ENET_IPV6); 177 188 + ENetAddressFamily family = enet_get_address_family (& currentPeer -> address); 178 + sentLength = enet_socket_send (family == ENET_IPV4 ? host -> socket4 : host -> socket6, 189 + ENetSocket socket = family == ENET_IPV4 ? host -> socket4 : host -> socket6; 190 + if (socket == ENET_SOCKET_NULL) 191 + return -1; 192 + sentLength = enet_socket_send (socket, 179 193 + & currentPeer -> address, 180 194 + host -> buffers, … … 184 198 enet_protocol_remove_sent_unreliable_commands (currentPeer); 185 199 186 @@ -1621,7 +16 37,21@@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)200 @@ -1621,7 +1640,23 @@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout) 187 201 break; 188 202 } 189 203 190 204 - switch (enet_protocol_receive_incoming_commands (host, event)) 191 + switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV4)) 205 + if (host -> socket4 != ENET_SOCKET_NULL) 206 + switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV4)) 192 207 + { 193 208 + case 1: … … 203 218 + } 204 219 + 205 + switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV6)) 220 + if (host -> socket6 != ENET_SOCKET_NULL) 221 + switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV6)) 206 222 { 207 223 case 1: 208 224 return 1; 209 @@ -1673,7 +170 3,7 @@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)225 @@ -1673,7 +1708,7 @@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout) 210 226 211 227 waitCondition = ENET_SOCKET_WAIT_RECEIVE; … … 217 233 host -> serviceTime = enet_time_get (); 218 234 diff --git a/unix.c b/unix.c 219 index 13a24d8.. 96d17f8100644235 index 13a24d8..22ffb76 100644 220 236 --- a/unix.c 221 237 +++ b/unix.c … … 227 243 + if (family == ENET_IPV4 && 228 244 + (enet_get_address_family (address) == ENET_IPV4 || 229 + !memcmp ( address, & ENET_HOST_ANY, sizeof(ENetHostAddress))))245 + !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress)))) 230 246 { 231 247 ((struct sockaddr_in *) sin) -> sin_family = AF_INET; … … 240 256 } 241 257 #endif // IPV6_V6ONLY 242 @@ -393,22 +395,3 1@@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket258 @@ -393,22 +395,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket 243 259 } 244 260 … … 249 265 -#ifdef HAS_POLL 250 266 - struct pollfd pollSocket; 251 + //FIXME allow only one of the sockets being available252 267 +//#ifdef HAS_POLL 253 268 + struct pollfd pollSocket[2]; 254 269 int pollCount; 255 270 - 256 271 - pollSocket.fd = socket; 257 272 - pollSocket.events = 0; 273 + 258 274 + pollSocket[0].fd = socket4; 259 275 + pollSocket[1].fd = socket6; 260 276 + pollSocket[0].events = 0; 261 277 + pollSocket[1].events = 0; 278 + //pollSocket[0].revents = 0; 279 + pollSocket[1].revents = 0; 280 + 281 + if (pollSocket[0].fd == ENET_SOCKET_NULL) 282 + { 283 + pollSocket[0].fd = pollSocket[1].fd; 284 + pollSocket[1].fd = ENET_SOCKET_NULL; 285 + } 262 286 263 287 if (* condition & ENET_SOCKET_WAIT_SEND) … … 276 300 277 301 - pollCount = poll (& pollSocket, 1, timeout); 278 + pollCount = poll (pollSocket, 2, timeout);302 + pollCount = poll (pollSocket, pollSocket[1].fd != ENET_SOCKET_NULL ? 2 : 1, timeout); 279 303 280 304 if (pollCount < 0) 281 305 return -1; 282 @@ -418,13 +4 29,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou306 @@ -418,13 +436,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou 283 307 if (pollCount == 0) 284 308 return 0; … … 294 318 return 0; 295 319 +/* 296 +FIXME: implement this320 +FIXME: implement or remove this 297 321 #else 298 322 fd_set readSet, writeSet; 299 323 struct timeval timeVal; 300 @@ -460,6 +4 73,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou324 @@ -460,6 +480,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou 301 325 302 326 return 0; -
code/branches/ipv6/src/external/enet/protocol.c
r7377 r7389 1523 1523 1524 1524 ENetAddressFamily family = enet_get_address_family (& currentPeer -> address); 1525 sentLength = enet_socket_send (family == ENET_IPV4 ? host -> socket4 : host -> socket6, 1525 ENetSocket socket = family == ENET_IPV4 ? host -> socket4 : host -> socket6; 1526 if (socket == ENET_SOCKET_NULL) 1527 return -1; 1528 sentLength = enet_socket_send (socket, 1526 1529 & currentPeer -> address, 1527 1530 host -> buffers, … … 1638 1641 } 1639 1642 1640 switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV4)) 1643 if (host -> socket4 != ENET_SOCKET_NULL) 1644 switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV4)) 1641 1645 { 1642 1646 case 1: … … 1652 1656 } 1653 1657 1654 switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV6)) 1658 if (host -> socket6 != ENET_SOCKET_NULL) 1659 switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV6)) 1655 1660 { 1656 1661 case 1: -
code/branches/ipv6/src/external/enet/unix.c
r7377 r7389 120 120 if (family == ENET_IPV4 && 121 121 (enet_get_address_family (address) == ENET_IPV4 || 122 !memcmp ( address, & ENET_HOST_ANY, sizeof(ENetHostAddress))))122 !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress)))) 123 123 { 124 124 ((struct sockaddr_in *) sin) -> sin_family = AF_INET; … … 398 398 enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout) 399 399 { 400 //FIXME allow only one of the sockets being available401 400 //#ifdef HAS_POLL 402 401 struct pollfd pollSocket[2]; 403 402 int pollCount; 404 403 405 404 pollSocket[0].fd = socket4; 406 405 pollSocket[1].fd = socket6; 407 406 pollSocket[0].events = 0; 408 407 pollSocket[1].events = 0; 408 //pollSocket[0].revents = 0; 409 pollSocket[1].revents = 0; 410 411 if (pollSocket[0].fd == ENET_SOCKET_NULL) 412 { 413 pollSocket[0].fd = pollSocket[1].fd; 414 pollSocket[1].fd = ENET_SOCKET_NULL; 415 } 409 416 410 417 if (* condition & ENET_SOCKET_WAIT_SEND) … … 420 427 } 421 428 422 pollCount = poll (pollSocket, 2, timeout);429 pollCount = poll (pollSocket, pollSocket[1].fd != ENET_SOCKET_NULL ? 2 : 1, timeout); 423 430 424 431 if (pollCount < 0) … … 438 445 return 0; 439 446 /* 440 FIXME: implement this447 FIXME: implement or remove this 441 448 #else 442 449 fd_set readSet, writeSet;
Note: See TracChangeset
for help on using the changeset viewer.