diff --git a/host.c b/host.c index ab55591..1ac0fa9 100644 --- a/host.c +++ b/host.c @@ -11,7 +11,6 @@ */ ENetHostBIO ENET_SOCKET_BIO = { - .context = NULL, .enet_socket_create = &enet_socket_create, .enet_socket_bind = &enet_socket_bind, .enet_socket_send = &enet_socket_send, diff --git a/include/enet/enet.h b/include/enet/enet.h index 6c43e43..8bd5944 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -359,12 +359,11 @@ typedef int (ENET_CALLBACK * ENetInterceptCallback) (struct _ENetHost * host, st */ typedef struct _ENetHistBIO { - void * context; ENetSocket (*enet_socket_create) (ENetSocketType); int (*enet_socket_bind) (ENetSocket, const ENetAddress *); int (*enet_socket_get_address) (ENetSocket, ENetAddress *); - int (*enet_socket_send) (void *, ENetSocket, const ENetAddress *, const ENetBuffer *, size_t, const ENetAddress *, void *); - int (*enet_socket_receive) (void *, ENetSocket, ENetAddress *, ENetBuffer *, size_t, ENetAddress *, void **); + int (*enet_socket_send) (/*ENetPeer*/ void *, ENetSocket, const ENetAddress *, const ENetBuffer *, size_t, const ENetAddress *); + int (*enet_socket_receive) (/*ENetHost*/ void *, ENetSocket, ENetAddress *, ENetBuffer *, size_t, ENetAddress *); int (*enet_socket_wait) (ENetSocket, enet_uint32 *, enet_uint32); int (*enet_socket_set_option) (ENetSocket, ENetSocketOption, int); int (*enet_socket_get_option) (ENetSocket, ENetSocketOption, int *); @@ -432,7 +431,8 @@ typedef struct _ENetHost size_t maximumPacketSize; /**< the maximum allowable packet size that may be sent or received on a peer */ size_t maximumWaitingData; /**< the maximum aggregate amount of buffer space a peer may use waiting for packets to be delivered */ ENetHostBIO bio; - void * connection; + void * data; /**< Application private data, may be freely modified */ + void * connection; /**< Application private data, may be freely modified */ } ENetHost; /** @@ -535,8 +535,8 @@ ENET_API int enet_socket_get_address (ENetSocket, ENetAddress *); ENET_API int enet_socket_listen (ENetSocket, int); ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *); ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *); -ENET_API int enet_socket_send (void *, ENetSocket, const ENetAddress *, const ENetBuffer *, size_t, const ENetAddress *, void *); -ENET_API int enet_socket_receive (void *, ENetSocket, ENetAddress *, ENetBuffer *, size_t, ENetAddress *, void **); +ENET_API int enet_socket_send (/*ENetPeer*/ void *, ENetSocket, const ENetAddress *, const ENetBuffer *, size_t, const ENetAddress *); +ENET_API int enet_socket_receive (/*ENetHost*/ void *, ENetSocket, ENetAddress *, ENetBuffer *, size_t, ENetAddress *); ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32); ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int); ENET_API int enet_socket_get_option (ENetSocket, ENetSocketOption, int *); diff --git a/protocol.c b/protocol.c index 52ce359..ac51e2a 100644 --- a/protocol.c +++ b/protocol.c @@ -1127,6 +1127,15 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event) command -> header.reliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> header.reliableSequenceNumber); +#if ENET_DEBUG + printf("<<< host: %p, port %d, peer: %p, state: %d, channel: %d, command: 0x%x, .header.reliableSequenceNumber: %d\n", + host, host -> address.port, + peer, peer != NULL ? peer->state : -1, + command -> header.channelID, + command -> header.command, + command -> header.reliableSequenceNumber); +#endif + switch (commandNumber) { case ENET_PROTOCOL_COMMAND_ACKNOWLEDGE: @@ -1246,13 +1255,12 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event) buffer.data = host -> packetData [0]; buffer.dataLength = sizeof (host -> packetData [0]); - receivedLength = (*host -> bio.enet_socket_receive) (host -> bio.context, + receivedLength = (*host -> bio.enet_socket_receive) (host, host -> socket, & host -> peerAddress, & buffer, 1, - & host -> localAddress, - &host -> connection); + & host -> localAddress); if (receivedLength == -2) continue; @@ -1743,13 +1751,25 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch (*host -> bio.enet_socket_set_option) (host -> socket, ENET_SOCKOPT_QOS, 0); } - sentLength = (*host -> bio.enet_socket_send) (host -> bio.context, +#if ENET_DEBUG + printf(">>> host: %p, port: %d START %d commands\n", host, host -> address.port, host -> commandCount); + for (int i = 0; i < host -> commandCount; i ++) { + printf(">>> host: %p, port: %d, peer: %p, state: %d, channel: %d, command: 0x%x, .header.reliableSequenceNumber: %d\n", + host, host -> address.port, + currentPeer, currentPeer->state, + host -> commands[i].header.channelID, + host -> commands[i].header.command, + host -> commands[i].header.reliableSequenceNumber); + } + printf(">>> host: %p, port: %d END\n", host, host -> address.port); +#endif + + sentLength = (*host -> bio.enet_socket_send) (currentPeer, host -> socket, & currentPeer -> peerAddress, host -> buffers, host -> bufferCount, - & currentPeer -> localAddress, - currentPeer -> connection); + & currentPeer -> localAddress); enet_protocol_remove_sent_unreliable_commands (currentPeer, & sentUnreliableCommands); diff --git a/unix.c b/unix.c index 5904046..c78f05b 100644 --- a/unix.c +++ b/unix.c @@ -504,12 +504,11 @@ enet_socket_destroy (ENetSocket socket) } int -enet_socket_send (void * context, ENetSocket socket, +enet_socket_send (void * enetPeer, ENetSocket socket, const ENetAddress * destinationAddress, const ENetBuffer * buffers, size_t bufferCount, - const ENetAddress * sourceAddress, - void * connection) + const ENetAddress * sourceAddress) { struct msghdr msgHdr; struct sockaddr_in6 sin; @@ -567,12 +566,12 @@ enet_socket_send (void * context, ENetSocket socket, } int -enet_socket_receive (void * context, ENetSocket socket, +enet_socket_receive (void * host, + ENetSocket socket, ENetAddress * sourceAddress, ENetBuffer * buffers, size_t bufferCount, - ENetAddress * destinationAddress, - void ** connection) + ENetAddress * destinationAddress) { struct msghdr msgHdr; struct sockaddr_in6 sin; diff --git a/win32.c b/win32.c index 9a14a40..46c3b09 100644 --- a/win32.c +++ b/win32.c @@ -365,12 +365,11 @@ enet_socket_destroy (ENetSocket socket) } int -enet_socket_send (void * context, ENetSocket socket, +enet_socket_send (void * enetPeer, ENetSocket socket, const ENetAddress * address, const ENetBuffer * buffers, size_t bufferCount, - const ENetAddress * sourceAddress, - void * connection) + const ENetAddress * sourceAddress) { struct sockaddr_in6 sin; DWORD sentLength = 0; @@ -404,12 +403,12 @@ enet_socket_send (void * context, ENetSocket socket, } int -enet_socket_receive (void * context, ENetSocket socket, +enet_socket_receive (void * host, + ENetSocket socket, ENetAddress * address, ENetBuffer * buffers, size_t bufferCount, - const ENetAddress * destinationAddress, - void ** connection) + const ENetAddress * destinationAddress) { INT sinLength = sizeof (struct sockaddr_in6); DWORD flags = 0,