mirror of
https://github.com/DrBeef/Raze.git
synced 2025-02-20 18:52:43 +00:00
Update ENet with the latest changes from github
git-svn-id: https://svn.eduke32.com/eduke32@3036 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
ead8204e1e
commit
6019e86010
7 changed files with 171 additions and 23 deletions
|
@ -29,7 +29,7 @@ extern "C"
|
|||
|
||||
#define ENET_VERSION_MAJOR 1
|
||||
#define ENET_VERSION_MINOR 3
|
||||
#define ENET_VERSION_PATCH 3
|
||||
#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)
|
||||
|
||||
|
@ -59,6 +59,13 @@ typedef enum _ENetSocketOption
|
|||
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 */
|
||||
|
@ -273,6 +280,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;
|
||||
|
@ -460,6 +471,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);
|
||||
|
||||
|
@ -521,6 +533,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,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"
|
||||
|
@ -134,6 +135,9 @@ enet_host_destroy (ENetHost * host)
|
|||
{
|
||||
ENetPeer * currentPeer;
|
||||
|
||||
if (host == NULL)
|
||||
return;
|
||||
|
||||
enet_socket_destroy (host -> socket);
|
||||
|
||||
for (currentPeer = host -> peers;
|
||||
|
|
|
@ -55,6 +55,9 @@ 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) &&
|
||||
|
|
|
@ -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
|
||||
|
@ -374,6 +374,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;
|
||||
|
@ -414,6 +418,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
|
||||
|
@ -636,17 +680,45 @@ 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 -> 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 (startCommand == currentCommand)
|
||||
startCommand = enet_list_next (currentCommand);
|
||||
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)
|
||||
|
@ -655,11 +727,12 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
|
|||
|
||||
peer -> needsDispatch = 1;
|
||||
}
|
||||
|
||||
droppedCommand = startCommand = enet_list_next (currentCommand);
|
||||
}
|
||||
}
|
||||
|
||||
startCommand = enet_list_next (currentCommand);
|
||||
}
|
||||
|
||||
if (startCommand != currentCommand)
|
||||
{
|
||||
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
|
||||
|
@ -671,7 +744,7 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
|
|||
peer -> needsDispatch = 1;
|
||||
}
|
||||
|
||||
droppedCommand = startCommand = enet_list_next (currentCommand);
|
||||
droppedCommand = currentCommand;
|
||||
}
|
||||
|
||||
enet_peer_remove_incoming_commands (& channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand);
|
||||
|
@ -712,6 +785,7 @@ enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * ch
|
|||
peer -> needsDispatch = 1;
|
||||
}
|
||||
|
||||
if (! enet_list_empty (& channel -> incomingUnreliableCommands))
|
||||
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,8 +83,9 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event)
|
|||
}
|
||||
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,6 +210,9 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
|
|||
wasSent = 0;
|
||||
}
|
||||
|
||||
if (outgoingCommand == NULL)
|
||||
return ENET_PROTOCOL_COMMAND_NONE;
|
||||
|
||||
if (channelID < peer -> channelCount)
|
||||
{
|
||||
ENetChannel * channel = & peer -> channels [channelID];
|
||||
|
@ -383,7 +387,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);
|
||||
|
@ -888,6 +892,8 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
|
|||
enet_list_empty (& peer -> outgoingUnreliableCommands) &&
|
||||
enet_list_empty (& peer -> sentReliableCommands))
|
||||
enet_peer_disconnect (peer, peer -> eventData);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1388,9 +1394,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);
|
||||
|
||||
|
@ -1499,7 +1505,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))
|
||||
|
@ -1585,7 +1591,7 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
|
|||
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);
|
||||
|
|
|
@ -46,18 +46,41 @@ struct msghdr {
|
|||
#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
|
||||
#include <sys/poll.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef HAS_SOCKLEN_T
|
||||
typedef int socklen_t;
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
|
@ -261,6 +284,7 @@ int
|
|||
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
int result;
|
||||
|
||||
memset (& sin, 0, sizeof (struct sockaddr_in));
|
||||
|
||||
|
@ -268,7 +292,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
|
||||
|
@ -294,9 +322,16 @@ 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)
|
||||
{
|
||||
if (socket != -1)
|
||||
close (socket);
|
||||
}
|
||||
|
||||
|
|
|
@ -184,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));
|
||||
|
||||
|
@ -191,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
|
||||
|
@ -217,9 +222,16 @@ 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)
|
||||
{
|
||||
if (socket != INVALID_SOCKET)
|
||||
closesocket (socket);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue