Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 8, 2010, 4:08:09 AM (15 years ago)
Author:
adrfried
Message:

using two separate sockets for ipv4 and ipv6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ipv6/src/external/enet/host.c

    r7330 r7377  
    4949    memset (host -> peers, 0, peerCount * sizeof (ENetPeer));
    5050
    51     host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM);
    52     enet_socket_set_option (host -> socket, ENET_SOCKOPT_V6ONLY, 0); // Needs to be set before bind.
    53 
    54     if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0))
    55     {
    56        if (host -> socket != ENET_SOCKET_NULL)
    57          enet_socket_destroy (host -> socket);
     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);
    5860
    5961       enet_free (host -> peers);
     
    6365    }
    6466
    65     enet_socket_set_option (host -> socket, ENET_SOCKOPT_NONBLOCK, 1);
    66     enet_socket_set_option (host -> socket, ENET_SOCKOPT_BROADCAST, 1);
    67     enet_socket_set_option (host -> socket, ENET_SOCKOPT_RCVBUF, ENET_HOST_RECEIVE_BUFFER_SIZE);
    68     enet_socket_set_option (host -> socket, ENET_SOCKOPT_SNDBUF, ENET_HOST_SEND_BUFFER_SIZE);
     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
    6993
    7094    if (address != NULL)
     
    136160    ENetPeer * currentPeer;
    137161
    138     enet_socket_destroy (host -> socket);
     162    enet_socket_destroy (host -> socket4);
     163    enet_socket_destroy (host -> socket6);
    139164
    140165    for (currentPeer = host -> peers;
Note: See TracChangeset for help on using the changeset viewer.