update to latest enet cvs

git-svn-id: https://svn.eduke32.com/eduke32@1640 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2010-05-15 09:07:49 +00:00
parent ddf83fbbf1
commit 709c18a0e5
14 changed files with 403 additions and 183 deletions

View File

@ -25,7 +25,7 @@ CFLAGS=$(debug) -W -Wall -Wimplicit -Werror-implicit-function-declaration \
-funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -D_FORTIFY_SOURCE=2 \
-fjump-tables -fno-stack-protector
CPPFLAGS=-Iinclude -Isrc -DHAVE_VORBIS
CPPFLAGS=-Iinclude -Isrc
OBJECTS=$(OBJ)/callbacks.o \
$(OBJ)/host.o \

View File

@ -23,7 +23,7 @@ CFLAGS=$(CFLAGS) /nologo /MT /J $(flags_cl) $(TARGETOPTS) /I$(INC) /I$(SRC)
CFLAGS=$(CFLAGS) /DDEBUGGINGAIDS
!endif
CFLAGS=$(CFLAGS) /DRENDERTYPE$(RENDERTYPE)=1 /D "_CRT_SECURE_NO_DEPRECATE" /W2 /DHAVE_VORBIS /Iinclude/msvc /DWIN32
CFLAGS=$(CFLAGS) /DRENDERTYPE$(RENDERTYPE)=1 /D "_CRT_SECURE_NO_DEPRECATE" /W2 /Iinclude/msvc /DWIN32
OBJECTS=$(OBJ)\callbacks.o \
$(OBJ)\host.o \

View File

