Explorar o código

added ENET_PACKET_FLAG_SENT to indicate that a packet has been sent

lsalzman %!s(int64=12) %!d(string=hai) anos
pai
achega
4ce4aac149
Modificáronse 3 ficheiros con 15 adicións e 3 borrados
  1. 1 0
      ChangeLog
  2. 4 1
      include/enet/enet.h
  3. 10 2
      protocol.c

+ 1 - 0
ChangeLog

@@ -1,3 +1,4 @@
+* added ENET_PACKET_FLAG_SENT to indicate that a packet is being freed because it has been sent
 * added userData field to ENetPacket
 * changed how random seed is generated on Windows to avoid import warnings
 * fixed case where disconnects could be generated with no preceding connect event

+ 4 - 1
include/enet/enet.h

@@ -112,7 +112,10 @@ typedef enum _ENetPacketFlag
    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)
+   ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = (1 << 3),
+
+   /** whether the packet has been sent from all queues it has been entered into */
+   ENET_PACKET_FLAG_SENT = (1<<8)
 } ENetPacketFlag;
 
 typedef void (ENET_CALLBACK * ENetPacketFreeCallback) (struct _ENetPacket *);

+ 10 - 2
protocol.c

@@ -163,7 +163,11 @@ enet_protocol_remove_sent_unreliable_commands (ENetPeer * peer)
            -- outgoingCommand -> packet -> referenceCount;
 
            if (outgoingCommand -> packet -> referenceCount == 0)
-             enet_packet_destroy (outgoingCommand -> packet);
+           {
+              outgoingCommand -> packet -> flags |= ENET_PACKET_FLAG_SENT;
+ 
+              enet_packet_destroy (outgoingCommand -> packet);
+           }
         }
 
         enet_free (outgoingCommand);
@@ -237,7 +241,11 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
        -- outgoingCommand -> packet -> referenceCount;
 
        if (outgoingCommand -> packet -> referenceCount == 0)
-         enet_packet_destroy (outgoingCommand -> packet);
+       {
+          outgoingCommand -> packet -> flags |= ENET_PACKET_FLAG_SENT;
+
+          enet_packet_destroy (outgoingCommand -> packet);
+       }
     }
 
     enet_free (outgoingCommand);