Changeset 7389 for code/branches/ipv6/src/external/enet/host.c
- Timestamp:
- Sep 9, 2010, 1:09:09 AM (14 years ago)
- File:
-
- 1 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;
Note: See TracChangeset
for help on using the changeset viewer.