@ -12,6 +12,7 @@ typedef struct _ENetCallbacks
void * (ENET_CALLBACK * malloc) (size_t size);
void (ENET_CALLBACK * free) (void * memory);
int (ENET_CALLBACK * rand) (void);
void (ENET_CALLBACK * no_memory) (void);
} ENetCallbacks;
/** @defgroup callbacks ENet internal callbacks

View File

@ -23,10 +23,13 @@ extern "C"
#include "enet/list.h"
#include "enet/callbacks.h"
typedef enum _ENetVersion
{
ENET_VERSION = 1
} ENetVersion;
#define ENET_VERSION_MAJOR 1
#define ENET_VERSION_MINOR 2
#define ENET_VERSION_PATCH 2
#define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
#define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH)
typedef enet_uint32 ENetVersion;
typedef enum _ENetSocketType
{
@ -226,6 +229,7 @@ typedef struct _ENetChannel
*/
typedef struct _ENetPeer
{
ENetListNode dispatchList;
struct _ENetHost * host;
enet_uint16 outgoingPeerID;
enet_uint16 incomingPeerID;
@ -272,6 +276,8 @@ typedef struct _ENetPeer
ENetList sentUnreliableCommands;
ENetList outgoingReliableCommands;
ENetList outgoingUnreliableCommands;
ENetList dispatchedCommands;
int needsDispatch;
enet_uint16 incomingUnsequencedGroup;
enet_uint16 outgoingUnsequencedGroup;
enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
@ -288,6 +294,7 @@ typedef struct _ENetPeer
@sa enet_host_service()
@sa enet_host_flush()
@sa enet_host_broadcast()
@sa enet_host_channel_limit()
@sa enet_host_bandwidth_limit()
@sa enet_host_bandwidth_throttle()
*/
@ -302,8 +309,9 @@ typedef struct _ENetHost
int recalculateBandwidthLimits;
ENetPeer * peers; /**< array of peers allocated for this host */
size_t peerCount; /**< number of peers allocated for this host */
size_t channelLimit; /**< maximum number of channels allowed for connected peers */
enet_uint32 serviceTime;
ENetPeer * lastServicedPeer;
ENetList dispatchQueue;
int continueSending;
size_t packetSize;
enet_uint16 headerFlags;
@ -314,6 +322,10 @@ typedef struct _ENetHost
ENetAddress receivedAddress;
enet_uint8 receivedData [ENET_PROTOCOL_MAXIMUM_MTU];
size_t receivedDataLength;
enet_uint32 totalSentData; /**< total data 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 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
} ENetHost;
/**
@ -373,7 +385,7 @@ typedef struct _ENetEvent
ENET_API int enet_initialize (void);
/**
Initializes ENet globally and supplies user-overridden callbacks. Must be called prior to using any functions in ENet. Do not use enet_initialize() if you use this variant.
Initializes ENet globally and supplies user-overridden callbacks. Must be called prior to using any functions in ENet. Do not use enet_initialize() if you use this variant. Make sure the ENetCallbacks structure is zeroed out so that any additional callbacks added in future versions will be properly ignored.
@param version the constant ENET_VERSION should be supplied so ENet knows which version of ENetCallbacks struct to use
@param inits user-overriden callbacks where any NULL callbacks will use ENet's defaults
@ -465,11 +477,12 @@ ENET_API int enet_host_check_events (ENetHost *, ENetEvent *);
ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32);
ENET_API void enet_host_flush (ENetHost *);
ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *);
ENET_API void enet_host_channel_limit (ENetHost *, size_t);
ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32);
extern void enet_host_bandwidth_throttle (ENetHost *);
ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8);
ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
ENET_API void enet_peer_ping (ENetPeer *);
ENET_API void enet_peer_reset (ENetPeer *);
ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32);
@ -478,6 +491,7 @@ ENET_API void enet_peer_disconnect_later (ENetPeer *, enet_uint32
ENET_API void enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
extern int enet_peer_throttle (ENetPeer *, enet_uint32);
extern void enet_peer_reset_queues (ENetPeer *);
extern void enet_peer_setup_outgoing_command (ENetPeer *, ENetOutgoingCommand *);
extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32);
extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16);

View File

@ -24,6 +24,7 @@ extern void enet_list_clear (ENetList *);
extern ENetListIterator enet_list_insert (ENetListIterator, void *);
extern void * enet_list_remove (ENetListIterator);
extern ENetListIterator enet_list_move (ENetListIterator, void *, void *);
extern size_t enet_list_size (ENetList *);

View File

@ -19,7 +19,7 @@ enum
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0x7FFF
};
typedef enum
typedef enum _ENetProtocolCommand
{
ENET_PROTOCOL_COMMAND_NONE = 0,
ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1,
@ -38,7 +38,7 @@ typedef enum
ENET_PROTOCOL_COMMAND_MASK = 0x0F
} ENetProtocolCommand;
typedef enum
typedef enum _ENetProtocolFlag
{
ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7),
ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6),
@ -47,28 +47,37 @@ typedef enum
ENET_PROTOCOL_HEADER_FLAG_MASK = 0x8000
} ENetProtocolFlag;
typedef struct
#ifdef _MSC_VER_
#pragma pack(push, 1)
#define ENET_PACKED
#elif defined(__GNUC__)
#define ENET_PACKED __attribute__ ((packed))
#else
#define ENET_PACKED
#endif
typedef struct _ENetProtocolHeader
{
enet_uint32 checksum;
enet_uint16 peerID;
enet_uint16 sentTime;
} ENetProtocolHeader;
} ENET_PACKED ENetProtocolHeader;
typedef struct
typedef struct _ENetProtocolCommandHeader
{
enet_uint8 command;
enet_uint8 channelID;
enet_uint16 reliableSequenceNumber;
} ENetProtocolCommandHeader;
} ENET_PACKED ENetProtocolCommandHeader;
typedef struct
typedef struct _ENetProtocolAcknowledge
{
ENetProtocolCommandHeader header;
enet_uint16 receivedReliableSequenceNumber;
enet_uint16 receivedSentTime;
} ENetProtocolAcknowledge;
} ENET_PACKED ENetProtocolAcknowledge;
typedef struct
typedef struct _ENetProtocolConnect
{
ENetProtocolCommandHeader header;
enet_uint16 outgoingPeerID;
@ -81,9 +90,9 @@ typedef struct
enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration;
enet_uint32 sessionID;
} ENetProtocolConnect;
} ENET_PACKED ENetProtocolConnect;
typedef struct
typedef struct _ENetProtocolVerifyConnect
{
ENetProtocolCommandHeader header;
enet_uint16 outgoingPeerID;
@ -95,55 +104,55 @@ typedef struct
enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration;
} ENetProtocolVerifyConnect;
} ENET_PACKED ENetProtocolVerifyConnect;
typedef struct
typedef struct _ENetProtocolBandwidthLimit
{
ENetProtocolCommandHeader header;
enet_uint32 incomingBandwidth;
enet_uint32 outgoingBandwidth;
} ENetProtocolBandwidthLimit;
} ENET_PACKED ENetProtocolBandwidthLimit;
typedef struct
typedef struct _ENetProtocolThrottleConfigure
{
ENetProtocolCommandHeader header;
enet_uint32 packetThrottleInterval;
enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration;
} ENetProtocolThrottleConfigure;
} ENET_PACKED ENetProtocolThrottleConfigure;
typedef struct
typedef struct _ENetProtocolDisconnect
{
ENetProtocolCommandHeader header;
enet_uint32 data;
} ENetProtocolDisconnect;
} ENET_PACKED ENetProtocolDisconnect;
typedef struct
typedef struct _ENetProtocolPing
{
ENetProtocolCommandHeader header;
} ENetProtocolPing;
} ENET_PACKED ENetProtocolPing;
typedef struct
typedef struct _ENetProtocolSendReliable
{
ENetProtocolCommandHeader header;
enet_uint16 dataLength;
} ENetProtocolSendReliable;
} ENET_PACKED ENetProtocolSendReliable;
typedef struct
typedef struct _ENetProtocolSendUnreliable
{
ENetProtocolCommandHeader header;
enet_uint16 unreliableSequenceNumber;
enet_uint16 dataLength;
} ENetProtocolSendUnreliable;
} ENET_PACKED ENetProtocolSendUnreliable;
typedef struct
typedef struct _ENetProtocolSendUnsequenced
{
ENetProtocolCommandHeader header;
enet_uint16 unsequencedGroup;
enet_uint16 dataLength;
} ENetProtocolSendUnsequenced;
} ENET_PACKED ENetProtocolSendUnsequenced;
typedef struct
typedef struct _ENetProtocolSendFragment
{
ENetProtocolCommandHeader header;
enet_uint16 startSequenceNumber;
@ -152,9 +161,9 @@ typedef struct
enet_uint32 fragmentNumber;
enet_uint32 totalLength;
enet_uint32 fragmentOffset;
} ENetProtocolSendFragment;
} ENET_PACKED ENetProtocolSendFragment;
typedef union
typedef union _ENetProtocol
{
ENetProtocolCommandHeader header;
ENetProtocolAcknowledge acknowledge;
@ -168,7 +177,11 @@ typedef union
ENetProtocolSendFragment sendFragment;
ENetProtocolBandwidthLimit bandwidthLimit;
ENetProtocolThrottleConfigure throttleConfigure;
} ENetProtocol;
} ENET_PACKED ENetProtocol;
#ifdef _MSC_VER_
#pragma pack(pop)
#endif
#endif /* __ENET_PROTOCOL_H__ */

View File

@ -5,14 +5,12 @@
#ifndef __ENET_WIN32_H__
#define __ENET_WIN32_H__
#ifdef _MSC_VER
#ifdef ENET_BUILDING_LIB
#pragma warning (disable: 4996) // 'strncpy' was declared deprecated
#pragma warning (disable: 4267) // size_t to int conversion
#pragma warning (disable: 4244) // 64bit to 32bit int
#pragma warning (disable: 4018) // signed/unsigned mismatch
#endif
#endif
#include <stdlib.h>
#include <winsock2.h>

View File

@ -5,14 +5,11 @@
#define ENET_BUILDING_LIB 1
#include "enet/enet.h"
static ENetCallbacks callbacks = { malloc, free, rand };
static ENetCallbacks callbacks = { malloc, free, rand, abort };
int
enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits)
{
if (version != ENET_VERSION)
return -1;
if (inits -> malloc != NULL || inits -> free != NULL)
{
if (inits -> malloc == NULL || inits -> free == NULL)
@ -25,6 +22,12 @@ enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits
if (inits -> rand != NULL)
callbacks.rand = inits -> rand;
if (version >= ENET_VERSION_CREATE(1, 2, 2))
{
if (inits -> no_memory != NULL)
callbacks.no_memory = inits -> no_memory;
}
return enet_initialize ();
}
@ -34,7 +37,7 @@ enet_malloc (size_t size)
void * memory = callbacks.malloc (size);
if (memory == NULL)
abort ();
callbacks.no_memory ();
return memory;
}

