aboutsummaryrefslogtreecommitdiffhomepage
path: root/protocol.c
diff options
context:
space:
mode:
authorLee Salzman <[email protected]>2019-01-27 14:46:45 -0500
committerLee Salzman <[email protected]>2019-01-27 14:46:45 -0500
commitb8713bdf88dba9a3e1ac75fc50923b7f23e00115 (patch)
treeb88080b89cc00546e38b20eac740e9e6409f7f39 /protocol.c
parente2ef83927d1626d6ee479742343a3011333fdfdd (diff)
downloadenet-b8713bdf88dba9a3e1ac75fc50923b7f23e00115.tar.gz
enet-b8713bdf88dba9a3e1ac75fc50923b7f23e00115.zip
delay handling of DISCONNECT_LATER until in-flight unreliable packets are sent
Diffstat (limited to 'protocol.c')
-rw-r--r--protocol.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/protocol.c b/protocol.c
index 29d6487..eee7f88 100644
--- a/protocol.c
+++ b/protocol.c
@@ -163,7 +163,10 @@ enet_protocol_remove_sent_unreliable_commands (ENetPeer * peer)
{
ENetOutgoingCommand * outgoingCommand;
- while (! enet_list_empty (& peer -> sentUnreliableCommands))
+ if (enet_list_empty (& peer -> sentUnreliableCommands))
+ return;
+
+ do
{
outgoingCommand = (ENetOutgoingCommand *) enet_list_front (& peer -> sentUnreliableCommands);
@@ -182,7 +185,13 @@ enet_protocol_remove_sent_unreliable_commands (ENetPeer * peer)
}
enet_free (outgoingCommand);
- }
+ } while (! enet_list_empty (& peer -> sentUnreliableCommands));
+
+ if (peer -> state == ENET_PEER_STATE_DISCONNECT_LATER &&
+ enet_list_empty (& peer -> outgoingReliableCommands) &&
+ enet_list_empty (& peer -> outgoingUnreliableCommands) &&
+ enet_list_empty (& peer -> sentReliableCommands))
+ enet_peer_disconnect (peer, peer -> eventData);
}
static ENetProtocolCommand
@@ -1406,7 +1415,8 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
if (peer -> state == ENET_PEER_STATE_DISCONNECT_LATER &&
enet_list_empty (& peer -> outgoingReliableCommands) &&
enet_list_empty (& peer -> outgoingUnreliableCommands) &&
- enet_list_empty (& peer -> sentReliableCommands))
+ enet_list_empty (& peer -> sentReliableCommands) &&
+ enet_list_empty (& peer -> sentUnreliableCommands))
enet_peer_disconnect (peer, peer -> eventData);
}