Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
eihrul committed Jul 6, 2006
1 parent 1e2c45a commit 1d6253c
Show file tree
Hide file tree
Showing 9 changed files with 580 additions and 346 deletions.
16 changes: 14 additions & 2 deletions configure.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_INIT(libenet, 1.0)
AM_INIT_AUTOMAKE(libenet.a, 1.0)
AC_INIT(libenet, 7-6-2006)
AM_INIT_AUTOMAKE(libenet.a, 7-6-2006)

AC_PROG_CC
AC_PROG_RANLIB
Expand All @@ -21,4 +21,16 @@ AC_CHECK_TYPE(socklen_t, [AC_DEFINE(HAS_SOCKLEN_T)], ,
AC_EGREP_HEADER(MSG_MAXIOVLEN, /usr/include/sys/socket.h, AC_DEFINE(ENET_BUFFER_MAXIMUM, [MSG_MAXIOVLEN]))
AC_EGREP_HEADER(MSG_MAXIOVLEN, socket.h, AC_DEFINE(ENET_BUFFER_MAXIMUM, [MSG_MAXIOVLEN]))

AC_MSG_CHECKING(whether to use CRC32)
AC_ARG_ENABLE(crc32,
[ --enable-crc32 enable CRC32 packet verification ],
[if test "$enableval" = yes; then
AC_MSG_RESULT(yes)
AC_DEFINE(USE_CRC32)
else
AC_MSG_RESULT(no)
fi],
[AC_MSG_RESULT(no)])

AC_OUTPUT([Makefile include/Makefile include/enet/Makefile])

26 changes: 13 additions & 13 deletions host.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
ENetHost * host = (ENetHost *) enet_malloc (sizeof (ENetHost));
ENetPeer * currentPeer;

if (peerCount > ENET_PROTOCOL_MAXIMUM_PEER_ID)
return NULL;

host -> peers = (ENetPeer *) enet_malloc (peerCount * sizeof (ENetPeer));
memset (host -> peers, 0, peerCount * sizeof (ENetPeer));

Expand Down Expand Up @@ -135,7 +138,7 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
currentPeer -> address = * address;
currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel));
currentPeer -> channelCount = channelCount;
currentPeer -> challenge = (enet_uint32) enet_rand ();
currentPeer -> sessionID = (enet_uint32) enet_rand ();

if (host -> outgoingBandwidth == 0)
currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
Expand Down Expand Up @@ -163,10 +166,8 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
enet_list_clear (& channel -> incomingUnreliableCommands);
}

command.header.command = ENET_PROTOCOL_COMMAND_CONNECT;
command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
command.header.channelID = 0xFF;
command.header.flags = ENET_PROTOCOL_FLAG_ACKNOWLEDGE;
command.header.commandLength = sizeof (ENetProtocolConnect);
command.connect.outgoingPeerID = ENET_HOST_TO_NET_16 (currentPeer -> incomingPeerID);
command.connect.mtu = ENET_HOST_TO_NET_16 (currentPeer -> mtu);
command.connect.windowSize = ENET_HOST_TO_NET_32 (currentPeer -> windowSize);
Expand All @@ -176,6 +177,7 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
command.connect.packetThrottleInterval = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleInterval);
command.connect.packetThrottleAcceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleAcceleration);
command.connect.packetThrottleDeceleration = ENET_HOST_TO_NET_32 (currentPeer -> packetThrottleDeceleration);
command.connect.sessionID = currentPeer -> sessionID;

enet_peer_queue_outgoing_command (currentPeer, & command, NULL, 0, 0);

Expand Down Expand Up @@ -243,7 +245,7 @@ enet_host_bandwidth_throttle (ENetHost * host)
peer < & host -> peers [host -> peerCount];
++ peer)
{
if (peer -> state != ENET_PEER_STATE_CONNECTED)
if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
continue;

++ peersTotal;
Expand Down Expand Up @@ -276,7 +278,7 @@ enet_host_bandwidth_throttle (ENetHost * host)
{
enet_uint32 peerBandwidth;

if (peer -> state != ENET_PEER_STATE_CONNECTED ||
if ((peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
peer -> incomingBandwidth == 0 ||
peer -> outgoingBandwidthThrottleEpoch == timeCurrent)
continue;
Expand Down Expand Up @@ -309,7 +311,7 @@ enet_host_bandwidth_throttle (ENetHost * host)
peer < & host -> peers [host -> peerCount];
++ peer)
{
if (peer -> state != ENET_PEER_STATE_CONNECTED ||
if ((peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
peer -> outgoingBandwidthThrottleEpoch == timeCurrent)
continue;

Expand Down Expand Up @@ -339,12 +341,12 @@ enet_host_bandwidth_throttle (ENetHost * host)
peer < & host -> peers [host -> peerCount];
++ peer)
{
if (peer -> state != ENET_PEER_STATE_CONNECTED ||
if ((peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
peer -> incomingBandwidthThrottleEpoch == timeCurrent)
continue;

if (peer -> outgoingBandwidth > 0 &&
bandwidthLimit > peer -> outgoingBandwidth)
peer -> outgoingBandwidth >= bandwidthLimit)
continue;

peer -> incomingBandwidthThrottleEpoch = timeCurrent;
Expand All @@ -359,13 +361,11 @@ enet_host_bandwidth_throttle (ENetHost * host)
peer < & host -> peers [host -> peerCount];
++ peer)
{
if (peer -> state != ENET_PEER_STATE_CONNECTED)
if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
continue;

command.header.command = ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT;
command.header.command = ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
command.header.channelID = 0xFF;
command.header.flags = ENET_PROTOCOL_FLAG_ACKNOWLEDGE;
command.header.commandLength = sizeof (ENetProtocolBandwidthLimit);
command.bandwidthLimit.outgoingBandwidth = ENET_HOST_TO_NET_32 (host -> outgoingBandwidth);

if (peer -> incomingBandwidthThrottleEpoch == timeCurrent)
Expand Down
74 changes: 42 additions & 32 deletions include/enet/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ typedef enum
/** packet will not be sequenced with other packets
* not supported for reliable packets
*/
ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1)
ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1),
/** packet will not allocate data, and user must supply it instead */
ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2)
} ENetPacketFlag;

/**
Expand Down Expand Up @@ -115,8 +117,8 @@ typedef struct _ENetAcknowledgement
typedef struct _ENetOutgoingCommand
{
ENetListNode outgoingCommandList;
enet_uint32 reliableSequenceNumber;
enet_uint32 unreliableSequenceNumber;
enet_uint16 reliableSequenceNumber;
enet_uint16 unreliableSequenceNumber;
enet_uint32 sentTime;
enet_uint32 roundTripTimeout;
enet_uint32 roundTripTimeoutLimit;
Expand All @@ -129,8 +131,8 @@ typedef struct _ENetOutgoingCommand
typedef struct _ENetIncomingCommand
{
ENetListNode incomingCommandList;
enet_uint32 reliableSequenceNumber;
enet_uint32 unreliableSequenceNumber;
enet_uint16 reliableSequenceNumber;
enet_uint16 unreliableSequenceNumber;
ENetProtocol command;
enet_uint32 fragmentCount;
enet_uint32 fragmentsRemaining;
Expand All @@ -144,10 +146,12 @@ typedef enum
ENET_PEER_STATE_CONNECTING = 1,
ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2,
ENET_PEER_STATE_CONNECTION_PENDING = 3,
ENET_PEER_STATE_CONNECTED = 4,
ENET_PEER_STATE_DISCONNECTING = 5,
ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 6,
ENET_PEER_STATE_ZOMBIE = 7
ENET_PEER_STATE_CONNECTION_SUCCEEDED = 4,
ENET_PEER_STATE_CONNECTED = 5,
ENET_PEER_STATE_DISCONNECT_LATER = 6,
ENET_PEER_STATE_DISCONNECTING = 7,
ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 8,
ENET_PEER_STATE_ZOMBIE = 9
} ENetPeerState;

#ifndef ENET_BUFFER_MAXIMUM
Expand All @@ -157,6 +161,7 @@ typedef enum
enum
{
ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024,
ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024,
ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000,
ENET_HOST_DEFAULT_MTU = 1400,

Expand Down Expand Up @@ -197,7 +202,7 @@ typedef struct _ENetPeer
struct _ENetHost * host;
enet_uint16 outgoingPeerID;
enet_uint16 incomingPeerID;
enet_uint32 challenge;
enet_uint32 sessionID;
ENetAddress address; /**< Internet address of the peer */
void * data; /**< Application private data, may be freely modified */
ENetPeerState state;
Expand Down Expand Up @@ -234,14 +239,14 @@ typedef struct _ENetPeer
enet_uint16 mtu;
enet_uint32 windowSize;
enet_uint32 reliableDataInTransit;
enet_uint32 outgoingReliableSequenceNumber;
enet_uint16 outgoingReliableSequenceNumber;
ENetList acknowledgements;
ENetList sentReliableCommands;
ENetList sentUnreliableCommands;
ENetList outgoingReliableCommands;
ENetList outgoingUnreliableCommands;
enet_uint32 incomingUnsequencedGroup;
enet_uint32 outgoingUnsequencedGroup;
enet_uint16 incomingUnsequencedGroup;
enet_uint16 outgoingUnsequencedGroup;
enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
enet_uint32 disconnectData;
} ENetPeer;
Expand Down Expand Up @@ -271,7 +276,9 @@ typedef struct _ENetHost
ENetPeer * peers; /**< array of peers allocated for this host */
size_t peerCount; /**< number of peers allocated for this host */
ENetPeer * lastServicedPeer;
int continueSending;
size_t packetSize;
enet_uint16 headerFlags;
ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
size_t commandCount;
ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
Expand Down Expand Up @@ -337,7 +344,7 @@ typedef struct _ENetEvent
*/
ENET_API int enet_initialize (void);

ENET_API int enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits);
ENET_API int enet_initialize_with_callbacks (ENetVersion, const ENetCallbacks *);

/**
Shuts down ENet globally. Should be called when a program that has
Expand All @@ -361,15 +368,14 @@ ENET_API void enet_time_set (enet_uint32);

/** @defgroup socket ENet socket functions
@{
@ingroup private
*/
extern ENetSocket enet_socket_create (ENetSocketType, const ENetAddress *);
extern ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
extern int enet_socket_connect (ENetSocket, const ENetAddress *);
extern int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
extern int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
extern int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
extern void enet_socket_destroy (ENetSocket);
ENET_API ENetSocket enet_socket_create (ENetSocketType, const ENetAddress *);
ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *);
ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
ENET_API void enet_socket_destroy (ENetSocket);

