Browse Source

*** empty log message ***

eihrul 17 years ago
parent
commit
870779bfb0
4 changed files with 46 additions and 8 deletions
  1. 3 0
      host.c
  2. 6 1
      include/enet/enet.h
  3. 4 0
      peer.c
  4. 33 7
      protocol.c

+ 3 - 0
host.c

@@ -169,6 +169,9 @@ enet_host_connect (ENetHost * host, const ENetAddress * address, size_t channelC
 
 
         enet_list_clear (& channel -> incomingReliableCommands);
         enet_list_clear (& channel -> incomingReliableCommands);
         enet_list_clear (& channel -> incomingUnreliableCommands);
         enet_list_clear (& channel -> incomingUnreliableCommands);
+
+        channel -> currentReliableWindow = 0;
+        memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows));
     }
     }
         
         
     command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
     command.header.command = ENET_PROTOCOL_COMMAND_CONNECT | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;

+ 6 - 1
include/enet/enet.h

@@ -143,6 +143,7 @@ typedef struct _ENetOutgoingCommand
    enet_uint32  roundTripTimeoutLimit;
    enet_uint32  roundTripTimeoutLimit;
    enet_uint32  fragmentOffset;
    enet_uint32  fragmentOffset;
    enet_uint16  fragmentLength;
    enet_uint16  fragmentLength;
+   enet_uint16  sendAttempts;
    ENetProtocol command;
    ENetProtocol command;
    ENetPacket * packet;
    ENetPacket * packet;
 } ENetOutgoingCommand;
 } ENetOutgoingCommand;
@@ -198,7 +199,9 @@ enum
    ENET_PEER_TIMEOUT_MINIMUM              = 5000,
    ENET_PEER_TIMEOUT_MINIMUM              = 5000,
    ENET_PEER_TIMEOUT_MAXIMUM              = 30000,
    ENET_PEER_TIMEOUT_MAXIMUM              = 30000,
    ENET_PEER_PING_INTERVAL                = 500,
    ENET_PEER_PING_INTERVAL                = 500,
-   ENET_PEER_UNSEQUENCED_WINDOW_SIZE      = 4 * 32
+   ENET_PEER_UNSEQUENCED_WINDOW_SIZE      = 4 * 32,
+   ENET_PEER_RELIABLE_WINDOWS             = 16,
+   ENET_PEER_RELIABLE_WINDOW_SIZE         = 0x1000
 };
 };
 
 
 typedef struct _ENetChannel
 typedef struct _ENetChannel
@@ -209,6 +212,8 @@ typedef struct _ENetChannel
    enet_uint16  incomingUnreliableSequenceNumber;
    enet_uint16  incomingUnreliableSequenceNumber;
    ENetList     incomingReliableCommands;
    ENetList     incomingReliableCommands;
    ENetList     incomingUnreliableCommands;
    ENetList     incomingUnreliableCommands;
