Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mman committed Aug 13, 2024
2 parents 65e752f + 1e80a78 commit e22bc43
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
10 changes: 10 additions & 0 deletions include/enet/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ typedef struct _ENetCallbacks
void (ENET_CALLBACK * no_memory) (void);
} ENetCallbacks;

#ifdef __cplusplus
extern "C"
{
#endif

/** @defgroup callbacks ENet internal callbacks
@{
@ingroup private
*/

extern void * enet_malloc (size_t);
extern void enet_free (void *);

/** @} */

#ifdef __cplusplus
}
#endif

#endif /* __ENET_CALLBACKS_H__ */

11 changes: 5 additions & 6 deletions include/enet/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
#ifndef __ENET_ENET_H__
#define __ENET_ENET_H__

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdlib.h>

#ifdef _WIN32
Expand Down Expand Up @@ -115,7 +110,6 @@ typedef enum _ENetPacketFlag
* made until the packet is delivered */
ENET_PACKET_FLAG_RELIABLE = (1 << 0),
/** packet will not be sequenced with other packets
* not supported for reliable packets
*/
ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1),
/** packet will not allocate data, and user must supply it instead */
Expand Down Expand Up @@ -480,6 +474,11 @@ typedef struct _ENetEvent
ENetPacket * packet; /**< packet associated with the event, if appropriate */
} ENetEvent;

#ifdef __cplusplus
extern "C"
{
#endif

/** @defgroup global ENet global functions
@{
*/
Expand Down
9 changes: 9 additions & 0 deletions include/enet/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ typedef struct _ENetList
ENetListNode sentinel;
} ENetList;

#ifdef __cplusplus
extern "C"
{
#endif

extern void enet_list_clear (ENetList *);

extern ENetListIterator enet_list_insert (ENetListIterator, void *);
Expand All @@ -28,6 +33,10 @@ extern ENetListIterator enet_list_move (ENetListIterator, void *, void *);

extern size_t enet_list_size (ENetList *);

#ifdef __cplusplus
}
#endif

#define enet_list_begin(list) ((list) -> sentinel.next)
#define enet_list_end(list) (& (list) -> sentinel)

Expand Down
4 changes: 4 additions & 0 deletions include/enet/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
#pragma warning (disable: 4244) // 64bit to 32bit int
#pragma warning (disable: 4018) // signed/unsigned mismatch
#pragma warning (disable: 4146) // unary minus operator applied to unsigned type
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#endif
#endif

#include <stdlib.h>
#include <winsock2.h>
Expand Down
11 changes: 8 additions & 3 deletions packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ enet_packet_resize (ENetPacket * packet, size_t dataLength)
if (newData == NULL)
return -1;

memcpy (newData, packet -> data, packet -> dataLength);
enet_free (packet -> data);

if (packet -> data != NULL)
{
if (packet -> dataLength > 0)
memcpy (newData, packet -> data, packet -> dataLength);

enet_free (packet -> data);
}

packet -> data = newData;
packet -> dataLength = dataLength;

Expand Down
27 changes: 15 additions & 12 deletions peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
#include <string.h>
#define ENET_BUILDING_LIB 1
#include "enet/utility.h"
#include "enet/enet.h"

/** @defgroup peer ENet peer functions
Expand Down Expand Up @@ -249,13 +250,13 @@ enet_peer_receive (ENetPeer * peer, enet_uint8 * channelID)

enet_free (incomingCommand);

peer -> totalWaitingData -= packet -> dataLength;
peer -> totalWaitingData -= ENET_MIN (peer -> totalWaitingData, packet -> dataLength);

return packet;
}

static void
enet_peer_reset_outgoing_commands (ENetList * queue)
enet_peer_reset_outgoing_commands (ENetPeer * peer, ENetList * queue)
{
ENetOutgoingCommand * outgoingCommand;

Expand All @@ -276,7 +277,7 @@ enet_peer_reset_outgoing_commands (ENetList * queue)
}

static void
enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand, ENetIncomingCommand * excludeCommand)
enet_peer_remove_incoming_commands (ENetPeer * peer, ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand, ENetIncomingCommand * excludeCommand)
{
ENetListIterator currentCommand;

Expand All @@ -295,6 +296,8 @@ enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startComm
{
-- incomingCommand -> packet -> referenceCount;

peer -> totalWaitingData -= ENET_MIN (peer -> totalWaitingData, incomingCommand -> packet -> dataLength);

if (incomingCommand -> packet -> referenceCount == 0)
enet_packet_destroy (incomingCommand -> packet);
}
Expand All @@ -307,9 +310,9 @@ enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startComm
}

static void
enet_peer_reset_incoming_commands (ENetList * queue)
enet_peer_reset_incoming_commands (ENetPeer * peer, ENetList * queue)
{
enet_peer_remove_incoming_commands(queue, enet_list_begin (queue), enet_list_end (queue), NULL);
enet_peer_remove_incoming_commands(peer, queue, enet_list_begin (queue), enet_list_end (queue), NULL);
}

void
Expand All @@ -327,19 +330,19 @@ enet_peer_reset_queues (ENetPeer * peer)
while (! enet_list_empty (& peer -> acknowledgements))
enet_free (enet_list_remove (enet_list_begin (& peer -> acknowledgements)));

enet_peer_reset_outgoing_commands (& peer -> sentReliableCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingSendReliableCommands);
enet_peer_reset_incoming_commands (& peer -> dispatchedCommands);
enet_peer_reset_outgoing_commands (peer, & peer -> sentReliableCommands);
enet_peer_reset_outgoing_commands (peer, & peer -> outgoingCommands);
enet_peer_reset_outgoing_commands (peer, & peer -> outgoingSendReliableCommands);
enet_peer_reset_incoming_commands (peer, & peer -> dispatchedCommands);

if (peer -> channels != NULL && peer -> channelCount > 0)
{
for (channel = peer -> channels;
channel < & peer -> channels [peer -> channelCount];
++ channel)
{
enet_peer_reset_incoming_commands (& channel -> incomingReliableCommands);
enet_peer_reset_incoming_commands (& channel -> incomingUnreliableCommands);
enet_peer_reset_incoming_commands (peer, & channel -> incomingReliableCommands);
enet_peer_reset_incoming_commands (peer, & channel -> incomingUnreliableCommands);
}

enet_free (peer -> channels);
Expand Down Expand Up @@ -808,7 +811,7 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
droppedCommand = currentCommand;
}

enet_peer_remove_incoming_commands (& channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand, queuedCommand);
enet_peer_remove_incoming_commands (peer, & channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand, queuedCommand);
}

void
Expand Down

0 comments on commit e22bc43

Please sign in to comment.