コード例 #1
0
ファイル: win32.c プロジェクト: thewolfwillcome/enet
int
enet_socket_send (ENetSocket socket,
                  const ENetAddress * address,
                  const ENetBuffer * buffers,
                  size_t bufferCount)
{
    ENetAddress address_clone;
    int address_length = enet_address_get_size (address);
    DWORD sentLength;

    if (address != NULL)
    {
        memcpy (& address_clone, address, address_length);

        address_clone.port = ENET_HOST_TO_NET_16 (address -> port);
    }

    if (WSASendTo (socket,
                   (LPWSABUF) buffers,
                   (DWORD) bufferCount,
                   & sentLength,
                   0,
                   address != NULL ? (struct sockaddr *) & address_clone : NULL,
                   address != NULL ? address_length : 0,
                   NULL,
                   NULL) == SOCKET_ERROR)
    {
       if (WSAGetLastError () == WSAEWOULDBLOCK)
         return 0;

       return -1;
    }

    return (int) sentLength;
}
コード例 #2
0
ファイル: win32.c プロジェクト: thewolfwillcome/enet
int
enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
{
    int error_code = getnameinfo((struct sockaddr *) address, enet_address_get_size(address),
                                 name, nameLength,
                                 NULL, 0,   // disregard service/socket name
                                 NI_DGRAM); // lookup via UPD when different

    // return IP address if name lookup is unsuccessful
    return (error_code == 0) ? 0 : enet_address_get_host_ip (address, name, nameLength);
}
コード例 #3
0
ファイル: unix.c プロジェクト: Ericson2314/enet
int
enet_socket_bind (ENetSocket socket, const ENetAddress * address)
{
    const size_t length = enet_address_get_size (address);
    ENetAddress * clone;

    memcopy (& clone, address, length);
    clone -> port = ENET_HOST_TO_NET_16 (address -> port);

    return bind (socket, (struct sockaddr *) clone, length);
}
コード例 #4
0
ファイル: win32.c プロジェクト: thewolfwillcome/enet
int
enet_socket_get_address (ENetSocket socket, ENetAddress * address)
{
	int length = enet_address_get_size(address);

    if (getsockname (socket, (struct sockaddr *) address, & length) == -1)
      return -1;

    address -> port = ENET_NET_TO_HOST_16 (address -> port);

    return 0;
}
コード例 #5
0
ファイル: win32.c プロジェクト: thewolfwillcome/enet
int
enet_socket_bind (ENetSocket socket, const ENetAddress * address)
{
    int length = enet_address_get_size (address);
    ENetAddress clone;

    memcpy (&clone, address, length);
	clone.port = ENET_HOST_TO_NET_16 (address -> port);

    int result = bind (socket, (struct sockaddr *) &clone, length);
	return result;
}
コード例 #6
0
ファイル: unix.c プロジェクト: Ericson2314/enet
int
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
{
    int result;
    size_t length = enet_address_get_size (address);
    ENetAddress * clone;

    memcopy (& clone, address, length);
    clone -> port = ENET_HOST_TO_NET_16 (address -> port);

    result = connect (socket, (struct sockaddr *) & clone, length);

    if (result == -1 && errno == EINPROGRESS)
      return 0;
    return result;
}
コード例 #7
0
ファイル: win32.c プロジェクト: thewolfwillcome/enet
int
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
{
    int result;
    size_t length = enet_address_get_size (address);
    ENetAddress clone;

    memcpy (& clone, address, length);
    clone.port = ENET_HOST_TO_NET_16 (address -> port);

    result = connect (socket, (struct sockaddr *) & clone, length);

    if (result == SOCKET_ERROR && WSAGetLastError () != WSAEWOULDBLOCK)
      return -1;

    return 0;
}
コード例 #8
0
ファイル: win32.c プロジェクト: thewolfwillcome/enet
ENetSocket
enet_socket_accept (ENetSocket socket, ENetAddress * address)
{
    SOCKET result;
    // only call enet_address_get_size if ptr is valid
    int length = address != NULL ? enet_address_get_size (address) : 0;

    result = accept (socket,
                     address != NULL ? (struct sockaddr *) address : NULL,
                     address != NULL ? & length : NULL);
    if (result == INVALID_SOCKET)
      return ENET_SOCKET_NULL;

    if (address != NULL)
        address -> port = ENET_NET_TO_HOST_16 (address -> port);

    return result;
}
コード例 #9
0
ファイル: unix.c プロジェクト: Ericson2314/enet
int
enet_socket_send (ENetSocket socket,
                  const ENetAddress * address,
                  const ENetBuffer * buffers,
                  size_t bufferCount)
{
    struct msghdr msgHdr;
    ENetAddress address_clone;
    int sentLength;

    memset (& msgHdr, 0, sizeof (struct msghdr));

    if (address != NULL)
    {
        msgHdr.msg_name = & address_clone;
        msgHdr.msg_namelen = enet_address_get_size (address);

        memcopy (& address_clone, address, msgHdr.msg_namelen);

        address_clone.port = ENET_HOST_TO_NET_16 (address -> port);
    }

    msgHdr.msg_iov = (struct iovec *) buffers;
    msgHdr.msg_iovlen = bufferCount;

    sentLength = sendmsg (socket, & msgHdr, MSG_NOSIGNAL);

    if (sentLength == -1)
    {
       if (errno == EWOULDBLOCK)
         return 0;

       return -1;
    }

    return sentLength;
}