+   enet_uint16  currentReliableWindow;
+   enet_uint16  reliableWindows [ENET_PEER_RELIABLE_WINDOWS];
 } ENetChannel;
 } ENetChannel;
 
 
 /**
 /**

+ 4 - 0
peer.c

@@ -145,6 +145,9 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
 
 
    command.header.channelID = channelID;
    command.header.channelID = channelID;
 
 
+   if (! (packet -> flags & (ENET_PACKET_FLAG_RELIABLE | ENET_PACKET_FLAG_UNSEQUENCED)) && channel -> outgoingUnreliableSequenceNumber >= 0xFFFF)
+     packet -> flags |= ENET_PACKET_FLAG_RELIABLE;
+
    if (packet -> flags & ENET_PACKET_FLAG_RELIABLE)
    if (packet -> flags & ENET_PACKET_FLAG_RELIABLE)
    {
    {
       command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
       command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE | ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE;
@@ -525,6 +528,7 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
        outgoingCommand -> unreliableSequenceNumber = channel -> outgoingUnreliableSequenceNumber;
        outgoingCommand -> unreliableSequenceNumber = channel -> outgoingUnreliableSequenceNumber;
     }
     }
    
    
+    outgoingCommand -> sendAttempts = 0;
     outgoingCommand -> sentTime = 0;
     outgoingCommand -> sentTime = 0;
     outgoingCommand -> roundTripTimeout = 0;
     outgoingCommand -> roundTripTimeout = 0;
     outgoingCommand -> roundTripTimeoutLimit = 0;
     outgoingCommand -> roundTripTimeoutLimit = 0;

+ 33 - 7
protocol.c

@@ -163,6 +163,8 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
     ENetOutgoingCommand * outgoingCommand;
     ENetOutgoingCommand * outgoingCommand;
     ENetListIterator currentCommand;
     ENetListIterator currentCommand;
     ENetProtocolCommand commandNumber;
     ENetProtocolCommand commandNumber;
+    ENetChannel * channel;
+    enet_uint16 reliableWindow;
 
 
     for (currentCommand = enet_list_begin (& peer -> sentReliableCommands);
     for (currentCommand = enet_list_begin (& peer -> sentReliableCommands);
          currentCommand != enet_list_end (& peer -> sentReliableCommands);
          currentCommand != enet_list_end (& peer -> sentReliableCommands);
@@ -178,8 +180,13 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl
     if (currentCommand == enet_list_end (& peer -> sentReliableCommands))
     if (currentCommand == enet_list_end (& peer -> sentReliableCommands))
       return ENET_PROTOCOL_COMMAND_NONE;
       return ENET_PROTOCOL_COMMAND_NONE;
 
 
-    commandNumber = outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK;
+    reliableWindow = reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE;
+    channel = & peer -> channels [channelID];
+    if (channel -> reliableWindows [reliableWindow] > 0)
+      -- channel -> reliableWindows [reliableWindow];
 
 
+    commandNumber = outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK;
+    
     enet_list_remove (& outgoingCommand -> outgoingCommandList);
     enet_list_remove (& outgoingCommand -> outgoingCommandList);
 
 
     if (outgoingCommand -> packet != NULL)
     if (outgoingCommand -> packet != NULL)
@@ -284,6 +291,9 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
 
 
         enet_list_clear (& channel -> incomingReliableCommands);
         enet_list_clear (& channel -> incomingReliableCommands);
         enet_list_clear (& channel -> incomingUnreliableCommands);
         enet_list_clear (& channel -> incomingUnreliableCommands);
+
+        channel -> currentReliableWindow = 0;
+        memset (channel -> reliableWindows, 0, sizeof (channel -> reliableWindows));
     }
     }
 
 
     mtu = ENET_NET_TO_HOST_16 (command -> connect.mtu);
     mtu = ENET_NET_TO_HOST_16 (command -> connect.mtu);
@@ -1146,16 +1156,24 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
     ENetBuffer * buffer = & host -> buffers [host -> bufferCount];
     ENetBuffer * buffer = & host -> buffers [host -> bufferCount];
     ENetOutgoingCommand * outgoingCommand;
     ENetOutgoingCommand * outgoingCommand;
     ENetListIterator currentCommand;
     ENetListIterator currentCommand;
+    ENetChannel *channel;
+    enet_uint16 reliableWindow;
+    size_t commandSize;
 
 
     currentCommand = enet_list_begin (& peer -> outgoingReliableCommands);
     currentCommand = enet_list_begin (& peer -> outgoingReliableCommands);
     
     
     while (currentCommand != enet_list_end (& peer -> outgoingReliableCommands))
     while (currentCommand != enet_list_end (& peer -> outgoingReliableCommands))
     {
     {
-       size_t commandSize;
-
        outgoingCommand = (ENetOutgoingCommand *) currentCommand;
        outgoingCommand = (ENetOutgoingCommand *) currentCommand;
+
+       channel = outgoingCommand -> command.header.channelID < peer -> channelCount ? & peer -> channels [outgoingCommand -> command.header.channelID] : NULL;
+       reliableWindow = outgoingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE;
+       if (channel != NULL && outgoingCommand -> sendAttempts < 1 && 
+           channel -> currentReliableWindow != reliableWindow && 
+           channel -> reliableWindows [reliableWindow] > 0)
+         break;
+  
        commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK];
        commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK];
-    
        if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] ||
        if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] ||
            buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] ||
            buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] ||
            peer -> mtu - host -> packetSize < commandSize)
            peer -> mtu - host -> packetSize < commandSize)
@@ -1165,8 +1183,6 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
           break;
           break;
        }
        }
 
 
-       currentCommand = enet_list_next (currentCommand);
-
        if (outgoingCommand -> packet != NULL)
        if (outgoingCommand -> packet != NULL)
        {
        {
           if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > peer -> windowSize)
           if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > peer -> windowSize)
@@ -1179,7 +1195,17 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer)
              break;
              break;
           }
           }
        }
        }
-       
+      
+       currentCommand = enet_list_next (currentCommand);
+
+       if (channel != NULL && outgoingCommand -> sendAttempts < 1)
+       {
+          if (channel -> currentReliableWindow != reliableWindow) channel -> currentReliableWindow = reliableWindow;
+          ++ channel -> reliableWindows [reliableWindow];
+       }
+
+       ++ outgoingCommand -> sendAttempts;
+ 
        if (outgoingCommand -> roundTripTimeout == 0)
        if (outgoingCommand -> roundTripTimeout == 0)
        {
        {
           outgoingCommand -> roundTripTimeout = peer -> roundTripTime + 4 * peer -> roundTripTimeVariance;
           outgoingCommand -> roundTripTimeout = peer -> roundTripTime + 4 * peer -> roundTripTimeVariance;