/** @} */

Expand All @@ -384,7 +390,7 @@ extern void enet_socket_destroy (ENetSocket);
@retval < 0 on failure
@returns the address of the given hostName in address on success
*/
ENET_API int enet_address_set_host (ENetAddress *address, const char *hostName );
ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName);

/** Attempts to do a reserve lookup of the host field in the address parameter.
@param address address used for reverse lookup
Expand All @@ -394,17 +400,18 @@ ENET_API int enet_address_set_host (ENetAddress *address, const char *hostName )
@retval 0 on success
@retval < 0 on failure
*/
ENET_API int enet_address_get_host (const ENetAddress *address, char *hostName, size_t nameLength );
ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength);

/** @} */

ENET_API ENetPacket * enet_packet_create (const void *dataContents, size_t dataLength, enet_uint32 flags);
ENET_API void enet_packet_destroy (ENetPacket *packet );
ENET_API int enet_packet_resize (ENetPacket *packet, size_t dataLength );

ENET_API ENetHost * enet_host_create (const ENetAddress *address, size_t peerCount, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth );
ENET_API void enet_host_destroy (ENetHost *host );
ENET_API ENetPeer * enet_host_connect (ENetHost *host, const ENetAddress *address, size_t channelCount );
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 ENetHost * enet_host_create (const ENetAddress *, size_t, enet_uint32, enet_uint32);
ENET_API void enet_host_destroy (ENetHost *);
ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t);
ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32);
ENET_API void enet_host_flush (ENetHost *);
ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *);
Expand All @@ -417,12 +424,15 @@ ENET_API void enet_peer_ping (ENetPeer *);
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);
ENET_API void enet_peer_disconnect_later (ENetPeer *, enet_uint32);
ENET_API void enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
extern int enet_peer_throttle (ENetPeer *, enet_uint32);
extern void enet_peer_reset_queues (ENetPeer *);
extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32);
extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint32);
extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16);

extern size_t enet_protocol_command_size (enet_uint8);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 1d6253c

Please sign in to comment.