View File

@ -27,13 +27,23 @@
ENetHost *
enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth)
{
ENetHost * host = (ENetHost *) enet_malloc (sizeof (ENetHost));
ENetHost * host;
ENetPeer * currentPeer;
if (peerCount > ENET_PROTOCOL_MAXIMUM_PEER_ID)
return NULL;
host = (ENetHost *) enet_malloc (sizeof (ENetHost));
if (host == NULL)
return NULL;
host -> peers = (ENetPeer *) enet_malloc (peerCount * sizeof (ENetPeer));
if (host -> peers == NULL)
{
enet_free (host);
return NULL;
}
memset (host -> peers, 0, peerCount * sizeof (ENetPeer));
host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM);
@ -56,19 +66,26 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
if (address != NULL)
host -> address = * address;
host -> channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
host -> incomingBandwidth = incomingBandwidth;
host -> outgoingBandwidth = outgoingBandwidth;
host -> bandwidthThrottleEpoch = 0;
host -> recalculateBandwidthLimits = 0;
host -> mtu = ENET_HOST_DEFAULT_MTU;
host -> peerCount = peerCount;
host -> lastServicedPeer = host -> peers;
host -> commandCount = 0;
host -> bufferCount = 0;
host -> receivedAddress.host = ENET_HOST_ANY;
host -> receivedAddress.port = 0;
host -> receivedDataLength = 0;
host -> totalSentData = 0;
host -> totalSentPackets = 0;
host -> totalReceivedData = 0;
host -> totalReceivedPackets = 0;
enet_list_clear (& host -> dispatchQueue);
for (currentPeer = host -> peers;
currentPeer < & host -> peers [host -> peerCount];
++ currentPeer)
@ -82,6 +99,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
enet_list_clear (& currentPeer -> sentUnreliableCommands);
enet_list_clear (& currentPeer -> outgoingReliableCommands);
enet_list_clear (& currentPeer -> outgoingUnreliableCommands);
enet_list_clear (& currentPeer -> dispatchedCommands);
enet_peer_reset (currentPeer);
}
@ -142,10 +160,12 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
if (currentPeer >= & host -> peers [host -> peerCount])
return NULL;
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel));
if (currentPeer -> channels == NULL)
return NULL;
currentPeer -> channelCount = channelCount;
currentPeer -> state = ENET_PEER_STATE_CONNECTING;
currentPeer -> address = * address;
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel));
currentPeer -> channelCount = channelCount;
currentPeer -> sessionID = (enet_uint32) enet_rand ();
if (host -> outgoingBandwidth == 0)
@ -194,6 +214,22 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
return currentPeer;
}
/** Limits the maximum allowed channels of future incoming connections.
@param host host to limit
@param channelLimit the maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT
*/
void
enet_host_channel_limit (ENetHost * host, size_t channelLimit)
{
if (! channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
else
if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT)
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
host -> channelLimit = channelLimit;
}
/** Queues a packet to be sent to all peers associated with the host.
@param host host on which to broadcast the packet
@param channelID channel on which to broadcast

View File

@ -40,6 +40,24 @@ enet_list_remove (ENetListIterator position)
return position;
}
ENetListIterator
enet_list_move (ENetListIterator position, void * dataFirst, void * dataLast)
{
ENetListIterator first = (ENetListIterator) dataFirst,
last = (ENetListIterator) dataLast;
first -> previous -> next = last -> next;
last -> next -> previous = first -> previous;
first -> previous = position -> previous;
last -> next = position;
first -> previous -> next = first;
position -> previous = last;
return first;
}
size_t
enet_list_size (ENetList * list)
{

View File

@ -20,6 +20,8 @@ ENetPacket *
enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags)
{
ENetPacket * packet = (ENetPacket *) enet_malloc (sizeof (ENetPacket));
if (packet == NULL)
return NULL;
if (flags & ENET_PACKET_FLAG_NO_ALLOCATE)
packet -> data = (enet_uint8 *) data;

View File

@ -115,9 +115,10 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
enet_uint32 fragmentCount = ENET_HOST_TO_NET_32 ((packet -> dataLength + fragmentLength - 1) / fragmentLength),
fragmentNumber,
fragmentOffset;
ENetList fragments;
ENetOutgoingCommand * fragment;
packet -> flags |= ENET_PACKET_FLAG_RELIABLE;
packet -> flags &= ~ENET_PACKET_FLAG_UNSEQUENCED;
enet_list_clear (& fragments);
for (fragmentNumber = 0,
fragmentOffset = 0;
@ -128,16 +129,41 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
if (packet -> dataLength - fragmentOffset < fragmentLength)
fragmentLength = packet -> dataLength - fragmentOffset;
command.header.command = ENET_PROTOCOL_COMMAND_SEND_FRAGMENT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
command.header.channelID = channelID;
command.sendFragment.startSequenceNumber = startSequenceNumber;
command.sendFragment.dataLength = ENET_HOST_TO_NET_16 (fragmentLength);
command.sendFragment.fragmentCount = fragmentCount;
command.sendFragment.fragmentNumber = ENET_HOST_TO_NET_32 (fragmentNumber);
command.sendFragment.totalLength = ENET_HOST_TO_NET_32 (packet -> dataLength);
command.sendFragment.fragmentOffset = ENET_NET_TO_HOST_32 (fragmentOffset);
fragment = (ENetOutgoingCommand *) enet_malloc (sizeof (ENetOutgoingCommand));
if (fragment == NULL)
{
while (! enet_list_empty (& fragments))
{
fragment = (ENetOutgoingCommand *) enet_list_remove (enet_list_begin (& fragments));
enet_peer_queue_outgoing_command (peer, & command, packet, fragmentOffset, fragmentLength);
enet_free (fragment);
}
return -1;
}
fragment -> fragmentOffset = fragmentOffset;
fragment -> fragmentLength = fragmentLength;
fragment -> packet = packet;
fragment -> command.header.command = ENET_PROTOCOL_COMMAND_SEND_FRAGMENT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
fragment -> command.header.channelID = channelID;
fragment -> command.sendFragment.startSequenceNumber = startSequenceNumber;
fragment -> command.sendFragment.dataLength = ENET_HOST_TO_NET_16 (fragmentLength);
fragment -> command.sendFragment.fragmentCount = fragmentCount;
fragment -> command.sendFragment.fragmentNumber = ENET_HOST_TO_NET_32 (fragmentNumber);
fragment -> command.sendFragment.totalLength = ENET_HOST_TO_NET_32 (packet -> dataLength);
fragment -> command.sendFragment.fragmentOffset = ENET_NET_TO_HOST_32 (fragmentOffset);
enet_list_insert (enet_list_end (& fragments), fragment);
}
packet -> referenceCount += fragmentNumber;
while (! enet_list_empty (& fragments))
{
fragment = (ENetOutgoingCommand *) enet_list_remove (enet_list_begin (& fragments));
enet_peer_setup_outgoing_command (peer, fragment);
}
return 0;
@ -145,9 +171,6 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
command.header.channelID = channelID;
if (! (packet -> flags & (ENET_PACKET_FLAG_RELIABLE | ENET_PACKET_FLAG_UNSEQUENCED)) && channel -> outgoingUnreliableSequenceNumber >= 0xFFFF)
packet -> flags |= ENET_PACKET_FLAG_RELIABLE;
if (packet -> flags & ENET_PACKET_FLAG_RELIABLE)
{
command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
@ -161,59 +184,42 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
command.sendUnsequenced.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
}
else
if (channel -> outgoingUnreliableSequenceNumber >= 0xFFFF)
{
command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
command.sendReliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
}
else
{
command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE;
command.sendUnreliable.unreliableSequenceNumber = ENET_HOST_TO_NET_16 (channel -> outgoingUnreliableSequenceNumber + 1);
command.sendUnreliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
}
enet_peer_queue_outgoing_command (peer, & command, packet, 0, packet -> dataLength);
if (enet_peer_queue_outgoing_command (peer, & command, packet, 0, packet -> dataLength) == NULL)
return -1;
return 0;
}
/** Attempts to dequeue any incoming queued packet.
@param peer peer to dequeue packets from
@param channelID channel on which to receive
@param channelID holds the channel ID of the channel the packet was received on success
@returns a pointer to the packet, or NULL if there are no available incoming queued packets
*/
ENetPacket *
enet_peer_receive (ENetPeer * peer, enet_uint8 channelID)
enet_peer_receive (ENetPeer * peer, enet_uint8 * channelID)
{
ENetChannel * channel = & peer -> channels [channelID];
ENetIncomingCommand * incomingCommand = NULL;
ENetIncomingCommand * incomingCommand;
ENetPacket * packet;
if (! enet_list_empty (& channel -> incomingUnreliableCommands))
{
incomingCommand = (ENetIncomingCommand *) enet_list_front (& channel -> incomingUnreliableCommands);
if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE)
{
if (incomingCommand -> reliableSequenceNumber != channel -> incomingReliableSequenceNumber)
incomingCommand = NULL;
}
}
if (incomingCommand == NULL &&
! enet_list_empty (& channel -> incomingReliableCommands))
{
incomingCommand = (ENetIncomingCommand *) enet_list_front (& channel -> incomingReliableCommands);
if (incomingCommand -> fragmentsRemaining > 0 ||
incomingCommand -> reliableSequenceNumber != (enet_uint16) (channel -> incomingReliableSequenceNumber + 1))
return NULL;
channel -> incomingReliableSequenceNumber = incomingCommand -> reliableSequenceNumber;
if (incomingCommand -> fragmentCount > 0)
channel -> incomingReliableSequenceNumber += incomingCommand -> fragmentCount - 1;
}
if (incomingCommand == NULL)
if (enet_list_empty (& peer -> dispatchedCommands))
return NULL;
enet_list_remove (& incomingCommand -> incomingCommandList);
incomingCommand = (ENetIncomingCommand *) enet_list_remove (enet_list_begin (& peer -> dispatchedCommands));
if (channelID != NULL)
* channelID = incomingCommand -> command.header.channelID;
packet = incomingCommand -> packet;
@ -277,6 +283,13 @@ enet_peer_reset_queues (ENetPeer * peer)
{
ENetChannel * channel;
if (peer -> needsDispatch)
{
enet_list_remove (& peer -> dispatchList);
peer -> needsDispatch = 0;
}
while (! enet_list_empty (& peer -> acknowledgements))
enet_free (enet_list_remove (enet_list_begin (& peer -> acknowledgements)));
@ -284,6 +297,7 @@ enet_peer_reset_queues (ENetPeer * peer)
enet_peer_reset_outgoing_commands (& peer -> sentUnreliableCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingReliableCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingUnreliableCommands);
enet_peer_reset_incoming_commands (& peer -> dispatchedCommands);
if (peer -> channels != NULL && peer -> channelCount > 0)
{
@ -487,9 +501,11 @@ enet_peer_queue_acknowledgement (ENetPeer * peer, const ENetProtocol * command,
return NULL;
}
peer -> outgoingDataTotal += sizeof (ENetProtocolAcknowledge);
acknowledgement = (ENetAcknowledgement *) enet_malloc (sizeof (ENetAcknowledgement));
if (acknowledgement == NULL)
return NULL;
peer -> outgoingDataTotal += sizeof (ENetProtocolAcknowledge);
acknowledgement -> sentTime = sentTime;
acknowledgement -> command = * command;
@ -499,17 +515,14 @@ enet_peer_queue_acknowledgement (ENetPeer * peer, const ENetProtocol * command,
return acknowledgement;
}
ENetOutgoingCommand *
enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 offset, enet_uint16 length)
void
enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoingCommand)
{
ENetChannel * channel = & peer -> channels [command -> header.channelID];
ENetOutgoingCommand * outgoingCommand;
ENetChannel * channel = & peer -> channels [outgoingCommand -> command.header.channelID];
peer -> outgoingDataTotal += enet_protocol_command_size (command -> header.command) + length;
peer -> outgoingDataTotal += enet_protocol_command_size (outgoingCommand -> command.header.command) + outgoingCommand -> fragmentLength;
outgoingCommand = (ENetOutgoingCommand *) enet_malloc (sizeof (ENetOutgoingCommand));
if (command -> header.channelID == 0xFF)
if (outgoingCommand -> command.header.channelID == 0xFF)
{
++ peer -> outgoingReliableSequenceNumber;
@ -517,7 +530,7 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
outgoingCommand -> unreliableSequenceNumber = 0;
}
else
if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
{
++ channel -> outgoingReliableSequenceNumber;
channel -> outgoingUnreliableSequenceNumber = 0;
@ -526,7 +539,7 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
outgoingCommand -> unreliableSequenceNumber = 0;
}
else
if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED)
if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED)
{
++ peer -> outgoingUnsequencedGroup;
@ -545,26 +558,103 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
outgoingCommand -> sentTime = 0;
outgoingCommand -> roundTripTimeout = 0;
outgoingCommand -> roundTripTimeoutLimit = 0;
outgoingCommand -> fragmentOffset = offset;
outgoingCommand -> fragmentLength = length;
outgoingCommand -> packet = packet;
outgoingCommand -> command = * command;
outgoingCommand -> command.header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (outgoingCommand -> reliableSequenceNumber);
if (packet != NULL)
++ packet -> referenceCount;
if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
enet_list_insert (enet_list_end (& peer -> outgoingReliableCommands), outgoingCommand);
else
enet_list_insert (enet_list_end (& peer -> outgoingUnreliableCommands), outgoingCommand);
}
ENetOutgoingCommand *
enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 offset, enet_uint16 length)
{
ENetOutgoingCommand * outgoingCommand = (ENetOutgoingCommand *) enet_malloc (sizeof (ENetOutgoingCommand));
if (outgoingCommand == NULL)
return NULL;
outgoingCommand -> command = * command;
outgoingCommand -> fragmentOffset = offset;
outgoingCommand -> fragmentLength = length;
outgoingCommand -> packet = packet;
if (packet != NULL)
++ packet -> referenceCount;
enet_peer_setup_outgoing_command (peer, outgoingCommand);
return outgoingCommand;
}
static void
enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel)
{
ENetListIterator currentCommand;
for (currentCommand = enet_list_begin (& channel -> incomingUnreliableCommands);
currentCommand != enet_list_end (& channel -> incomingUnreliableCommands);
currentCommand = enet_list_next (currentCommand))
{
ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand;
if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE &&
incomingCommand -> reliableSequenceNumber != channel -> incomingReliableSequenceNumber)
break;
}
if (currentCommand == enet_list_begin (& channel -> incomingUnreliableCommands))
return;
enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingUnreliableCommands), enet_list_previous (currentCommand));
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
}
static void
enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel)
{
ENetListIterator currentCommand;
for (currentCommand = enet_list_begin (& channel -> incomingReliableCommands);
currentCommand != enet_list_end (& channel -> incomingReliableCommands);
currentCommand = enet_list_next (currentCommand))
{
ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand;
if (incomingCommand -> fragmentsRemaining > 0 ||
incomingCommand -> reliableSequenceNumber != (enet_uint16) (channel -> incomingReliableSequenceNumber + 1))
break;
channel -> incomingReliableSequenceNumber = incomingCommand -> reliableSequenceNumber;
if (incomingCommand -> fragmentCount > 0)
channel -> incomingReliableSequenceNumber += incomingCommand -> fragmentCount - 1;
}
if (currentCommand == enet_list_begin (& channel -> incomingReliableCommands))
return;
enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingReliableCommands), enet_list_previous (currentCommand));
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
}
ENetIncomingCommand *
enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command, ENetPacket * packet, enet_uint32 fragmentCount)
{
static ENetIncomingCommand dummyCommand;
ENetChannel * channel = & peer -> channels [command -> header.channelID];
enet_uint32 unreliableSequenceNumber = 0, reliableSequenceNumber;
enet_uint16 reliableWindow, currentWindow;
@ -665,6 +755,8 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
}
incomingCommand = (ENetIncomingCommand *) enet_malloc (sizeof (ENetIncomingCommand));
if (incomingCommand == NULL)
goto notifyError;
incomingCommand -> reliableSequenceNumber = command -> header.reliableSequenceNumber;
incomingCommand -> unreliableSequenceNumber = unreliableSequenceNumber & 0xFFFF;
@ -677,6 +769,12 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
if (fragmentCount > 0)
{
incomingCommand -> fragments = (enet_uint32 *) enet_malloc ((fragmentCount + 31) / 32 * sizeof (enet_uint32));
if (incomingCommand -> fragments == NULL)
{
enet_free (incomingCommand);
goto notifyError;
}
memset (incomingCommand -> fragments, 0, (fragmentCount + 31) / 32 * sizeof (enet_uint32));
}
@ -685,14 +783,32 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
enet_list_insert (enet_list_next (currentCommand), incomingCommand);
switch (command -> header.command & ENET_PROTOCOL_COMMAND_MASK)
{
case ENET_PROTOCOL_COMMAND_SEND_FRAGMENT:
case ENET_PROTOCOL_COMMAND_SEND_RELIABLE:
enet_peer_dispatch_incoming_reliable_commands (peer, channel);
break;
default:
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
break;
}
return incomingCommand;
freePacket:
if (packet != NULL)
{
if (packet -> referenceCount == 0)
enet_packet_destroy (packet);
}
if (fragmentCount > 0)
goto notifyError;
if (packet != NULL && packet -> referenceCount == 0)
enet_packet_destroy (packet);
return & dummyCommand;
notifyError:
if (packet != NULL && packet -> referenceCount == 0)
enet_packet_destroy (packet);
return NULL;
}

