17 Commits

Author SHA1 Message Date
Lee Salzman be852c5d8b 1.3.5 release preparation 2012-07-31 16:15:38 +03:00
Lee Salzman f6160fd2e9 case warning fixes 2012-07-31 16:12:11 +03:00
Lee Salzman 158955c86b unreliable fragment queuing fixes 2012-07-31 16:10:40 +03:00
lsalzman 22f1236079 mingw time workaround 2012-05-30 10:34:14 -07:00
lsalzman 2800fd4e0e updated copyright date 2012-05-29 20:27:16 -07:00
lsalzman ea8faf3579 added per-peer configurable ping interval and timeouts
1.3.4 release prep
2012-05-29 19:05:34 -07:00
Lee Salzman fb55c5d7c3 CVS -> github 2012-05-05 07:51:29 +03:00
Lee Salzman 78e828b80e github migration note 2012-05-05 07:48:43 +03:00
eihrul 5018dcf207 added support for setting tcp send/receive timeouts 2012-02-18 10:31:56 +00:00
eihrul 78222dc79e sanity checks 2012-01-06 15:11:04 +00:00
eihrul 27d8c07142 only bail out of sending on a timeout if there really is an event to dispatch 2012-01-05 04:12:46 +00:00
eihrul 70d0d8f25d warning workarounds 2011-12-31 12:37:26 +00:00
eihrul e96c668702 zero out host memory on creation 2011-12-08 14:20:54 +00:00
eihrul d4768414eb include fix 2011-11-28 21:37:24 +00:00
eihrul 93ceb9d2be enet_crc32 is ENET_API 2011-08-21 07:44:57 +00:00
eihrul ee869ab08a enet 1.3.3 release prep 2011-06-28 15:34:32 +00:00
eihrul 7691ccc318 fixed bug with simultaneous disconnects not dispatching events 2011-06-28 15:25:53 +00:00
16 changed files with 224 additions and 81 deletions
+18
View File
@@ -1,3 +1,17 @@
ENet 1.3.5 (July 31, 2012):
* fixed bug in unreliable packet fragment queuing
ENet 1.3.4 (May 29, 2012):
* added enet_peer_ping_interval() for configuring per-peer ping intervals
* added enet_peer_timeout() for configuring per-peer timeouts
* added protocol packet size limits
ENet 1.3.3 (June 28, 2011):
* fixed bug with simultaneous disconnects not dispatching events
ENet 1.3.2 (May 31, 2011):
* added support for unreliable packet fragmenting via the packet flag
@@ -28,6 +42,10 @@ Caveats: This version is not protocol compatible with the 1.2 series or
earlier. The enet_host_connect and enet_host_create API functions require
supplying additional parameters.
ENet 1.2.5 (June 28, 2011):
* fixed bug with simultaneous disconnects not dispatching events
ENet 1.2.4 (May 31, 2011):
* fixed regression in unreliable packet queuing
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2002-2011 Lee Salzman
Copyright (c) 2002-2012 Lee Salzman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+2 -2
View File
@@ -16,7 +16,7 @@ enetinclude_HEADERS = \
lib_LTLIBRARIES = libenet.la
libenet_la_SOURCES = callbacks.c compress.c host.c list.c packet.c peer.c protocol.c unix.c win32.c
# see info '(libtool) Updating version info' before making a release
libenet_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:2:0
INCLUDES = -Iinclude
libenet_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2:0:0
INCLUDES = -I$(top_srcdir)/include
ACLOCAL_AMFLAGS = -Im4
+1 -1
View File
@@ -1,7 +1,7 @@
Please visit the ENet homepage at http://enet.bespin.org for installation
and usage instructions.
If you obtained this package from CVS, the quick description on how to build
If you obtained this package from github, the quick description on how to build
is:
# Generate the build system.
+1 -1
View File
@@ -1,4 +1,4 @@
AC_INIT([libenet], [1.3.2])
AC_INIT([libenet], [1.3.5])
AC_CONFIG_SRCDIR([include/enet/enet.h])
AM_INIT_AUTOMAKE([foreign])
+5 -1
View File
@@ -12,7 +12,7 @@ by doing the following:
./configure && make && make install
If you obtained the package from CVS, you must have automake and autoconf
If you obtained the package from github, you must have automake and autoconf
available to generate the build system first by doing the following command
before using the above mentioned build procedure:
@@ -27,6 +27,10 @@ is linked in.
@section Windows Microsoft Windows
You may simply use the included "enet.lib" or "enet64.lib" static libraries.
However, if you wish to build the library yourself, then the following
instructions apply:
There is an included MSVC 6 project (enet.dsp) which you may use to
build a suitable library file. Alternatively, you may simply drag all
the ENet source files into your main project.
+1 -1
View File
@@ -1,7 +1,7 @@
/**
@page License License
Copyright (c) 2002-2011 Lee Salzman
Copyright (c) 2002-2012 Lee Salzman
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
+4 -20
View File
@@ -34,28 +34,12 @@ portable, and easily embeddable.
@page SourceDistro Source Distribution
You can retrieve the source to ENet by downloading it in either .tar.gz form
or accessing the cvs distribution directly.
or accessing the github distribution directly.
The most recent stable release (1.3.2) can be downloaded <a href="http://enet.bespin.org/download/enet-1.3.2.tar.gz">here</a>.
The last release that is protocol compatible with the 1.2 series or earlier (1.2.4) can be downloaded <a href="http://enet.bespin.org/download/enet-1.2.4.tar.gz">here</a>
The most recent stable release (1.3.5) can be downloaded <a href="http://enet.bespin.org/download/enet-1.3.5.tar.gz">here</a>.
The last release that is protocol compatible with the 1.2 series or earlier (1.2.5) can be downloaded <a href="http://enet.bespin.org/download/enet-1.2.5.tar.gz">here</a>
To access ENet via anonymous CVS, you must use the CVSROOT
:pserver:anonymous\@bespin.org:/var/lib/cvs/enet with an empty
password.
@code
$ cvs -z3 -d :pserver:anonymous@bespin.org:/var/lib/cvs/enet login
@endcode
Hit the return key when prompted for a password.
@code
$ cvs -z3 -d :pserver:anonymous@bespin.org:/var/lib/cvs/enet co -l .
$ cvs -z3 co enet
@endcode
This will create a CVS directory in the current directory, and with
the second command will proceed to check the enet module out of CVS.
Any problems with CVS access or request for write access should be
sent via email to @ref MailingList.
You can find the most recent ENet source at <a href="https://github.com/lsalzman/enet">the github repository</a>.
*/
+2
View File
@@ -3,6 +3,7 @@
@brief ENet host management functions
*/
#define ENET_BUILDING_LIB 1
#define __MINGW_USE_VC2005_COMPAT 1
#include <string.h>
#include <time.h>
#include "enet/enet.h"
@@ -38,6 +39,7 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
host = (ENetHost *) enet_malloc (sizeof (ENetHost));
if (host == NULL)
return NULL;
memset (host, 0, sizeof (ENetHost));
host -> peers = (ENetPeer *) enet_malloc (peerCount * sizeof (ENetPeer));
if (host -> peers == NULL)
+11 -3
View File
@@ -25,7 +25,7 @@ extern "C"
#define ENET_VERSION_MAJOR 1
#define ENET_VERSION_MINOR 3
#define ENET_VERSION_PATCH 2
#define ENET_VERSION_PATCH 5
#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)
@@ -50,7 +50,9 @@ typedef enum _ENetSocketOption
ENET_SOCKOPT_BROADCAST = 2,
ENET_SOCKOPT_RCVBUF = 3,
ENET_SOCKOPT_SNDBUF = 4,
ENET_SOCKOPT_REUSEADDR = 5
ENET_SOCKOPT_REUSEADDR = 5,
ENET_SOCKOPT_RCVTIMEO = 6,
ENET_SOCKOPT_SNDTIMEO = 7
} ENetSocketOption;
enum
@@ -267,6 +269,10 @@ typedef struct _ENetPeer
enet_uint32 packetThrottleAcceleration;
enet_uint32 packetThrottleDeceleration;
enet_uint32 packetThrottleInterval;
enet_uint32 pingInterval;
enet_uint32 timeoutLimit;
enet_uint32 timeoutMinimum;
enet_uint32 timeoutMaximum;
enet_uint32 lastRoundTripTime;
enet_uint32 lowestRoundTripTime;
enet_uint32 lastRoundTripTimeVariance;
@@ -497,7 +503,7 @@ ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName
ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
ENET_API void enet_packet_destroy (ENetPacket *);
ENET_API int enet_packet_resize (ENetPacket *, size_t);
extern enet_uint32 enet_crc32 (const ENetBuffer *, size_t);
ENET_API enet_uint32 enet_crc32 (const ENetBuffer *, size_t);
ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
ENET_API void enet_host_destroy (ENetHost *);
@@ -515,6 +521,8 @@ 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 * channelID);
ENET_API void enet_peer_ping (ENetPeer *);
ENET_API void enet_peer_ping_interval (ENetPeer *, enet_uint32);
ENET_API void enet_peer_timeout (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
ENET_API void enet_peer_reset (ENetPeer *);
ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32);
ENET_API void enet_peer_disconnect_now (ENetPeer *, enet_uint32);
+3 -1
View File
@@ -16,7 +16,9 @@ enum
ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 32768,
ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1,
ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255,
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF,
ENET_PROTOCOL_MAXIMUM_PACKET_SIZE = 1024 * 1024 * 1024,
ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT = 1024 * 1024
};
typedef enum _ENetProtocolCommand
+5 -1
View File
@@ -26,6 +26,9 @@ enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags)
if (flags & ENET_PACKET_FLAG_NO_ALLOCATE)
packet -> data = (enet_uint8 *) data;
else
if (dataLength <= 0)
packet -> data = NULL;
else
{
packet -> data = (enet_uint8 *) enet_malloc (dataLength);
if (packet -> data == NULL)
@@ -54,7 +57,8 @@ enet_packet_destroy (ENetPacket * packet)
{
if (packet -> freeCallback != NULL)
(* packet -> freeCallback) (packet);
if (! (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE))
if (! (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE) &&
packet -> data != NULL)
enet_free (packet -> data);
enet_free (packet);
}
+110 -30
View File
@@ -104,7 +104,8 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
size_t fragmentLength;
if (peer -> state != ENET_PEER_STATE_CONNECTED ||
channelID >= peer -> channelCount)
channelID >= peer -> channelCount ||
packet -> dataLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE)
return -1;
fragmentLength = peer -> mtu - sizeof (ENetProtocolHeader) - sizeof (ENetProtocolSendFragment);
@@ -113,7 +114,7 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
if (packet -> dataLength > fragmentLength)
{
enet_uint32 fragmentCount = ENET_HOST_TO_NET_32 ((packet -> dataLength + fragmentLength - 1) / fragmentLength),
enet_uint32 fragmentCount = (packet -> dataLength + fragmentLength - 1) / fragmentLength,
fragmentNumber,
fragmentOffset;
enet_uint8 commandNumber;
@@ -121,6 +122,9 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
ENetList fragments;
ENetOutgoingCommand * fragment;
if (fragmentCount > ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT)
return -1;
if ((packet -> flags & (ENET_PACKET_FLAG_RELIABLE | ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT)) == ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT &&
channel -> outgoingUnreliableSequenceNumber < 0xFFFF)
{
@@ -164,7 +168,7 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
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.fragmentCount = ENET_HOST_TO_NET_32 (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);
@@ -292,7 +296,7 @@ enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startComm
static void
enet_peer_reset_incoming_commands (ENetList * queue)
{
enet_peer_remove_incoming_commands(queue, enet_list_begin (queue), enet_list_end(queue));
enet_peer_remove_incoming_commands(queue, enet_list_begin (queue), enet_list_end (queue));
}
void
@@ -368,6 +372,10 @@ enet_peer_reset (ENetPeer * peer)
peer -> packetThrottleAcceleration = ENET_PEER_PACKET_THROTTLE_ACCELERATION;
peer -> packetThrottleDeceleration = ENET_PEER_PACKET_THROTTLE_DECELERATION;
peer -> packetThrottleInterval = ENET_PEER_PACKET_THROTTLE_INTERVAL;
peer -> pingInterval = ENET_PEER_PING_INTERVAL;
peer -> timeoutLimit = ENET_PEER_TIMEOUT_LIMIT;
peer -> timeoutMinimum = ENET_PEER_TIMEOUT_MINIMUM;
peer -> timeoutMaximum = ENET_PEER_TIMEOUT_MAXIMUM;
peer -> lastRoundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME;
peer -> lowestRoundTripTime = ENET_PEER_DEFAULT_ROUND_TRIP_TIME;
peer -> lastRoundTripTimeVariance = 0;
@@ -408,6 +416,46 @@ enet_peer_ping (ENetPeer * peer)
enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);
}
/** Sets the interval at which pings will be sent to a peer.
Pings are used both to monitor the liveness of the connection and also to dynamically
adjust the throttle during periods of low traffic so that the throttle has reasonable
responsiveness during traffic spikes.
@param peer the peer to adjust
@param pingInterval the interval at which to send pings; defaults to ENET_PEER_PING_INTERVAL if 0
*/
void
enet_peer_ping_interval (ENetPeer * peer, enet_uint32 pingInterval)
{
peer -> pingInterval = pingInterval ? pingInterval : ENET_PEER_PING_INTERVAL;
}
/** Sets the timeout parameters for a peer.
The timeout parameter control how and when a peer will timeout from a failure to acknowledge
reliable traffic. Timeout values use an exponential backoff mechanism, where if a reliable
packet is not acknowledge within some multiple of the average RTT plus a variance tolerance,
the timeout will be doubled until it reaches a set limit. If the timeout is thus at this
limit and reliable packets have been sent but not acknowledged within a certain minimum time
period, the peer will be disconnected. Alternatively, if reliable packets have been sent
but not acknowledged for a certain maximum time period, the peer will be disconnected regardless
of the current timeout limit value.
@param peer the peer to adjust
@param timeoutLimit the timeout limit; defaults to ENET_PEER_TIMEOUT_LIMIT if 0
@param timeoutMinimum the timeout minimum; defaults to ENET_PEER_TIMEOUT_MINIMUM if 0
@param timeoutMaximum the timeout maximum; defaults to ENET_PEER_TIMEOUT_MAXIMUM if 0
*/
void
enet_peer_timeout (ENetPeer * peer, enet_uint32 timeoutLimit, enet_uint32 timeoutMinimum, enet_uint32 timeoutMaximum)
{
peer -> timeoutLimit = timeoutLimit ? timeoutLimit : ENET_PEER_TIMEOUT_LIMIT;
peer -> timeoutMinimum = timeoutMinimum ? timeoutMinimum : ENET_PEER_TIMEOUT_MINIMUM;
peer -> timeoutMaximum = timeoutMaximum ? timeoutMaximum : ENET_PEER_TIMEOUT_MAXIMUM;
}
/** Force an immediate disconnection from a peer.
@param peer peer to disconnect
@param data data describing the disconnection
@@ -630,42 +678,71 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED)
continue;
else
if (incomingCommand -> reliableSequenceNumber != channel -> incomingReliableSequenceNumber)
break;
else
if (incomingCommand -> fragmentsRemaining <= 0)
channel -> incomingUnreliableSequenceNumber = incomingCommand -> unreliableSequenceNumber;
else
if (startCommand == currentCommand)
startCommand = enet_list_next (currentCommand);
else
{
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
if (! peer -> needsDispatch)
{
if (incomingCommand -> reliableSequenceNumber == channel -> incomingReliableSequenceNumber)
{
if (incomingCommand -> fragmentsRemaining <= 0)
{
channel -> incomingUnreliableSequenceNumber = incomingCommand -> unreliableSequenceNumber;
continue;
}
if (startCommand != currentCommand)
{
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
}
droppedCommand = startCommand = enet_list_next (currentCommand);
droppedCommand = currentCommand;
}
else
if (droppedCommand != currentCommand)
droppedCommand = enet_list_previous (currentCommand);
}
else
{
enet_uint16 reliableWindow = incomingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE,
currentWindow = channel -> incomingReliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE;
if (incomingCommand -> reliableSequenceNumber < channel -> incomingReliableSequenceNumber)
reliableWindow += ENET_PEER_RELIABLE_WINDOWS;
if (reliableWindow >= currentWindow && reliableWindow < currentWindow + ENET_PEER_FREE_RELIABLE_WINDOWS - 1)
break;
droppedCommand = enet_list_next (currentCommand);
if (startCommand != currentCommand)
{
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
}
}
startCommand = enet_list_next (currentCommand);
}
if (startCommand != currentCommand)
{
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
if (! peer -> needsDispatch)
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
}
peer -> needsDispatch = 1;
}
droppedCommand = startCommand = enet_list_next (currentCommand);
droppedCommand = currentCommand;
}
enet_peer_remove_incoming_commands (& channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand);
@@ -674,6 +751,7 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
void
enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel)
{
enet_uint16 oldReliableSequenceNumber = channel -> incomingReliableSequenceNumber;
ENetListIterator currentCommand;
for (currentCommand = enet_list_begin (& channel -> incomingReliableCommands);
@@ -706,7 +784,8 @@ enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * ch
peer -> needsDispatch = 1;
}
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
if (! enet_list_empty (& channel -> incomingUnreliableCommands))
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
}
ENetIncomingCommand *
@@ -715,7 +794,7 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
static ENetIncomingCommand dummyCommand;
ENetChannel * channel = & peer -> channels [command -> header.channelID];
enet_uint32 unreliableSequenceNumber = 0, reliableSequenceNumber;
enet_uint32 unreliableSequenceNumber = 0, reliableSequenceNumber = 0;
enet_uint16 reliableWindow, currentWindow;
ENetIncomingCommand * incomingCommand;
ENetListIterator currentCommand;
@@ -832,7 +911,8 @@ 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 (fragmentCount <= ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT)
incomingCommand -> fragments = (enet_uint32 *) enet_malloc ((fragmentCount + 31) / 32 * sizeof (enet_uint32));
if (incomingCommand -> fragments == NULL)
{
enet_free (incomingCommand);
+43 -18
View File
@@ -83,6 +83,9 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
}
return 1;
default:
break;
}
}
@@ -170,7 +173,7 @@ enet_protocol_remove_sent_unreliable_commands (ENetPeer * peer)
static ENetProtocolCommand
enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliableSequenceNumber, enet_uint8 channelID)
{
ENetOutgoingCommand * outgoingCommand;
ENetOutgoingCommand * outgoingCommand = NULL;
ENetListIterator currentCommand;
ENetProtocolCommand commandNumber;
int wasSent = 1;
@@ -406,7 +409,9 @@ enet_protocol_handle_send_reliable (ENetHost * host, ENetPeer * peer, const ENet
dataLength = ENET_NET_TO_HOST_16 (command -> sendReliable.dataLength);
* currentData += dataLength;
if (* currentData > & host -> receivedData [host -> receivedDataLength])
if (dataLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendReliable),
@@ -432,7 +437,9 @@ enet_protocol_handle_send_unsequenced (ENetHost * host, ENetPeer * peer, const E
dataLength = ENET_NET_TO_HOST_16 (command -> sendUnsequenced.dataLength);
* currentData += dataLength;
if (* currentData > & host -> receivedData [host -> receivedDataLength])
if (dataLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
unsequencedGroup = ENET_NET_TO_HOST_16 (command -> sendUnsequenced.unsequencedGroup);
@@ -480,7 +487,9 @@ enet_protocol_handle_send_unreliable (ENetHost * host, ENetPeer * peer, const EN
dataLength = ENET_NET_TO_HOST_16 (command -> sendUnreliable.dataLength);
* currentData += dataLength;
if (* currentData > & host -> receivedData [host -> receivedDataLength])
if (dataLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnreliable),
@@ -513,7 +522,9 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
fragmentLength = ENET_NET_TO_HOST_16 (command -> sendFragment.dataLength);
* currentData += fragmentLength;
if (* currentData > & host -> receivedData [host -> receivedDataLength])
if (fragmentLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
channel = & peer -> channels [command -> header.channelID];
@@ -532,9 +543,11 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
fragmentOffset = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentOffset);
totalLength = ENET_NET_TO_HOST_32 (command -> sendFragment.totalLength);
if (fragmentOffset >= totalLength ||
fragmentOffset + fragmentLength > totalLength ||
fragmentNumber >= fragmentCount)
if (fragmentCount > ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT ||
fragmentNumber >= fragmentCount ||
totalLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
fragmentOffset >= totalLength ||
fragmentLength > totalLength - fragmentOffset)
return -1;
for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingReliableCommands));
@@ -622,7 +635,9 @@ enet_protocol_handle_send_unreliable_fragment (ENetHost * host, ENetPeer * peer,
fragmentLength = ENET_NET_TO_HOST_16 (command -> sendFragment.dataLength);
* currentData += fragmentLength;
if (* currentData > & host -> receivedData [host -> receivedDataLength])
if (fragmentLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
* currentData < host -> receivedData ||
* currentData > & host -> receivedData [host -> receivedDataLength])
return -1;
channel = & peer -> channels [command -> header.channelID];
@@ -647,9 +662,11 @@ enet_protocol_handle_send_unreliable_fragment (ENetHost * host, ENetPeer * peer,
fragmentOffset = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentOffset);
totalLength = ENET_NET_TO_HOST_32 (command -> sendFragment.totalLength);
if (fragmentOffset >= totalLength ||
fragmentOffset + fragmentLength > totalLength ||
fragmentNumber >= fragmentCount)
if (fragmentCount > ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT ||
fragmentNumber >= fragmentCount ||
totalLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
fragmentOffset >= totalLength ||
fragmentLength > totalLength - fragmentOffset)
return -1;
for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingUnreliableCommands));
@@ -764,7 +781,7 @@ enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetPro
enet_peer_reset_queues (peer);
if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED)
if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED || peer -> state == ENET_PEER_STATE_DISCONNECTING)
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)
@@ -863,6 +880,9 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
enet_list_empty (& peer -> sentReliableCommands))
enet_peer_disconnect (peer, peer -> eventData);
break;
default:
break;
}
return 0;
@@ -1361,9 +1381,9 @@ enet_protocol_check_timeouts (ENetHost * host, ENetPeer * peer, ENetEvent * even
peer -> earliestTimeout = outgoingCommand -> sentTime;
if (peer -> earliestTimeout != 0 &&
(ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= ENET_PEER_TIMEOUT_MAXIMUM ||
(ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= peer -> timeoutMaximum ||
(outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit &&
ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= ENET_PEER_TIMEOUT_MINIMUM)))
ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= peer -> timeoutMinimum)))
{
enet_protocol_notify_disconnect (host, peer, event);
@@ -1472,7 +1492,7 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
if (outgoingCommand -> roundTripTimeout == 0)
{
outgoingCommand -> roundTripTimeout = peer -> roundTripTime + 4 * peer -> roundTripTimeVariance;
outgoingCommand -> roundTripTimeoutLimit = ENET_PEER_TIMEOUT_LIMIT * outgoingCommand -> roundTripTimeout;
outgoingCommand -> roundTripTimeoutLimit = peer -> timeoutLimit * outgoingCommand -> roundTripTimeout;
}
if (enet_list_empty (& peer -> sentReliableCommands))
@@ -1548,12 +1568,17 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
! enet_list_empty (& currentPeer -> sentReliableCommands) &&
ENET_TIME_GREATER_EQUAL (host -> serviceTime, currentPeer -> nextTimeout) &&
enet_protocol_check_timeouts (host, currentPeer, event) == 1)
return 1;
{
if (event != NULL && event -> type != ENET_EVENT_TYPE_NONE)
return 1;
else
continue;
}
if ((enet_list_empty (& currentPeer -> outgoingReliableCommands) ||
enet_protocol_send_reliable_outgoing_commands (host, currentPeer)) &&
enet_list_empty (& currentPeer -> sentReliableCommands) &&
ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= ENET_PEER_PING_INTERVAL &&
ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= currentPeer -> pingInterval &&
currentPeer -> mtu - host -> packetSize >= sizeof (ENetProtocolPing))
{
enet_peer_ping (currentPeer);
+8
View File
@@ -219,6 +219,14 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
result = setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (char *) & value, sizeof (int));
break;
case ENET_SOCKOPT_RCVTIMEO:
result = setsockopt (socket, SOL_SOCKET, SO_RCVTIMEO, (char *) & value, sizeof (int));
break;
case ENET_SOCKOPT_SNDTIMEO:
result = setsockopt (socket, SOL_SOCKET, SO_SNDTIMEO, (char *) & value, sizeof (int));
break;
default:
break;
}
+9 -1
View File
@@ -166,6 +166,14 @@ enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
result = setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (char *) & value, sizeof (int));
break;
case ENET_SOCKOPT_RCVTIMEO:
result = setsockopt (socket, SOL_SOCKET, SO_RCVTIMEO, (char *) & value, sizeof (int));
break;
case ENET_SOCKOPT_SNDTIMEO:
result = setsockopt (socket, SOL_SOCKET, SO_SNDTIMEO, (char *) & value, sizeof (int));
break;
default:
break;
}
@@ -238,7 +246,7 @@ enet_socket_send (ENetSocket socket,
(DWORD) bufferCount,
& sentLength,
0,
address != NULL ? (struct sockaddr *) & sin : 0,
address != NULL ? (struct sockaddr *) & sin : NULL,
address != NULL ? sizeof (struct sockaddr_in) : 0,
NULL,
NULL) == SOCKET_ERROR)