Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7377 for code/branches/ipv6


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

using two separate sockets for ipv4 and ipv6

Location:
code/branches/ipv6/src/external/enet
Files:
1 added
2 deleted
4 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;
  • code/branches/ipv6/src/external/enet/include/enet/enet.h

    r7330 r7377  
    5151   ENET_SOCKOPT_RCVBUF    = 3,
    5252   ENET_SOCKOPT_SNDBUF    = 4,
    53    ENET_SOCKOPT_REUSEADDR = 5,
    54    ENET_SOCKOPT_V6ONLY = 6
     53   ENET_SOCKOPT_REUSEADDR = 5
    5554} ENetSocketOption;
    5655
     
    6059} ENetHostAddress;
    6160
    62 extern const ENetHostAddress ENET_HOST_ANY;       /**< specifies the default server host */
    63 extern const ENetHostAddress ENET_HOST_BROADCAST; /**< specifies a IPv4 subnet-wide broadcast */
    64 #define ENET_PORT_ANY 0                           /**< specifies that a port should be automatically chosen */
     61extern const ENetHostAddress ENET_HOST_ANY;          /**< specifies the default server host */
     62extern const ENetHostAddress ENET_IPV4MAPPED_PREFIX; /**< specifies the IPv4-mapped IPv6 prefix */
     63extern const ENetHostAddress ENET_HOST_BROADCAST;    /**< specifies a IPv4 subnet-wide broadcast */
     64#define ENET_IPV4MAPPED_PREFIX_LEN 12                /**< specifies the length of the IPv4-mapped IPv6 prefix */
     65#define ENET_PORT_ANY 0                              /**< specifies that a port should be automatically chosen */
    6566
    6667/**
     
    8081   enet_uint16 port;
    8182} ENetAddress;
     83
     84/**
     85 * The address family type.
     86 */
     87typedef enum _ENetAddressFamily
     88{
     89    ENET_NO_ADDRESS_FAMILY = 0,
     90    ENET_IPV4 = 1,
     91    ENET_IPV6 = 2
     92} ENetAddressFamily;
    8293
    8394/**
     
    325336typedef struct _ENetHost
    326337{
    327    ENetSocket           socket;
     338   ENetSocket           socket4;
     339   ENetSocket           socket6;
    328340   ENetAddress          address;                     /**< Internet address of the host */
    329341   enet_uint32          incomingBandwidth;           /**< downstream bandwidth of the host */
     
    445457    @{
    446458*/
    447 ENET_API ENetSocket enet_socket_create (ENetSocketType);
    448 ENET_API int        enet_socket_bind (ENetSocket, const ENetAddress *);
     459ENET_API ENetSocket enet_socket_create (ENetSocketType, ENetAddressFamily);
     460ENET_API int        enet_socket_bind (ENetSocket, const ENetAddress *, ENetAddressFamily);
    449461ENET_API int        enet_socket_listen (ENetSocket, int);
    450 ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
    451 ENET_API int        enet_socket_connect (ENetSocket, const ENetAddress *);
    452 ENET_API int        enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
    453 ENET_API int        enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
    454 ENET_API int        enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
     462ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *, ENetAddressFamily);
     463ENET_API int        enet_socket_connect (ENetSocket, const ENetAddress *, ENetAddressFamily);
     464ENET_API int        enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t, ENetAddressFamily);
     465ENET_API int        enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t, ENetAddressFamily);
     466ENET_API int        enet_socket_wait (ENetSocket, ENetSocket, enet_uint32 *, enet_uint32);
    455467ENET_API int        enet_socket_set_option (ENetSocket, ENetSocketOption, int);
    456468ENET_API void       enet_socket_destroy (ENetSocket);
     
    496508    @returns the IPv4-mapped IPv6 address in network byte order
    497509*/
    498 static inline ENetHostAddress enet_address_map4 (enet_uint32 address)
    499 {
    500    ENetHostAddress addr = ENET_HOST_ANY;
    501    ((enet_uint16 *)addr.addr)[5] = 0xffff;
    502    ((enet_uint32 *)addr.addr)[3] = address;
    503    return addr;
    504 }
     510ENET_API ENetHostAddress enet_address_map4 (enet_uint32 address);
     511
     512/** Returns the Address family of an (IPv4-mapped) IPv6 address.
     513    @param address IPv6 address
     514    @returns address family
     515*/
     516ENET_API ENetAddressFamily enet_get_address_family (const ENetAddress * address);
    505517
    506518/** @} */
  • code/branches/ipv6/src/external/enet/protocol.c

    r7330 r7377  
    1111
    1212const ENetHostAddress ENET_HOST_ANY = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
     13const ENetHostAddress ENET_IPV4MAPPED_PREFIX = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0,0,0,0 } };
    1314const ENetHostAddress ENET_HOST_BROADCAST = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
    1415
     
    2829    sizeof (ENetProtocolThrottleConfigure),
    2930};
     31
     32ENetHostAddress
     33enet_address_map4 (enet_uint32 address)
     34{
     35    ENetHostAddress addr = ENET_IPV4MAPPED_PREFIX;
     36    ((enet_uint32 *)addr.addr)[3] = address;
     37    return addr;
     38}
     39
     40ENetAddressFamily
     41enet_get_address_family (const ENetAddress * address)
     42{
     43    if (!memcmp(& address->host, & ENET_IPV4MAPPED_PREFIX, ENET_IPV4MAPPED_PREFIX_LEN))
     44        return ENET_IPV4;
     45    return ENET_IPV6;
     46}
    3047
    3148size_t
     
    10251042 
    10261043static int
    1027 enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
     1044enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event, ENetAddressFamily family)
    10281045{
    10291046    for (;;)
     
    10351052       buffer.dataLength = sizeof (host -> packetData [0]);
    10361053
    1037        receivedLength = enet_socket_receive (host -> socket,
     1054       receivedLength = enet_socket_receive (family == ENET_IPV4 ? host -> socket4 : host -> socket6,
    10381055                                             & host -> receivedAddress,
    10391056                                             & buffer,
    1040                                              1);
     1057                                             1,
     1058                                             family);
    10411059
    10421060       if (receivedLength < 0)
     
    10451063       if (receivedLength == 0)
    10461064         return 0;
     1065
     1066       if (enet_get_address_family (& host -> receivedAddress) != family)
     1067         return -1;
    10471068
    10481069       host -> receivedData = host -> packetData [0];
     
    15011522        currentPeer -> lastSendTime = host -> serviceTime;
    15021523
    1503         sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount);
     1524        ENetAddressFamily family = enet_get_address_family (& currentPeer -> address);
     1525        sentLength = enet_socket_send (family == ENET_IPV4 ? host -> socket4 : host -> socket6,
     1526                                           & currentPeer -> address,
     1527                                           host -> buffers,
     1528                                           host -> bufferCount,
     1529                                           family);
    15041530
    15051531        enet_protocol_remove_sent_unreliable_commands (currentPeer);
     
    16121638       }
    16131639
    1614        switch (enet_protocol_receive_incoming_commands (host, event))
     1640       switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV4))
     1641       {
     1642       case 1:
     1643          return 1;
     1644
     1645       case -1:
     1646          perror ("Error receiving incoming packets");
     1647
     1648          return -1;
     1649
     1650       default:
     1651          break;
     1652       }
     1653
     1654       switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV6))
    16151655       {
    16161656       case 1:
     
    16641704       waitCondition = ENET_SOCKET_WAIT_RECEIVE;
    16651705
    1666        if (enet_socket_wait (host -> socket, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)
     1706       if (enet_socket_wait (host -> socket4, host -> socket6, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)
    16671707         return -1;
    16681708       
  • code/branches/ipv6/src/external/enet/unix.c

    r7330 r7377  
    7272}
    7373
     74static enet_uint16
     75enet_af (ENetAddressFamily family)
     76{
     77    if (family == ENET_IPV4)
     78        return AF_INET;
     79    if (family == ENET_IPV6)
     80        return AF_INET6;
     81    return 0;
     82}
     83
     84static socklen_t
     85enet_sa_size (ENetAddressFamily family)
     86{
     87    if (family == ENET_IPV4)
     88        return sizeof (struct sockaddr_in);
     89    if (family == ENET_IPV6)
     90        return sizeof (struct sockaddr_in6);
     91    return 0;
     92}
     93
     94
     95static ENetAddressFamily
     96enet_address_set_address (ENetAddress * address, const struct sockaddr * sin)
     97{
     98    memset (address, 0, sizeof (ENetAddress));
     99    if (sin -> sa_family == AF_INET)
     100    {
     101        address -> host = enet_address_map4 ((((struct sockaddr_in *) sin) -> sin_addr.s_addr));
     102        //address -> scopeID = 0;
     103        address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in *) sin) -> sin_port);
     104        return ENET_IPV4;
     105    }
     106    if (sin -> sa_family == AF_INET6)
     107    {
     108        address -> host = * (ENetHostAddress *) & ((struct sockaddr_in6 *) sin) -> sin6_addr;
     109        address -> scopeID = ((struct sockaddr_in6 *) sin) -> sin6_scope_id;
     110        address -> port = ENET_NET_TO_HOST_16 (((struct sockaddr_in6 *) sin) -> sin6_port);
     111        return ENET_IPV6;
     112    }
     113    return ENET_NO_ADDRESS_FAMILY;
     114}
     115
     116static int
     117enet_address_set_sin (struct sockaddr * sin, const ENetAddress * address, ENetAddressFamily family)
     118{
     119    memset (sin, 0, enet_sa_size(family));
     120    if (family == ENET_IPV4 &&
     121      (enet_get_address_family (address) == ENET_IPV4 ||
     122      !memcmp (address, & ENET_HOST_ANY, sizeof(ENetHostAddress))))
     123    {
     124        ((struct sockaddr_in *) sin) -> sin_family = AF_INET;
     125        ((struct sockaddr_in *) sin) -> sin_addr = * (struct in_addr *) & address -> host.addr[12];
     126        ((struct sockaddr_in *) sin) -> sin_port = ENET_HOST_TO_NET_16 (address -> port);
     127        return 0;
     128    }
     129    else if (family == ENET_IPV6)
     130    {
     131        ((struct sockaddr_in6 *) sin) -> sin6_family = AF_INET6;
     132        ((struct sockaddr_in6 *) sin) -> sin6_addr = * (struct in6_addr *) & address -> host;
     133        ((struct sockaddr_in6 *) sin) -> sin6_scope_id = address -> scopeID;
     134        ((struct sockaddr_in6 *) sin) -> sin6_port = ENET_HOST_TO_NET_16 (address -> port);
     135        return 0;
     136    }
     137    return -1;
     138}
     139
    74140int
    75141enet_address_set_host (ENetAddress * address, const char * name)
    76142{
     143    enet_uint16 port = address -> port;
    77144    struct addrinfo hints;
    78145    struct addrinfo * result;
     
    84151
    85152    if ( getaddrinfo(name, NULL, &hints, &result) )
    86     {
    87153        return -1;
    88     }
    89154
    90155    for (res = result; res != NULL; res = res -> ai_next)
    91156    {
    92         if (res -> ai_family == AF_INET)
    93         {
    94             address -> host = enet_address_map4( ((struct sockaddr_in *) res -> ai_addr ) -> sin_addr.s_addr );
    95             address -> scopeID = 0;
    96             break;
    97         }
    98         if (res -> ai_family == AF_INET6)
    99         {
    100             address -> host = * (ENetHostAddress *) & ((struct sockaddr_in6 *) res -> ai_addr ) -> sin6_addr;
    101             address -> scopeID = ((struct sockaddr_in6 *) res -> ai_addr ) -> sin6_scope_id;
    102             break;
    103         }
    104     }
     157        if ( enet_address_set_address(address, res -> ai_addr) != ENET_NO_ADDRESS_FAMILY )
     158            break;
     159    }
     160
     161    address -> port = port;
    105162    freeaddrinfo(result);
    106163    if (res == NULL) return -1;
     
    112169enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags)
    113170{
    114     struct sockaddr_in6 sin;
    115 
    116     memset (& sin, 0, sizeof (struct sockaddr_in6));
    117 
    118     sin.sin6_family = AF_INET6;
    119     sin.sin6_addr = * (struct in6_addr *) & address -> host;
    120     sin.sin6_scope_id = address -> scopeID;
    121 
    122     if ( getnameinfo((struct sockaddr *) & sin, sizeof(sin), name, nameLength, NULL, 0, flags))
    123     {
     171    struct sockaddr_storage sin;
     172    enet_address_set_sin((struct sockaddr *) & sin, address, ENET_IPV6);
     173
     174    if ( getnameinfo((struct sockaddr *) & sin, enet_sa_size (ENET_IPV6), name, nameLength, NULL, 0, flags))
    124175        return -1;
    125     }
    126176
    127177    return 0;
     
    141191
    142192int
    143 enet_socket_bind (ENetSocket socket, const ENetAddress * address)
    144 {
    145     struct sockaddr_in6 sin;
    146 
    147     memset (& sin, 0, sizeof (struct sockaddr_in6));
    148 
    149     sin.sin6_family = AF_INET6;
     193enet_socket_bind (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
     194{
     195    struct sockaddr_storage sin;
    150196
    151197    if (address != NULL)
    152198    {
    153        sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
    154        sin.sin6_addr = * (struct in6_addr *) & address -> host;
    155        sin.sin6_scope_id = address -> scopeID;
     199        enet_address_set_sin((struct sockaddr *) & sin, address, family);
    156200    }
    157201    else
    158202    {
    159        sin.sin6_port = 0;
    160        sin.sin6_addr = in6addr_any;
    161        sin.sin6_scope_id = 0;
    162     }
    163 
    164     return bind (socket,
    165                  (struct sockaddr *) & sin,
    166                  sizeof (struct sockaddr_in6));
    167 }
    168 
    169 int
     203        ENetAddress address_ = { ENET_HOST_ANY, 0, 0 };
     204        enet_address_set_sin((struct sockaddr *) & sin, & address_, family);
     205    }
     206
     207    return bind (socket, (struct sockaddr *) & sin, enet_sa_size(family));
     208}
     209
     210int
    170211enet_socket_listen (ENetSocket socket, int backlog)
    171212{
     
    174215
    175216ENetSocket
    176 enet_socket_create (ENetSocketType type)
    177 {
    178     return socket (AF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
     217enet_socket_create (ENetSocketType type, ENetAddressFamily family)
     218{
     219    ENetSocket sock = socket (enet_af (family), type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
     220
     221#ifdef IPV6_V6ONLY
     222    if (family == ENET_IPV6)
     223    {
     224        int value = 1;
     225        setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, & value, sizeof (int));
     226    }
     227#endif // IPV6_V6ONLY
     228
     229    return sock;
    179230}
    180231
     
    209260            break;
    210261
    211         case ENET_SOCKOPT_V6ONLY:
    212             result = setsockopt (socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *) & value, sizeof (int));
    213             break;
    214 
    215262        default:
    216263            break;
     
    220267
    221268int
    222 enet_socket_connect (ENetSocket socket, const ENetAddress * address)
    223 {
    224     struct sockaddr_in6 sin;
    225 
    226     memset (& sin, 0, sizeof (struct sockaddr_in6));
    227 
    228     sin.sin6_family = AF_INET6;
    229     sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
    230     sin.sin6_addr = * (struct in6_addr *) & address -> host;
    231     sin.sin6_scope_id = address -> scopeID;
    232 
    233     return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6));
     269enet_socket_connect (ENetSocket socket, const ENetAddress * address, ENetAddressFamily family)
     270{
     271    struct sockaddr_storage sin;
     272    enet_address_set_sin((struct sockaddr *) & sin, address, family);
     273
     274    return connect (socket, (struct sockaddr *) & sin, enet_sa_size (family));
    234275}
    235276
    236277ENetSocket
    237 enet_socket_accept (ENetSocket socket, ENetAddress * address)
     278enet_socket_accept (ENetSocket socket, ENetAddress * address, ENetAddressFamily family)
    238279{
    239280    int result;
    240     struct sockaddr_in6 sin;
    241     socklen_t sinLength = sizeof (struct sockaddr_in6);
     281    struct sockaddr_storage sin;
     282    socklen_t sinLength = enet_sa_size (family);
    242283
    243284    result = accept (socket,
    244285                     address != NULL ? (struct sockaddr *) & sin : NULL,
    245286                     address != NULL ? & sinLength : NULL);
    246    
     287
    247288    if (result == -1)
    248289      return ENET_SOCKET_NULL;
     
    250291    if (address != NULL)
    251292    {
    252         address -> host = * (ENetHostAddress *) & sin.sin6_addr;
    253         address -> scopeID = sin.sin6_scope_id;
    254         address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);
     293        enet_address_set_address(address, (struct sockaddr *) & sin);
    255294    }
    256295
     
    268307                  const ENetAddress * address,
    269308                  const ENetBuffer * buffers,
    270                   size_t bufferCount)
     309                  size_t bufferCount,
     310                  ENetAddressFamily family)
    271311{
    272312    struct msghdr msgHdr;
    273     struct sockaddr_in6 sin;
     313    struct sockaddr_storage sin;
    274314    int sentLength;
    275315
     
    278318    if (address != NULL)
    279319    {
    280         memset (& sin, 0, sizeof (struct sockaddr_in6));
    281 
    282         sin.sin6_family = AF_INET6;
    283         sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port);
    284         sin.sin6_addr = * (struct in6_addr *) & address -> host;
    285         sin.sin6_scope_id = address -> scopeID;
    286 
     320        enet_address_set_sin((struct sockaddr *) & sin, address, family);
    287321        msgHdr.msg_name = & sin;
    288         msgHdr.msg_namelen = sizeof (struct sockaddr_in6);
     322        msgHdr.msg_namelen = enet_sa_size (family);
    289323    }
    290324
     
    309343                     ENetAddress * address,
    310344                     ENetBuffer * buffers,
    311                      size_t bufferCount)
     345                     size_t bufferCount,
     346                     ENetAddressFamily family)
    312347{
    313348    struct msghdr msgHdr;
    314     struct sockaddr_in6 sin;
     349    struct sockaddr_storage sin;
    315350    int recvLength;
    316351
     
    320355    {
    321356        msgHdr.msg_name = & sin;
    322         msgHdr.msg_namelen = sizeof (struct sockaddr_in6);
     357        msgHdr.msg_namelen = enet_sa_size (family);
    323358    }
    324359
     
    343378    if (address != NULL)
    344379    {
    345         address -> host = * (ENetHostAddress *) & sin.sin6_addr;
    346         address -> scopeID = sin.sin6_scope_id;
    347         address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port);
     380        enet_address_set_address(address, (struct sockaddr *) & sin);
    348381    }
    349382
     
    363396
    364397int
    365 enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
    366 {
    367 #ifdef HAS_POLL
    368     struct pollfd pollSocket;
     398enet_socket_wait (ENetSocket socket4, ENetSocket socket6, enet_uint32 * condition, enet_uint32 timeout)
     399{
     400    //FIXME allow only one of the sockets being available
     401//#ifdef HAS_POLL
     402    struct pollfd pollSocket[2];
    369403    int pollCount;
    370404   
    371     pollSocket.fd = socket;
    372     pollSocket.events = 0;
     405    pollSocket[0].fd = socket4;
     406    pollSocket[1].fd = socket6;
     407    pollSocket[0].events = 0;
     408    pollSocket[1].events = 0;
    373409
    374410    if (* condition & ENET_SOCKET_WAIT_SEND)
    375       pollSocket.events |= POLLOUT;
     411    {
     412        pollSocket[0].events |= POLLOUT;
     413        pollSocket[1].events |= POLLOUT;
     414    }
    376415
    377416    if (* condition & ENET_SOCKET_WAIT_RECEIVE)
    378       pollSocket.events |= POLLIN;
    379 
    380     pollCount = poll (& pollSocket, 1, timeout);
     417    {
     418        pollSocket[0].events |= POLLIN;
     419        pollSocket[1].events |= POLLIN;
     420    }
     421
     422    pollCount = poll (pollSocket, 2, timeout);
    381423
    382424    if (pollCount < 0)
     
    388430      return 0;
    389431
    390     if (pollSocket.revents & POLLOUT)
     432    if ((pollSocket[0].revents | pollSocket[1].revents) & POLLOUT)
    391433      * condition |= ENET_SOCKET_WAIT_SEND;
    392434   
    393     if (pollSocket.revents & POLLIN)
     435    if ((pollSocket[0].revents | pollSocket[1].revents) & POLLIN)
    394436      * condition |= ENET_SOCKET_WAIT_RECEIVE;
    395437
    396438    return 0;
     439/*
     440FIXME: implement this
    397441#else
    398442    fd_set readSet, writeSet;
     
    430474    return 0;
    431475#endif
    432 }
    433 
    434 #endif
    435 
     476*/
     477}
     478
     479#endif
     480
Note: See TracChangeset for help on using the changeset viewer.