Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7c0ce8240 | |||
| 2c413b2353 | |||
| c74ac8b844 | |||
| 77cc156305 | |||
| 2d979ceb51 | |||
| 9dff8f72cf | |||
| 0e0ace781b | |||
| 74d4c4a88f | |||
| 0fd4c9389b | |||
| 71b7550049 | |||
| be852c5d8b | |||
| f6160fd2e9 | |||
| 158955c86b | |||
| 22f1236079 | |||
| 2800fd4e0e | |||
| ea8faf3579 | |||
| fb55c5d7c3 | |||
| 78e828b80e | |||
| 5018dcf207 | |||
| 78222dc79e | |||
| 27d8c07142 | |||
| 70d0d8f25d | |||
| e96c668702 | |||
| d4768414eb | |||
| 93ceb9d2be | |||
| ee869ab08a | |||
| 7691ccc318 | |||
| cfb05d051b | |||
| f38c177db0 | |||
| 33e2fc6201 | |||
| 620e92fa66 | |||
| 39a851cb16 | |||
| c77495463b | |||
| 0419c707e9 | |||
| 5258b40640 | |||
| 907b4ba2f5 | |||
| 7af1cd0de7 | |||
| 6ad4a745fb | |||
| 1e18fd6001 |
@@ -1,3 +1,37 @@
|
||||
ENet 1.3.6 (December 11, 2012):
|
||||
|
||||
* added support for intercept callback in ENetHost that can be used to process raw packets before ENet
|
||||
* added enet_socket_shutdown() for issuing shutdown on a socket
|
||||
* fixed enet_socket_connect() to not error on non-blocking connects
|
||||
* fixed bug in MTU negotiation during connections
|
||||
|
||||
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
|
||||
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT
|
||||
* fixed regression in unreliable packet queuing
|
||||
* added check against received port to limit some forms of IP-spoofing
|
||||
|
||||
ENet 1.3.1 (February 10, 2011):
|
||||
|
||||
* fixed bug in tracking of reliable data in transit
|
||||
* reliable data window size now scales with the throttle
|
||||
* fixed bug in fragment length calculation when checksums are used
|
||||
|
||||
ENet 1.3.0 (June 5, 2010):
|
||||
|
||||
* enet_host_create() now requires the channel limit to be specified as
|
||||
@@ -15,6 +49,19 @@ 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
|
||||
* added check against received port to limit some forms of IP-spoofing
|
||||
|
||||
ENet 1.2.3 (February 10, 2011):
|
||||
|
||||
* fixed bug in tracking reliable data in transit
|
||||
|
||||
ENet 1.2.2 (June 5, 2010):
|
||||
|
||||
* checksum functionality is now enabled by setting a checksum callback
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2002-2010 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
@@ -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:0:0
|
||||
INCLUDES = -Iinclude
|
||||
libenet_la_LDFLAGS = $(AM_LDFLAGS) -version-info 3:0:1
|
||||
INCLUDES = -I$(top_srcdir)/include
|
||||
|
||||
ACLOCAL_AMFLAGS = -Im4
|
||||
|
||||
@@ -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
@@ -1,4 +1,4 @@
|
||||
AC_INIT([libenet], [1.3.0])
|
||||
AC_INIT([libenet], [1.3.6])
|
||||
AC_CONFIG_SRCDIR([include/enet/enet.h])
|
||||
AM_INIT_AUTOMAKE([foreign])
|
||||
|
||||
|
||||
+5
-1
@@ -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
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
@page License License
|
||||
|
||||
Copyright (c) 2002-2010 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
@@ -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.0) can be downloaded <a href="http://enet.bespin.org/download/enet-1.3.0.tar.gz">here</a>.
|
||||
The last release that is protocol compatible with the 1.2 series or earlier (1.2.2) can be downloaded <a href="http://enet.bespin.org/download/enet-1.2.2.tar.gz">here</a>
|
||||
The most recent stable release (1.3.6) can be downloaded <a href="http://enet.bespin.org/download/enet-1.3.6.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>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -101,6 +103,8 @@ enet_host_create (const ENetAddress * address, size_t peerCount, size_t channelL
|
||||
host -> compressor.decompress = NULL;
|
||||
host -> compressor.destroy = NULL;
|
||||
|
||||
host -> intercept = NULL;
|
||||
|
||||
enet_list_clear (& host -> dispatchQueue);
|
||||
|
||||
for (currentPeer = host -> peers;
|
||||
@@ -133,6 +137,9 @@ enet_host_destroy (ENetHost * host)
|
||||
{
|
||||
ENetPeer * currentPeer;
|
||||
|
||||
if (host == NULL)
|
||||
return;
|
||||
|
||||
enet_socket_destroy (host -> socket);
|
||||
|
||||
for (currentPeer = host -> peers;
|
||||
@@ -210,6 +217,7 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
|
||||
channel -> outgoingReliableSequenceNumber = 0;
|
||||
channel -> outgoingUnreliableSequenceNumber = 0;
|
||||
channel -> incomingReliableSequenceNumber = 0;
|
||||
channel -> incomingUnreliableSequenceNumber = 0;
|
||||
|
||||
enet_list_clear (& channel -> incomingReliableCommands);
|
||||
enet_list_clear (& channel -> incomingUnreliableCommands);
|
||||
|
||||
+32
-5
@@ -25,12 +25,16 @@ extern "C"
|
||||
|
||||
#define ENET_VERSION_MAJOR 1
|
||||
#define ENET_VERSION_MINOR 3
|
||||
#define ENET_VERSION_PATCH 0
|
||||
#define ENET_VERSION_PATCH 6
|
||||
#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;
|
||||
|
||||
struct _ENetHost;
|
||||
struct _ENetEvent;
|
||||
struct _ENetPacket;
|
||||
|
||||
typedef enum _ENetSocketType
|
||||
{
|
||||
ENET_SOCKET_TYPE_STREAM = 1,
|
||||
@@ -50,9 +54,18 @@ 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;
|
||||
|
||||
typedef enum _ENetSocketShutdown
|
||||
{
|
||||
ENET_SOCKET_SHUTDOWN_READ = 0,
|
||||
ENET_SOCKET_SHUTDOWN_WRITE = 1,
|
||||
ENET_SOCKET_SHUTDOWN_READ_WRITE = 2
|
||||
} ENetSocketShutdown;
|
||||
|
||||
enum
|
||||
{
|
||||
ENET_HOST_ANY = 0, /**< specifies the default server host */
|
||||
@@ -96,10 +109,12 @@ typedef enum _ENetPacketFlag
|
||||
*/
|
||||
ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1),
|
||||
/** packet will not allocate data, and user must supply it instead */
|
||||
ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2)
|
||||
ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2),
|
||||
/** packet will be fragmented using unreliable (instead of reliable) sends
|
||||
* if it exceeds the MTU */
|
||||
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = (1 << 3)
|
||||
} ENetPacketFlag;
|
||||
|
||||
struct _ENetPacket;
|
||||
typedef void (ENET_CALLBACK * ENetPacketFreeCallback) (struct _ENetPacket *);
|
||||
|
||||
/**
|
||||
@@ -218,6 +233,7 @@ typedef struct _ENetChannel
|
||||
enet_uint16 usedReliableWindows;
|
||||
enet_uint16 reliableWindows [ENET_PEER_RELIABLE_WINDOWS];
|
||||
enet_uint16 incomingReliableSequenceNumber;
|
||||
enet_uint16 incomingUnreliableSequenceNumber;
|
||||
ENetList incomingReliableCommands;
|
||||
ENetList incomingUnreliableCommands;
|
||||
} ENetChannel;
|
||||
@@ -263,6 +279,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;
|
||||
@@ -302,6 +322,9 @@ typedef struct _ENetCompressor
|
||||
|
||||
/** 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);
|
||||
|
||||
/** 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) (struct _ENetHost * host, struct _ENetEvent * event);
|
||||
|
||||
/** An ENet host for communicating with peers.
|
||||
*
|
||||
@@ -351,6 +374,7 @@ typedef struct _ENetHost
|
||||
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 */
|
||||
ENetInterceptCallback intercept; /**< callback the user can set to intercept received raw UDP packets */
|
||||
} ENetHost;
|
||||
|
||||
/**
|
||||
@@ -450,6 +474,7 @@ ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENe
|
||||
ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
|
||||
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_shutdown (ENetSocket, ENetSocketShutdown);
|
||||
ENET_API void enet_socket_destroy (ENetSocket);
|
||||
ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
|
||||
|
||||
@@ -493,7 +518,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 *);
|
||||
@@ -511,6 +536,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);
|
||||
|
||||
@@ -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
|
||||
@@ -33,7 +35,8 @@ typedef enum _ENetProtocolCommand
|
||||
ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED = 9,
|
||||
ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT = 10,
|
||||
ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE = 11,
|
||||
ENET_PROTOCOL_COMMAND_COUNT = 12,
|
||||
ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT = 12,
|
||||
ENET_PROTOCOL_COMMAND_COUNT = 13,
|
||||
|
||||
ENET_PROTOCOL_COMMAND_MASK = 0x0F
|
||||
} ENetProtocolCommand;
|
||||
|
||||
@@ -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)
|
||||
@@ -52,9 +55,13 @@ enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags)
|
||||
void
|
||||
enet_packet_destroy (ENetPacket * packet)
|
||||
{
|
||||
if (packet == NULL)
|
||||
return;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
the mean round trip time measured over the interval, then the throttle probability
|
||||
is decreased to limit traffic by an amount specified in the deceleration parameter, which
|
||||
is a ratio to the ENET_PEER_PACKET_THROTTLE_SCALE constant. When the throttle has
|
||||
a value of ENET_PEER_PACKET_THROTTLE_SCALE, on unreliable packets are dropped by
|
||||
a value of ENET_PEER_PACKET_THROTTLE_SCALE, no unreliable packets are dropped by
|
||||
ENet, and so 100% of all unreliable packets will be sent. When the throttle has a
|
||||
value of 0, all unreliable packets are dropped by ENet, and so 0% of all unreliable
|
||||
packets will be sent. Intermediate values for the throttle represent intermediate
|
||||
@@ -104,20 +104,39 @@ 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);
|
||||
if (peer -> host -> checksum != NULL)
|
||||
fragmentLength -= sizeof(enet_uint32);
|
||||
|
||||
if (packet -> dataLength > fragmentLength)
|
||||
{
|
||||
enet_uint16 startSequenceNumber = ENET_HOST_TO_NET_16 (channel -> outgoingReliableSequenceNumber + 1);
|
||||
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;
|
||||
enet_uint16 startSequenceNumber;
|
||||
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)
|
||||
{
|
||||
commandNumber = ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT;
|
||||
startSequenceNumber = ENET_HOST_TO_NET_16 (channel -> outgoingUnreliableSequenceNumber + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandNumber = ENET_PROTOCOL_COMMAND_SEND_FRAGMENT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
|
||||
startSequenceNumber = ENET_HOST_TO_NET_16 (channel -> outgoingReliableSequenceNumber + 1);
|
||||
}
|
||||
|
||||
enet_list_clear (& fragments);
|
||||
|
||||
for (fragmentNumber = 0,
|
||||
@@ -145,11 +164,11 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
|
||||
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.command = commandNumber;
|
||||
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);
|
||||
@@ -171,20 +190,13 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
|
||||
|
||||
command.header.channelID = channelID;
|
||||
|
||||
if (packet -> flags & ENET_PACKET_FLAG_RELIABLE)
|
||||
{
|
||||
command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
|
||||
command.sendReliable.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
|
||||
}
|
||||
else
|
||||
if (packet -> flags & ENET_PACKET_FLAG_UNSEQUENCED)
|
||||
if ((packet -> flags & (ENET_PACKET_FLAG_RELIABLE | ENET_PACKET_FLAG_UNSEQUENCED)) == ENET_PACKET_FLAG_UNSEQUENCED)
|
||||
{
|
||||
command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED | ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED;
|
||||
command.sendUnsequenced.unsequencedGroup = ENET_HOST_TO_NET_16 (peer -> outgoingUnsequencedGroup + 1);
|
||||
command.sendUnsequenced.dataLength = ENET_HOST_TO_NET_16 (packet -> dataLength);
|
||||
}
|
||||
else
|
||||
if (channel -> outgoingUnreliableSequenceNumber >= 0xFFFF)
|
||||
if (packet -> flags & ENET_PACKET_FLAG_RELIABLE || 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);
|
||||
@@ -192,7 +204,6 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -255,14 +266,18 @@ enet_peer_reset_outgoing_commands (ENetList * queue)
|
||||
}
|
||||
|
||||
static void
|
||||
enet_peer_reset_incoming_commands (ENetList * queue)
|
||||
enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand)
|
||||
{
|
||||
ENetIncomingCommand * incomingCommand;
|
||||
|
||||
while (! enet_list_empty (queue))
|
||||
ENetListIterator currentCommand;
|
||||
|
||||
for (currentCommand = startCommand; currentCommand != endCommand; )
|
||||
{
|
||||
incomingCommand = (ENetIncomingCommand *) enet_list_remove (enet_list_begin (queue));
|
||||
ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand;
|
||||
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
|
||||
enet_list_remove (& incomingCommand -> incomingCommandList);
|
||||
|
||||
if (incomingCommand -> packet != NULL)
|
||||
{
|
||||
-- incomingCommand -> packet -> referenceCount;
|
||||
@@ -278,6 +293,12 @@ enet_peer_reset_incoming_commands (ENetList * queue)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
enet_peer_reset_incoming_commands (ENetList * queue)
|
||||
{
|
||||
enet_peer_remove_incoming_commands(queue, enet_list_begin (queue), enet_list_end (queue));
|
||||
}
|
||||
|
||||
void
|
||||
enet_peer_reset_queues (ENetPeer * peer)
|
||||
{
|
||||
@@ -351,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;
|
||||
@@ -391,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
|
||||
@@ -548,7 +613,8 @@ enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoin
|
||||
}
|
||||
else
|
||||
{
|
||||
++ channel -> outgoingUnreliableSequenceNumber;
|
||||
if (outgoingCommand -> fragmentOffset == 0)
|
||||
++ channel -> outgoingUnreliableSequenceNumber;
|
||||
|
||||
outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber;
|
||||
outgoingCommand -> unreliableSequenceNumber = channel -> outgoingUnreliableSequenceNumber;
|
||||
@@ -560,6 +626,20 @@ enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoin
|
||||
outgoingCommand -> roundTripTimeoutLimit = 0;
|
||||
outgoingCommand -> command.header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (outgoingCommand -> reliableSequenceNumber);
|
||||
|
||||
switch (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK)
|
||||
{
|
||||
case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE:
|
||||
outgoingCommand -> command.sendUnreliable.unreliableSequenceNumber = ENET_HOST_TO_NET_16 (outgoingCommand -> unreliableSequenceNumber);
|
||||
break;
|
||||
|
||||
case ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED:
|
||||
outgoingCommand -> command.sendUnsequenced.unsequencedGroup = ENET_HOST_TO_NET_16 (peer -> outgoingUnsequencedGroup);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
|
||||
enet_list_insert (enet_list_end (& peer -> outgoingReliableCommands), outgoingCommand);
|
||||
else
|
||||
@@ -588,30 +668,84 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
|
||||
void
|
||||
enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel)
|
||||
{
|
||||
ENetListIterator currentCommand;
|
||||
ENetListIterator droppedCommand, startCommand, currentCommand;
|
||||
|
||||
for (currentCommand = enet_list_begin (& channel -> incomingUnreliableCommands);
|
||||
for (droppedCommand = startCommand = 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 ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED)
|
||||
continue;
|
||||
|
||||
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 = 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 (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)
|
||||
if (startCommand != currentCommand)
|
||||
{
|
||||
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
|
||||
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
|
||||
|
||||
peer -> needsDispatch = 1;
|
||||
if (! peer -> needsDispatch)
|
||||
{
|
||||
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
|
||||
|
||||
peer -> needsDispatch = 1;
|
||||
}
|
||||
|
||||
droppedCommand = currentCommand;
|
||||
}
|
||||
|
||||
enet_peer_remove_incoming_commands (& channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -638,6 +772,8 @@ enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * ch
|
||||
if (currentCommand == enet_list_begin (& channel -> incomingReliableCommands))
|
||||
return;
|
||||
|
||||
channel -> incomingUnreliableSequenceNumber = 0;
|
||||
|
||||
enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingReliableCommands), enet_list_previous (currentCommand));
|
||||
|
||||
if (! peer -> needsDispatch)
|
||||
@@ -647,7 +783,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 *
|
||||
@@ -656,7 +793,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;
|
||||
@@ -682,7 +819,7 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
|
||||
case ENET_PROTOCOL_COMMAND_SEND_FRAGMENT:
|
||||
case ENET_PROTOCOL_COMMAND_SEND_RELIABLE:
|
||||
if (reliableSequenceNumber == channel -> incomingReliableSequenceNumber)
|
||||
goto freePacket;
|
||||
goto freePacket;
|
||||
|
||||
for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingReliableCommands));
|
||||
currentCommand != enet_list_end (& channel -> incomingReliableCommands);
|
||||
@@ -710,15 +847,20 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
|
||||
break;
|
||||
|
||||
case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE:
|
||||
case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT:
|
||||
unreliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> sendUnreliable.unreliableSequenceNumber);
|
||||
|
||||
if (reliableSequenceNumber == channel -> incomingReliableSequenceNumber &&
|
||||
unreliableSequenceNumber <= channel -> incomingUnreliableSequenceNumber)
|
||||
goto freePacket;
|
||||
|
||||
for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingUnreliableCommands));
|
||||
currentCommand != enet_list_end (& channel -> incomingUnreliableCommands);
|
||||
currentCommand = enet_list_previous (currentCommand))
|
||||
{
|
||||
incomingCommand = (ENetIncomingCommand *) currentCommand;
|
||||
|
||||
if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) != ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE)
|
||||
if ((command -> header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED)
|
||||
continue;
|
||||
|
||||
if (reliableSequenceNumber >= channel -> incomingReliableSequenceNumber)
|
||||
@@ -768,7 +910,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);
|
||||
|
||||
+264
-60
@@ -23,6 +23,7 @@ static size_t commandSizes [ENET_PROTOCOL_COMMAND_COUNT] =
|
||||
sizeof (ENetProtocolSendUnsequenced),
|
||||
sizeof (ENetProtocolBandwidthLimit),
|
||||
sizeof (ENetProtocolThrottleConfigure),
|
||||
sizeof (ENetProtocolSendFragment)
|
||||
};
|
||||
|
||||
size_t
|
||||
@@ -82,6 +83,9 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,9 +173,10 @@ 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;
|
||||
|
||||
for (currentCommand = enet_list_begin (& peer -> sentReliableCommands);
|
||||
currentCommand != enet_list_end (& peer -> sentReliableCommands);
|
||||
@@ -201,8 +206,13 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
|
||||
|
||||
if (currentCommand == enet_list_end (& peer -> outgoingReliableCommands))
|
||||
return ENET_PROTOCOL_COMMAND_NONE;
|
||||
|
||||
wasSent = 0;
|
||||
}
|
||||
|
||||
if (outgoingCommand == NULL)
|
||||
return ENET_PROTOCOL_COMMAND_NONE;
|
||||
|
||||
if (channelID < peer -> channelCount)
|
||||
{
|
||||
ENetChannel * channel = & peer -> channels [channelID];
|
||||
@@ -221,7 +231,8 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
|
||||
|
||||
if (outgoingCommand -> packet != NULL)
|
||||
{
|
||||
peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength;
|
||||
if (wasSent)
|
||||
peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength;
|
||||
|
||||
-- outgoingCommand -> packet -> referenceCount;
|
||||
|
||||
@@ -315,6 +326,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
|
||||
channel -> outgoingReliableSequenceNumber = 0;
|
||||
channel -> outgoingUnreliableSequenceNumber = 0;
|
||||
channel -> incomingReliableSequenceNumber = 0;
|
||||
channel -> incomingUnreliableSequenceNumber = 0;
|
||||
|
||||
enet_list_clear (& channel -> incomingReliableCommands);
|
||||
enet_list_clear (& channel -> incomingUnreliableCommands);
|
||||
@@ -373,7 +385,7 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
|
||||
verifyCommand.verifyConnect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID);
|
||||
verifyCommand.verifyConnect.incomingSessionID = incomingSessionID;
|
||||
verifyCommand.verifyConnect.outgoingSessionID = outgoingSessionID;
|
||||
verifyCommand.verifyConnect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu);
|
||||
verifyCommand.verifyConnect.mtu = ENET_HOST_TO_NET_32 (currentPeer -> mtu);
|
||||
verifyCommand.verifyConnect.windowSize = ENET_HOST_TO_NET_32 (windowSize);
|
||||
verifyCommand.verifyConnect.channelCount = ENET_HOST_TO_NET_32 (channelCount);
|
||||
verifyCommand.verifyConnect.incomingBandwidth = ENET_HOST_TO_NET_32 (host -> incomingBandwidth);
|
||||
@@ -400,7 +412,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),
|
||||
@@ -426,7 +440,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);
|
||||
@@ -474,7 +490,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),
|
||||
@@ -507,7 +525,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];
|
||||
@@ -526,9 +546,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));
|
||||
@@ -569,12 +591,6 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
|
||||
return -1;
|
||||
|
||||
hostCommand.header.reliableSequenceNumber = startSequenceNumber;
|
||||
hostCommand.sendFragment.startSequenceNumber = startSequenceNumber;
|
||||
hostCommand.sendFragment.dataLength = fragmentLength;
|
||||
hostCommand.sendFragment.fragmentNumber = fragmentNumber;
|
||||
hostCommand.sendFragment.fragmentCount = fragmentCount;
|
||||
hostCommand.sendFragment.fragmentOffset = fragmentOffset;
|
||||
hostCommand.sendFragment.totalLength = totalLength;
|
||||
|
||||
startCommand = enet_peer_queue_incoming_command (peer, & hostCommand, packet, fragmentCount);
|
||||
if (startCommand == NULL)
|
||||
@@ -601,6 +617,128 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
enet_protocol_handle_send_unreliable_fragment (ENetHost * host, ENetPeer * peer, const ENetProtocol * command, enet_uint8 ** currentData)
|
||||
{
|
||||
enet_uint32 fragmentNumber,
|
||||
fragmentCount,
|
||||
fragmentOffset,
|
||||
fragmentLength,
|
||||
reliableSequenceNumber,
|
||||
startSequenceNumber,
|
||||
totalLength;
|
||||
enet_uint16 reliableWindow, currentWindow;
|
||||
ENetChannel * channel;
|
||||
ENetListIterator currentCommand;
|
||||
ENetIncomingCommand * startCommand = NULL;
|
||||
|
||||
if (command -> header.channelID >= peer -> channelCount ||
|
||||
(peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER))
|
||||
return -1;
|
||||
|
||||
fragmentLength = ENET_NET_TO_HOST_16 (command -> sendFragment.dataLength);
|
||||
* currentData += fragmentLength;
|
||||
if (fragmentLength > ENET_PROTOCOL_MAXIMUM_PACKET_SIZE ||
|
||||
* currentData < host -> receivedData ||
|
||||
* currentData > & host -> receivedData [host -> receivedDataLength])
|
||||
return -1;
|
||||
|
||||
channel = & peer -> channels [command -> header.channelID];
|
||||
reliableSequenceNumber = command -> header.reliableSequenceNumber;
|
||||
startSequenceNumber = ENET_NET_TO_HOST_16 (command -> sendFragment.startSequenceNumber);
|
||||
|
||||
reliableWindow = reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE;
|
||||
currentWindow = channel -> incomingReliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE;
|
||||
|
||||
if (reliableSequenceNumber < channel -> incomingReliableSequenceNumber)
|
||||
reliableWindow += ENET_PEER_RELIABLE_WINDOWS;
|
||||
|
||||
if (reliableWindow < currentWindow || reliableWindow >= currentWindow + ENET_PEER_FREE_RELIABLE_WINDOWS - 1)
|
||||
return 0;
|
||||
|
||||
if (reliableSequenceNumber == channel -> incomingReliableSequenceNumber &&
|
||||
startSequenceNumber <= channel -> incomingUnreliableSequenceNumber)
|
||||
return 0;
|
||||
|
||||
fragmentNumber = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentNumber);
|
||||
fragmentCount = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentCount);
|
||||
fragmentOffset = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentOffset);
|
||||
totalLength = ENET_NET_TO_HOST_32 (command -> sendFragment.totalLength);
|
||||
|
||||
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));
|
||||
currentCommand != enet_list_end (& channel -> incomingUnreliableCommands);
|
||||
currentCommand = enet_list_previous (currentCommand))
|
||||
{
|
||||
ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand;
|
||||
|
||||
if (reliableSequenceNumber >= channel -> incomingReliableSequenceNumber)
|
||||
{
|
||||
if (incomingCommand -> reliableSequenceNumber < channel -> incomingReliableSequenceNumber)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
if (incomingCommand -> reliableSequenceNumber >= channel -> incomingReliableSequenceNumber)
|
||||
break;
|
||||
|
||||
if (incomingCommand -> reliableSequenceNumber < reliableSequenceNumber)
|
||||
break;
|
||||
|
||||
if (incomingCommand -> reliableSequenceNumber > reliableSequenceNumber)
|
||||
continue;
|
||||
|
||||
if (incomingCommand -> unreliableSequenceNumber <= startSequenceNumber)
|
||||
{
|
||||
if (incomingCommand -> unreliableSequenceNumber < startSequenceNumber)
|
||||
break;
|
||||
|
||||
if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) != ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT ||
|
||||
totalLength != incomingCommand -> packet -> dataLength ||
|
||||
fragmentCount != incomingCommand -> fragmentCount)
|
||||
return -1;
|
||||
|
||||
startCommand = incomingCommand;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (startCommand == NULL)
|
||||
{
|
||||
ENetPacket * packet = enet_packet_create (NULL, totalLength, ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT);
|
||||
if (packet == NULL)
|
||||
return -1;
|
||||
|
||||
startCommand = enet_peer_queue_incoming_command (peer, command, packet, fragmentCount);
|
||||
if (startCommand == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((startCommand -> fragments [fragmentNumber / 32] & (1 << (fragmentNumber % 32))) == 0)
|
||||
{
|
||||
-- startCommand -> fragmentsRemaining;
|
||||
|
||||
startCommand -> fragments [fragmentNumber / 32] |= (1 << (fragmentNumber % 32));
|
||||
|
||||
if (fragmentOffset + fragmentLength > startCommand -> packet -> dataLength)
|
||||
fragmentLength = startCommand -> packet -> dataLength - fragmentOffset;
|
||||
|
||||
memcpy (startCommand -> packet -> data + fragmentOffset,
|
||||
(enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
|
||||
fragmentLength);
|
||||
|
||||
if (startCommand -> fragmentsRemaining <= 0)
|
||||
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
enet_protocol_handle_ping (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
|
||||
{
|
||||
@@ -646,7 +784,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)
|
||||
@@ -745,6 +883,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;
|
||||
@@ -848,7 +989,8 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
|
||||
|
||||
if (peer -> state == ENET_PEER_STATE_DISCONNECTED ||
|
||||
peer -> state == ENET_PEER_STATE_ZOMBIE ||
|
||||
(host -> receivedAddress.host != peer -> address.host &&
|
||||
((host -> receivedAddress.host != peer -> address.host ||
|
||||
host -> receivedAddress.port != peer -> address.port) &&
|
||||
peer -> address.host != ENET_HOST_BROADCAST) ||
|
||||
(peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID &&
|
||||
sessionID != peer -> incomingSessionID))
|
||||
@@ -981,6 +1123,11 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
|
||||
goto commandError;
|
||||
break;
|
||||
|
||||
case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE_FRAGMENT:
|
||||
if (enet_protocol_handle_send_unreliable_fragment (host, peer, command, & currentData))
|
||||
goto commandError;
|
||||
break;
|
||||
|
||||
default:
|
||||
goto commandError;
|
||||
}
|
||||
@@ -1047,7 +1194,25 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
|
||||
|
||||
host -> totalReceivedData += receivedLength;
|
||||
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))
|
||||
{
|
||||
case 1:
|
||||
@@ -1134,7 +1299,7 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
|
||||
buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] ||
|
||||
peer -> mtu - host -> packetSize < commandSize ||
|
||||
(outgoingCommand -> packet != NULL &&
|
||||
peer -> mtu - host -> packetSize < commandSize + outgoingCommand -> packet -> dataLength))
|
||||
peer -> mtu - host -> packetSize < commandSize + outgoingCommand -> fragmentLength))
|
||||
{
|
||||
host -> continueSending = 1;
|
||||
|
||||
@@ -1143,20 +1308,35 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
|
||||
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
|
||||
if (outgoingCommand -> packet != NULL)
|
||||
if (outgoingCommand -> packet != NULL && outgoingCommand -> fragmentOffset == 0)
|
||||
{
|
||||
peer -> packetThrottleCounter += ENET_PEER_PACKET_THROTTLE_COUNTER;
|
||||
peer -> packetThrottleCounter %= ENET_PEER_PACKET_THROTTLE_SCALE;
|
||||
|
||||
if (peer -> packetThrottleCounter > peer -> packetThrottle)
|
||||
{
|
||||
-- outgoingCommand -> packet -> referenceCount;
|
||||
enet_uint16 reliableSequenceNumber = outgoingCommand -> reliableSequenceNumber,
|
||||
unreliableSequenceNumber = outgoingCommand -> unreliableSequenceNumber;
|
||||
for (;;)
|
||||
{
|
||||
-- outgoingCommand -> packet -> referenceCount;
|
||||
|
||||
if (outgoingCommand -> packet -> referenceCount == 0)
|
||||
enet_packet_destroy (outgoingCommand -> packet);
|
||||
if (outgoingCommand -> packet -> referenceCount == 0)
|
||||
enet_packet_destroy (outgoingCommand -> packet);
|
||||
|
||||
enet_list_remove (& outgoingCommand -> outgoingCommandList);
|
||||
enet_free (outgoingCommand);
|
||||
enet_list_remove (& outgoingCommand -> outgoingCommandList);
|
||||
enet_free (outgoingCommand);
|
||||
|
||||
if (currentCommand == enet_list_end (& peer -> outgoingUnreliableCommands))
|
||||
break;
|
||||
|
||||
outgoingCommand = (ENetOutgoingCommand *) currentCommand;
|
||||
if (outgoingCommand -> reliableSequenceNumber != reliableSequenceNumber ||
|
||||
outgoingCommand -> unreliableSequenceNumber != unreliableSequenceNumber)
|
||||
break;
|
||||
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -1175,8 +1355,8 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
|
||||
{
|
||||
++ buffer;
|
||||
|
||||
buffer -> data = outgoingCommand -> packet -> data;
|
||||
buffer -> dataLength = outgoingCommand -> packet -> dataLength;
|
||||
buffer -> data = outgoingCommand -> packet -> data + outgoingCommand -> fragmentOffset;
|
||||
buffer -> dataLength = outgoingCommand -> fragmentLength;
|
||||
|
||||
host -> packetSize += buffer -> dataLength;
|
||||
|
||||
@@ -1222,9 +1402,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);
|
||||
|
||||
@@ -1252,7 +1432,7 @@ enet_protocol_check_timeouts (ENetHost * host, ENetPeer * peer, ENetEvent * even
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
|
||||
{
|
||||
ENetProtocol * command = & host -> commands [host -> commandCount];
|
||||
@@ -1262,6 +1442,7 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
|
||||
ENetChannel *channel;
|
||||
enet_uint16 reliableWindow;
|
||||
size_t commandSize;
|
||||
int windowExceeded = 0, windowWrap = 0, canPing = 1;
|
||||
|
||||
currentCommand = enet_list_begin (& peer -> outgoingReliableCommands);
|
||||
|
||||
@@ -1271,37 +1452,54 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
|
||||
|
||||
channel = outgoingCommand -> command.header.channelID < peer -> channelCount ? & peer -> channels [outgoingCommand -> command.header.channelID] : NULL;
|
||||
reliableWindow = outgoingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE;
|
||||
if (channel != NULL &&
|
||||
outgoingCommand -> sendAttempts < 1 &&
|
||||
! (outgoingCommand -> reliableSequenceNumber % ENET_PEER_RELIABLE_WINDOW_SIZE) &&
|
||||
(channel -> reliableWindows [(reliableWindow + ENET_PEER_RELIABLE_WINDOWS - 1) % ENET_PEER_RELIABLE_WINDOWS] >= ENET_PEER_RELIABLE_WINDOW_SIZE ||
|
||||
channel -> usedReliableWindows & ((((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) << reliableWindow) |
|
||||
(((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) >> (ENET_PEER_RELIABLE_WINDOW_SIZE - reliableWindow)))))
|
||||
break;
|
||||
|
||||
if (channel != NULL)
|
||||
{
|
||||
if (! windowWrap &&
|
||||
outgoingCommand -> sendAttempts < 1 &&
|
||||
! (outgoingCommand -> reliableSequenceNumber % ENET_PEER_RELIABLE_WINDOW_SIZE) &&
|
||||
(channel -> reliableWindows [(reliableWindow + ENET_PEER_RELIABLE_WINDOWS - 1) % ENET_PEER_RELIABLE_WINDOWS] >= ENET_PEER_RELIABLE_WINDOW_SIZE ||
|
||||
channel -> usedReliableWindows & ((((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) << reliableWindow) |
|
||||
(((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) >> (ENET_PEER_RELIABLE_WINDOW_SIZE - reliableWindow)))))
|
||||
windowWrap = 1;
|
||||
if (windowWrap)
|
||||
{
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (outgoingCommand -> packet != NULL)
|
||||
{
|
||||
if (! windowExceeded)
|
||||
{
|
||||
enet_uint32 windowSize = (peer -> packetThrottle * peer -> windowSize) / ENET_PEER_PACKET_THROTTLE_SCALE;
|
||||
|
||||
if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > ENET_MAX (windowSize, peer -> mtu))
|
||||
windowExceeded = 1;
|
||||
}
|
||||
if (windowExceeded)
|
||||
{
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
canPing = 0;
|
||||
|
||||
commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK];
|
||||
if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] ||
|
||||
buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] ||
|
||||
peer -> mtu - host -> packetSize < commandSize)
|
||||
peer -> mtu - host -> packetSize < commandSize ||
|
||||
(outgoingCommand -> packet != NULL &&
|
||||
(enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength)))
|
||||
{
|
||||
host -> continueSending = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (outgoingCommand -> packet != NULL)
|
||||
{
|
||||
if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > peer -> windowSize)
|
||||
break;
|
||||
|
||||
if ((enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength))
|
||||
{
|
||||
host -> continueSending = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
|
||||
if (channel != NULL && outgoingCommand -> sendAttempts < 1)
|
||||
@@ -1315,7 +1513,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))
|
||||
@@ -1354,6 +1552,8 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
|
||||
|
||||
host -> commandCount = command - host -> commands;
|
||||
host -> bufferCount = buffer - host -> buffers;
|
||||
|
||||
return canPing;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1389,13 +1589,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);
|
||||
else
|
||||
if (enet_list_empty (& currentPeer -> sentReliableCommands) &&
|
||||
ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= ENET_PEER_PING_INTERVAL &&
|
||||
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) >= currentPeer -> pingInterval &&
|
||||
currentPeer -> mtu - host -> packetSize >= sizeof (ENetProtocolPing))
|
||||
{
|
||||
enet_peer_ping (currentPeer);
|
||||
|
||||
@@ -18,12 +18,29 @@
|
||||
#define ENET_BUILDING_LIB 1
|
||||
#include "enet/enet.h"
|
||||
|
||||
#ifdef HAS_FCNTL
|
||||
#include <fcntl.h>
|
||||
#ifdef __APPLE__
|
||||
#ifdef HAS_POLL
|
||||
#undef HAS_POLL
|
||||
#endif
|
||||
#ifndef HAS_FCNTL
|
||||
#define HAS_FCNTL 1
|
||||
#endif
|
||||
#ifndef HAS_INET_PTON
|
||||
#define HAS_INET_PTON 1
|
||||
#endif
|
||||
#ifndef HAS_INET_NTOP
|
||||
#define HAS_INET_NTOP 1
|
||||
#endif
|
||||
#ifndef HAS_MSGHDR_FLAGS
|
||||
#define HAS_MSGHDR_FLAGS 1
|
||||
#endif
|
||||
#ifndef HAS_SOCKLEN_T
|
||||
#define HAS_SOCKLEN_T 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#undef HAS_POLL
|
||||
#ifdef HAS_FCNTL
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAS_POLL
|
||||
@@ -219,6 +236,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;
|
||||
}
|
||||
@@ -229,6 +254,7 @@ int
|
||||
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
int result;
|
||||
|
||||
memset (& sin, 0, sizeof (struct sockaddr_in));
|
||||
|
||||
@@ -236,7 +262,11 @@ enet_socket_connect (ENetSocket socket, const ENetAddress * address)
|
||||
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
|
||||
sin.sin_addr.s_addr = address -> host;
|
||||
|
||||
return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
|
||||
result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
|
||||
if (result == -1 && errno == EINPROGRESS)
|
||||
return 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ENetSocket
|
||||
@@ -262,10 +292,17 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
enet_socket_shutdown (ENetSocket socket, ENetSocketShutdown how)
|
||||
{
|
||||
return shutdown (socket, (int) how);
|
||||
}
|
||||
|
||||
void
|
||||
enet_socket_destroy (ENetSocket socket)
|
||||
{
|
||||
close (socket);
|
||||
if (socket != -1)
|
||||
close (socket);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -176,6 +184,7 @@ int
|
||||
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
int result;
|
||||
|
||||
memset (& sin, 0, sizeof (struct sockaddr_in));
|
||||
|
||||
@@ -183,7 +192,11 @@ enet_socket_connect (ENetSocket socket, const ENetAddress * address)
|
||||
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
|
||||
sin.sin_addr.s_addr = address -> host;
|
||||
|
||||
return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
|
||||
result = connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
|
||||
if (result == SOCKET_ERROR && WSAGetLastError () != WSAEWOULDBLOCK)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ENetSocket
|
||||
@@ -209,10 +222,17 @@ enet_socket_accept (ENetSocket socket, ENetAddress * address)
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
enet_socket_shutdown (ENetSocket socket, ENetSocketShutdown how)
|
||||
{
|
||||
return shutdown (socket, (int) how) == SOCKET_ERROR ? -1 : 0;
|
||||
}
|
||||
|
||||
void
|
||||
enet_socket_destroy (ENetSocket socket)
|
||||
{
|
||||
closesocket (socket);
|
||||
if (socket != INVALID_SOCKET)
|
||||
closesocket (socket);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -238,7 +258,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)
|
||||
|
||||
Reference in New Issue
Block a user