View File

@ -34,24 +34,20 @@ enet_protocol_command_size (enet_uint8 commandNumber)
static int
enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
{
ENetPeer * currentPeer = host -> lastServicedPeer;
ENetChannel * channel;
do
while (! enet_list_empty (& host -> dispatchQueue))
{
++ currentPeer;
ENetPeer * peer = (ENetPeer *) enet_list_remove (enet_list_begin (& host -> dispatchQueue));
if (currentPeer >= & host -> peers [host -> peerCount])
currentPeer = host -> peers;
peer -> needsDispatch = 0;
switch (currentPeer -> state)
switch (peer -> state)
{
case ENET_PEER_STATE_CONNECTION_PENDING:
case ENET_PEER_STATE_CONNECTION_SUCCEEDED:
currentPeer -> state = ENET_PEER_STATE_CONNECTED;
peer -> state = ENET_PEER_STATE_CONNECTED;
event -> type = ENET_EVENT_TYPE_CONNECT;
event -> peer = currentPeer;
event -> peer = peer;
return 1;
@ -59,72 +55,77 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
host -> recalculateBandwidthLimits = 1;
event -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = currentPeer;
event -> data = currentPeer -> disconnectData;
event -> peer = peer;
event -> data = peer -> disconnectData;
enet_peer_reset (currentPeer);
host -> lastServicedPeer = currentPeer;
enet_peer_reset (peer);
return 1;
}
if (currentPeer -> state != ENET_PEER_STATE_CONNECTED)
continue;
for (channel = currentPeer -> channels;
channel < & currentPeer -> channels [currentPeer -> channelCount];
++ channel)
{
if (enet_list_empty (& channel -> incomingReliableCommands) &&
enet_list_empty (& channel -> incomingUnreliableCommands))
case ENET_PEER_STATE_CONNECTED:
if (enet_list_empty (& peer -> dispatchedCommands))
continue;
event -> packet = enet_peer_receive (currentPeer, channel - currentPeer -> channels);
event -> packet = enet_peer_receive (peer, & event -> channelID);
if (event -> packet == NULL)
continue;
event -> type = ENET_EVENT_TYPE_RECEIVE;
event -> peer = currentPeer;
event -> channelID = (enet_uint8) (channel - currentPeer -> channels);
event -> peer = peer;
host -> lastServicedPeer = currentPeer;
if (! enet_list_empty (& peer -> dispatchedCommands))
{
peer -> needsDispatch = 1;
enet_list_insert (enet_list_end (& host -> dispatchQueue), & peer -> dispatchList);
}
return 1;
}
} while (currentPeer != host -> lastServicedPeer);
}
return 0;
}
static void
enet_protocol_dispatch_state (ENetHost * host, ENetPeer * peer, ENetPeerState state)
{
peer -> state = state;
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
}
static void
enet_protocol_notify_connect (ENetHost * host, ENetPeer * peer, ENetEvent * event)
{
host -> recalculateBandwidthLimits = 1;
if (event == NULL)
peer -> state = (peer -> state == ENET_PEER_STATE_CONNECTING ? ENET_PEER_STATE_CONNECTION_SUCCEEDED : ENET_PEER_STATE_CONNECTION_PENDING);
else
if (event != NULL)
{
peer -> state = ENET_PEER_STATE_CONNECTED;
peer -> state = ENET_PEER_STATE_CONNECTED;
event -> type = ENET_EVENT_TYPE_CONNECT;
event -> peer = peer;
event -> type = ENET_EVENT_TYPE_CONNECT;
event -> peer = peer;
}
else
enet_protocol_dispatch_state (host, peer, peer -> state == ENET_PEER_STATE_CONNECTING ? ENET_PEER_STATE_CONNECTION_SUCCEEDED : ENET_PEER_STATE_CONNECTION_PENDING);
}
static void
enet_protocol_notify_disconnect (ENetHost * host, ENetPeer * peer, ENetEvent * event)
{
if (peer -> state >= ENET_PEER_STATE_CONNECTION_PENDING)
host -> recalculateBandwidthLimits = 1;
host -> recalculateBandwidthLimits = 1;
if (peer -> state != ENET_PEER_STATE_CONNECTING && peer -> state < ENET_PEER_STATE_CONNECTION_SUCCEEDED)
enet_peer_reset (peer);
else
if (event == NULL)
peer -> state = ENET_PEER_STATE_ZOMBIE;
else
if (event != NULL)
{
event -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = peer;
@ -132,6 +133,8 @@ enet_protocol_notify_disconnect (ENetHost * host, ENetPeer * peer, ENetEvent * e
enet_peer_reset (peer);
}
else
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
}
static void
@ -289,6 +292,12 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
if (currentPeer >= & host -> peers [host -> peerCount])
return NULL;
if (channelCount > host -> channelLimit)
channelCount = host -> channelLimit;
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel));
if (currentPeer -> channels == NULL)
return NULL;
currentPeer -> channelCount = channelCount;
currentPeer -> state = ENET_PEER_STATE_ACKNOWLEDGING_CONNECT;
currentPeer -> sessionID = command -> connect.sessionID;
currentPeer -> address = host -> receivedAddress;
@ -298,8 +307,6 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
currentPeer -> packetThrottleInterval = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleInterval);
currentPeer -> packetThrottleAcceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleAcceleration);
currentPeer -> packetThrottleDeceleration = ENET_NET_TO_HOST_32 (command -> connect.packetThrottleDeceleration);
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel));
currentPeer -> channelCount = channelCount;
for (channel = currentPeer -> channels;
channel < & currentPeer -> channels [channelCount];
@ -396,10 +403,10 @@ enet_protocol_handle_send_reliable (ENetHost * host, ENetPeer * peer, const ENet
packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendReliable),
dataLength,
ENET_PACKET_FLAG_RELIABLE);
if (packet == NULL)
if (packet == NULL ||
enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL)
return -1;
enet_peer_queue_incoming_command (peer, command, packet, 0);
return 0;
}
@ -440,16 +447,15 @@ enet_protocol_handle_send_unsequenced (ENetHost * host, ENetPeer * peer, const E
if (peer -> unsequencedWindow [index / 32] & (1 << (index % 32)))
return 0;
peer -> unsequencedWindow [index / 32] |= 1 << (index % 32);
packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnsequenced),
dataLength,
ENET_PACKET_FLAG_UNSEQUENCED);
if (packet == NULL)
if (packet == NULL ||
enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL)
return -1;
enet_peer_queue_incoming_command (peer, command, packet, 0);
peer -> unsequencedWindow [index / 32] |= 1 << (index % 32);
return 0;
}
@ -471,10 +477,10 @@ enet_protocol_handle_send_unreliable (ENetHost * host, ENetPeer * peer, const EN
packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnreliable),
dataLength,
0);
if (packet == NULL)
if (packet == NULL ||
enet_peer_queue_incoming_command (peer, command, packet, 0) == NULL)
return -1;
enet_peer_queue_incoming_command (peer, command, packet, 0);
return 0;
}
@ -635,7 +641,7 @@ enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetPro
enet_peer_reset_queues (peer);
if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED)
peer -> state = ENET_PEER_STATE_ZOMBIE;
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
else
if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
{
@ -647,7 +653,7 @@ enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetPro
if (command -> header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
peer -> state = ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT;
else
peer -> state = ENET_PEER_STATE_ZOMBIE;
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
peer -> disconnectData = ENET_NET_TO_HOST_32 (command -> disconnect.data);
return 0;
@ -741,22 +747,28 @@ enet_protocol_handle_verify_connect (ENetHost * host, ENetEvent * event, ENetPee
{
enet_uint16 mtu;
enet_uint32 windowSize;
size_t channelCount;
if (peer -> state != ENET_PEER_STATE_CONNECTING)
return 0;
if (ENET_NET_TO_HOST_32 (command -> verifyConnect.channelCount) != peer -> channelCount ||
channelCount = ENET_NET_TO_HOST_32 (command -> verifyConnect.channelCount);
if (channelCount < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT || channelCount > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleInterval) != peer -> packetThrottleInterval ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleAcceleration) != peer -> packetThrottleAcceleration ||
ENET_NET_TO_HOST_32 (command -> verifyConnect.packetThrottleDeceleration) != peer -> packetThrottleDeceleration)
{
peer -> state = ENET_PEER_STATE_ZOMBIE;
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
return -1;
}
enet_protocol_remove_sent_reliable_command (peer, 1, 0xFF);
if (channelCount < peer -> channelCount)
peer -> channelCount = channelCount;
peer -> outgoingPeerID = ENET_NET_TO_HOST_16 (command -> verifyConnect.outgoingPeerID);
mtu = ENET_NET_TO_HOST_16 (command -> verifyConnect.mtu);
@ -994,6 +1006,9 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
host -> receivedDataLength = receivedLength;
host -> totalReceivedData += receivedLength;
host -> totalReceivedPackets ++;
switch (enet_protocol_handle_incoming_commands (host, event))
{
case 1:
@ -1046,7 +1061,7 @@ enet_protocol_send_acknowledgements (ENetHost * host, ENetPeer * peer)
command -> acknowledge.receivedSentTime = ENET_HOST_TO_NET_16 (acknowledgement -> sentTime);
if ((acknowledgement -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_DISCONNECT)
peer -> state = ENET_PEER_STATE_ZOMBIE;
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
enet_list_remove (& acknowledgement -> acknowledgementList);
enet_free (acknowledgement);
@ -1412,6 +1427,9 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
if (sentLength < 0)
return -1;
host -> totalSentData += sentLength;
host -> totalSentPackets ++;
}
return 0;

View File

@ -31,7 +31,7 @@
#endif
#ifndef HAS_SOCKLEN_T
// typedef int socklen_t;
typedef int socklen_t;
#endif
#ifndef MSG_NOSIGNAL