Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 9, 2010, 1:09:09 AM (14 years ago)
Author:
adrfried
Message:

fix some stuff

Location:
code/branches/ipv6/src/external/enet/patches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ipv6/src/external/enet/patches/0003-using-address-family-in-functions.patch

    r7378 r7389  
    1 From 130babc6f69e07830f73f7757222597117eb1cba Mon Sep 17 00:00:00 2001
     1From af3c0910bd25d73b1a3c06bbfa4e0a3c6b96ddc5 Mon Sep 17 00:00:00 2001
    22From: Adrian Friedli <adi@koalatux.ch>
    33Date: Mon, 6 Sep 2010 14:58:50 +0200
     
    2727          enet_socket_destroy (host -> socket);
    2828diff --git a/include/enet/enet.h b/include/enet/enet.h
    29 index d3ca971..97f0556 100644
     29index d3ca971..7f5876f 100644
    3030--- a/include/enet/enet.h
    3131+++ b/include/enet/enet.h
     
    3939+{
    4040+    ENET_NO_ADDRESS_FAMILY = 0,
    41 +    ENET_IPV4 = 1,
    42 +    ENET_IPV6 = 2
     41+    ENET_IPV4 = (1 << 0),
     42+    ENET_IPV6 = (1 << 1)
    4343+} ENetAddressFamily;
    4444+
  • code/branches/ipv6/src/external/enet/patches/0004-using-two-separate-sockets-for-IPv4-and-IPv6.patch

    r7378 r7389  
    1 From d61448922c08e6801f07c38077623d3bcc513ad4 Mon Sep 17 00:00:00 2001
     1From 9801a6bcd072870248a6b07245fc09a9492f8f51 Mon Sep 17 00:00:00 2001
    22From: Adrian Friedli <adi@koalatux.ch>
    33Date: Wed, 8 Sep 2010 12:50:04 +0200
     
    55
    66---
    7  host.c              |   45 ++++++++++++++++++++++++++++++++++++---------
    8  include/enet/enet.h |   11 +++++++++--
    9  protocol.c          |   42 ++++++++++++++++++++++++++++++++++++------
    10  unix.c              |   38 ++++++++++++++++++++++++++------------
    11  4 files changed, 107 insertions(+), 29 deletions(-)
     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(-)
    1212
    1313diff --git a/host.c b/host.c
    14 index 9ccf894..85dfa3c 100644
     14index 9ccf894..46e52c9 100644
    1515--- a/host.c
    1616+++ 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
    1846     }
    1947     memset (host -> peers, 0, peerCount * sizeof (ENetPeer));
     
    2149-    host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, ENET_IPV6);
    2250-    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-    {
    3052-       if (host -> socket != ENET_SOCKET_NULL)
    3153-         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;
    3973     }
    4074 
     
    4377-    enet_socket_set_option (host -> socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
    4478-    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-
    7280     if (address != NULL)
    7381       host -> address = * address;
    74 @@ -133,7 +159,8 @@ enet_host_destroy (ENetHost * host)
     82 
     83@@ -133,7 +155,10 @@ enet_host_destroy (ENetHost * host)
    7584 {
    7685     ENetPeer * currentPeer;
    7786 
    7887-    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);
    8192 
    8293     for (currentPeer = host -> peers;
    8394          currentPeer < & host -> peers [host -> peerCount];
    8495diff --git a/include/enet/enet.h b/include/enet/enet.h
    85 index 97f0556..39cf93e 100644
     96index 7f5876f..616fe7f 100644
    8697--- a/include/enet/enet.h
    8798+++ b/include/enet/enet.h
     
    119130 ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
    120131diff --git a/protocol.c b/protocol.c
    121 index 4c4850a..37f6387 100644
     132index 4c4850a..505c684 100644
    122133--- a/protocol.c
    123134+++ b/protocol.c
     
    170181        host -> receivedDataLength = receivedLength;
    171182       
    172 @@ -1510,7 +1521,12 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
     183@@ -1510,7 +1521,15 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
    173184 
    174185         currentPeer -> lastSendTime = host -> serviceTime;
     
    176187-        sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount, ENET_IPV6);
    177188+        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,
    179193+                                           & currentPeer -> address,
    180194+                                           host -> buffers,
     
    184198         enet_protocol_remove_sent_unreliable_commands (currentPeer);
    185199 
    186 @@ -1621,7 +1637,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)
    187201           break;
    188202        }
    189203 
    190204-       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))
    192207+       {
    193208+       case 1:
     
    203218+       }
    204219+
    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))
    206222        {
    207223        case 1:
    208224           return 1;
    209 @@ -1673,7 +1703,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)
    210226 
    211227        waitCondition = ENET_SOCKET_WAIT_RECEIVE;
     
    217233        host -> serviceTime = enet_time_get ();
    218234diff --git a/unix.c b/unix.c
    219 index 13a24d8..96d17f8 100644
     235index 13a24d8..22ffb76 100644
    220236--- a/unix.c
    221237+++ b/unix.c
     
    227243+    if (family == ENET_IPV4 &&
    228244+      (enet_get_address_family (address) == ENET_IPV4 ||
    229 +      !memcmp (address, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
     245+      !memcmp (& address -> host, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
    230246     {
    231247         ((struct sockaddr_in *) sin) -> sin_family = AF_INET;
     
    240256     }
    241257 #endif // IPV6_V6ONLY
    242 @@ -393,22 +395,31 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
     258@@ -393,22 +395,38 @@ enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocket
    243259 }
    244260 
     
    249265-#ifdef HAS_POLL
    250266-    struct pollfd pollSocket;
    251 +    //FIXME allow only one of the sockets being available
    252267+//#ifdef HAS_POLL
    253268+    struct pollfd pollSocket[2];
    254269     int pollCount;
    255     
     270-   
    256271-    pollSocket.fd = socket;
    257272-    pollSocket.events = 0;
     273+
    258274+    pollSocket[0].fd = socket4;
    259275+    pollSocket[1].fd = socket6;
    260276+    pollSocket[0].events = 0;
    261277+    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+    }
    262286 
    263287     if (* condition & ENET_SOCKET_WAIT_SEND)
     
    276300 
    277301-    pollCount = poll (& pollSocket, 1, timeout);
    278 +    pollCount = poll (pollSocket, 2, timeout);
     302+    pollCount = poll (pollSocket, pollSocket[1].fd != ENET_SOCKET_NULL ? 2 : 1, timeout);
    279303 
    280304     if (pollCount < 0)
    281305       return -1;
    282 @@ -418,13 +429,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
     306@@ -418,13 +436,15 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
    283307     if (pollCount == 0)
    284308       return 0;
     
    294318     return 0;
    295319+/*
    296 +FIXME: implement this
     320+FIXME: implement or remove this
    297321 #else
    298322     fd_set readSet, writeSet;
    299323     struct timeval timeVal;
    300 @@ -460,6 +473,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
     324@@ -460,6 +480,7 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
    301325 
    302326     return 0;
Note: See TracChangeset for help on using the changeset viewer.