mirror of
https://github.com/lsalzman/enet
synced 2024-11-21 14:29:05 -07:00
intercept callback support
This commit is contained in:
parent
9dff8f72cf
commit
2d979ceb51
2 changed files with 23 additions and 1 deletions
|
@ -319,6 +319,9 @@ typedef struct _ENetCompressor
|
||||||
|
|
||||||
/** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */
|
/** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */
|
||||||
typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
|
typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
|
||||||
|
|
||||||
|
/** Callback for intercepting received raw UDP packets. Should return 1 to intercept, 0 to ignore, or -1 to propagate an error. */
|
||||||
|
typedef int (ENET_CALLBACK * ENetInterceptCallback) (ENetHost * host, ENetEvent * event);
|
||||||
|
|
||||||
/** An ENet host for communicating with peers.
|
/** An ENet host for communicating with peers.
|
||||||
*
|
*
|
||||||
|
@ -368,6 +371,7 @@ typedef struct _ENetHost
|
||||||
enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
|
enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
|
||||||
enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */
|
enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */
|
||||||
enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
|
enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
|
||||||
|
ENetInterceptCallback intercept; /**< callback the user can set to intercept received raw UDP packets */
|
||||||
} ENetHost;
|
} ENetHost;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
20
protocol.c
20
protocol.c
|
@ -1194,7 +1194,25 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
|
||||||
|
|
||||||
host -> totalReceivedData += receivedLength;
|
host -> totalReceivedData += receivedLength;
|
||||||
host -> totalReceivedPackets ++;
|
host -> totalReceivedPackets ++;
|
||||||
|
|
||||||
|
if (host -> intercept != NULL)
|
||||||
|
{
|
||||||
|
switch (host -> intercept (host, event))
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
if (event != NULL && event -> type != ENET_EVENT_TYPE_NONE)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case -1:
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (enet_protocol_handle_incoming_commands (host, event))
|
switch (enet_protocol_handle_incoming_commands (host, event))
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
|
|
Loading…
Reference in a new issue