[enet-cvs] CVS: enet Makefile.am, 1.2, 1.3 configure.in, 1.2, 1.3 enet.dsp, 1.5, 1.6 host.c, 1.14, 1.15 packet.c, 1.6, 1.7 peer.c, 1.21, 1.22 protocol.c, 1.36, 1.37 unix.c, 1.11, 1.12 win32.c, 1.10, 1.11

Lee Salzman enet at sferik.cubik.org
Mon Mar 29 13:43:18 PST 2004


Update of /home/enet/cvsroot/enet
In directory sferik:/tmp/cvs-serv2339

Modified Files:
	Makefile.am configure.in enet.dsp host.c packet.c peer.c 
	protocol.c unix.c win32.c 
Log Message:
grab bag of fixes and updates for impending 1.0


Index: Makefile.am
===================================================================
RCS file: /home/enet/cvsroot/enet/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Makefile.am	2003/11/03 16:12:15	1.2
+++ Makefile.am	2004/03/29 21:43:14	1.3
@@ -1,5 +1,5 @@
 lib_LIBRARIES = libenet.a
-libenet_a_SOURCES = host.c list.c memory.c packet.c peer.c protocol.c unix.c win32.c
+libenet_a_SOURCES = host.c list.c callbacks.c packet.c peer.c protocol.c unix.c win32.c
 INCLUDES = -Iinclude/
 
 SUBDIRS = include

Index: configure.in
===================================================================
RCS file: /home/enet/cvsroot/enet/configure.in,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- configure.in	2003/11/03 16:12:15	1.2
+++ configure.in	2004/03/29 21:43:14	1.3
@@ -11,6 +11,11 @@
 
 AC_CHECK_MEMBER(struct msghdr.msg_flags, [AC_DEFINE(HAS_MSGHDR_FLAGS)], , [#include <sys/socket.h>])
 
+AC_CHECK_TYPE(socklen_t, [AC_DEFINE(HAS_SOCKLEN_T)], , 
+              #include <sys/types.h>
+              #include <sys/socket.h>
+)
+
 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]))
 

Index: enet.dsp
===================================================================
RCS file: /home/enet/cvsroot/enet/enet.dsp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- enet.dsp	2003/12/17 20:03:50	1.5
+++ enet.dsp	2004/03/29 21:43:14	1.6
@@ -97,7 +97,7 @@
 # End Source File
 # Begin Source File
 
-SOURCE=.\memory.c
+SOURCE=.\callbacks.c
 # End Source File
 # Begin Source File
 
@@ -133,7 +133,7 @@
 # End Source File
 # Begin Source File
 
-SOURCE=.\include\enet\memory.h
+SOURCE=.\include\enet\callbacks.h
 # End Source File
 # Begin Source File
 

Index: host.c
===================================================================
RCS file: /home/enet/cvsroot/enet/host.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- host.c	2003/11/16 18:18:24	1.14
+++ host.c	2004/03/29 21:43:14	1.15
@@ -3,7 +3,6 @@
  @brief ENet host management functions
 */
 #define ENET_BUILDING_LIB 1
-#include "enet/memory.h"
 #include "enet/enet.h"
 
 /** @defgroup host ENet host functions
@@ -30,7 +29,8 @@
     ENetHost * host = (ENetHost *) enet_malloc (sizeof (ENetHost));
     ENetPeer * currentPeer;
 
-    host -> peers = (ENetPeer *) enet_calloc (peerCount, sizeof (ENetPeer));
+    host -> peers = (ENetPeer *) enet_malloc (peerCount * sizeof (ENetPeer))
+    memset (host -> peers, 0, peerCount * sizeof (ENetPeer));
 
     host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM, address);
     if (host -> socket == ENET_SOCKET_NULL)
@@ -134,7 +134,7 @@
     currentPeer -> address = * address;
     currentPeer -> channels = (ENetChannel *) enet_malloc (channelCount * sizeof (ENetChannel));
     currentPeer -> channelCount = channelCount;
-    currentPeer -> challenge = (enet_uint32) rand ();
+    currentPeer -> challenge = (enet_uint32) enet_rand ();
 
     if (host -> outgoingBandwidth == 0)
       currentPeer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
@@ -363,7 +363,7 @@
 
            command.header.command = ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT;
            command.header.channelID = 0xFF;
-           command.header.flags = 0;
+           command.header.flags = ENET_PROTOCOL_FLAG_ACKNOWLEDGE;
            command.header.commandLength = sizeof (ENetProtocolBandwidthLimit);
            command.bandwidthLimit.outgoingBandwidth = ENET_HOST_TO_NET_32 (host -> outgoingBandwidth);
 

Index: packet.c
===================================================================
RCS file: /home/enet/cvsroot/enet/packet.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- packet.c	2003/10/30 15:55:31	1.6
+++ packet.c	2004/03/29 21:43:14	1.7
@@ -4,7 +4,6 @@
 */
 #include <string.h>
 #define ENET_BUILDING_LIB 1
-#include "enet/memory.h"
 #include "enet/enet.h"
 
 /** @defgroup Packet ENet packet functions 
@@ -62,8 +61,10 @@
        return 0;
     }
 
-    newData = (enet_uint8 *) enet_realloc (packet -> data, dataLength);
-
+    newData = (enet_uint8 *) enet_malloc (dataLength);
+    memcpy (newData, packet -> data, packet -> dataLength);
+    free (packet -> data);
+    
     packet -> data = newData;
     packet -> dataLength = dataLength;
 

Index: peer.c
===================================================================
RCS file: /home/enet/cvsroot/enet/peer.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- peer.c	2003/12/22 03:26:41	1.21
+++ peer.c	2004/03/29 21:43:14	1.22
@@ -3,7 +3,6 @@
  @brief ENet peer management functions
 */
 #define ENET_BUILDING_LIB 1
-#include "enet/memory.h"
 #include "enet/enet.h"
 
 /** @defgroup peer ENet peer functions 
@@ -50,7 +49,7 @@
 
     command.header.command = ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE;
     command.header.channelID = 0xFF;
-    command.header.flags = 0;
+    command.header.flags = ENET_PROTOCOL_FLAG_ACKNOWLEDGE;
     command.header.commandLength = sizeof (ENetProtocolThrottleConfigure);
 
     command.throttleConfigure.packetThrottleInterval = ENET_HOST_TO_NET_32 (interval);
@@ -105,7 +104,8 @@
    ENetProtocol command;
    size_t fragmentLength;
 
-   if (peer -> state != ENET_PEER_STATE_CONNECTED)
+   if (peer -> state != ENET_PEER_STATE_CONNECTED ||
+       channelID >= peer -> channelCount)
      return -1;
 
    fragmentLength = peer -> mtu - sizeof (ENetProtocolHeader) - sizeof (ENetProtocolSendFragment);
@@ -117,7 +117,7 @@
              fragmentNumber,
              fragmentOffset;
 
-      packet -> flags |= ENET_PACKET_FLAG_RELIABLE;
+      packet -> flags = ENET_PACKET_FLAG_RELIABLE;
 
       for (fragmentNumber = 0,
              fragmentOffset = 0;
@@ -153,6 +153,14 @@
       command.header.commandLength = sizeof (ENetProtocolSendReliable);
    }
    else
+   if (packet -> flags & ENET_PACKET_FLAG_UNSEQUENCED)
+   {
+      command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED;
+      command.header.flags = ENET_PROTOCOL_FLAG_UNSEQUENCED;
+      command.header.commandLength = sizeof (ENetProtocolSendUnsequenced);
+      command.sendUnsequenced.unsequencedGroup = ENET_HOST_TO_NET_32 (peer -> outgoingUnsequencedGroup + 1);
+   }
+   else
    {
       command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE;
       command.header.flags = 0;
@@ -181,10 +189,13 @@
    {
       incomingCommand = (ENetIncomingCommand *) enet_list_front (& channel -> incomingUnreliableCommands);
 
-      if (incomingCommand -> reliableSequenceNumber > channel -> incomingReliableSequenceNumber)
-        incomingCommand = NULL;
-      else
-        channel -> incomingUnreliableSequenceNumber = incomingCommand -> unreliableSequenceNumber;
+      if (incomingCommand -> unreliableSequenceNumber > 0)
+      {
+         if (incomingCommand -> reliableSequenceNumber > channel -> incomingReliableSequenceNumber)
+           incomingCommand = NULL;
+         else
+           channel -> incomingUnreliableSequenceNumber = incomingCommand -> unreliableSequenceNumber;
+      }
    }
 
    if (incomingCommand == NULL &&
@@ -362,7 +373,11 @@
     peer -> reliableDataInTransit = 0;
     peer -> outgoingReliableSequenceNumber = 0;
     peer -> windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
+    peer -> incomingUnsequencedGroup = 0;
+    peer -> outgoingUnsequencedGroup = 0;
 
+    memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow));
+    
     enet_peer_reset_queues (peer);
 }
 
@@ -410,7 +425,7 @@
 
         command.header.command = ENET_PROTOCOL_COMMAND_DISCONNECT;
         command.header.channelID = 0xFF;
-        command.header.flags = 0;
+        command.header.flags = ENET_PROTOCOL_FLAG_UNSEQUENCED;
         command.header.commandLength = sizeof (ENetProtocolDisconnect);
 
         enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);
@@ -440,11 +455,11 @@
 
     command.header.command = ENET_PROTOCOL_COMMAND_DISCONNECT;
     command.header.channelID = 0xFF;
-    command.header.flags = 0;
+    command.header.flags = ENET_PROTOCOL_FLAG_UNSEQUENCED;
     command.header.commandLength = sizeof (ENetProtocolDisconnect);
 
     if (peer -> state == ENET_PEER_STATE_CONNECTED)
-      command.header.flags |= ENET_PROTOCOL_FLAG_ACKNOWLEDGE;
+      command.header.flags = ENET_PROTOCOL_FLAG_ACKNOWLEDGE;
     
     enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);
 
@@ -500,6 +515,12 @@
        outgoingCommand -> unreliableSequenceNumber = 0;
     }
     else
+    if (command -> header.flags & ENET_PROTOCOL_FLAG_UNSEQUENCED)
+    {
+       outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber;
+       outgoingCommand -> unreliableSequenceNumber = 0;
+    }
+    else
     {
        ++ channel -> outgoingUnreliableSequenceNumber;
         
@@ -535,11 +556,9 @@
     ENetIncomingCommand * incomingCommand;
     ENetListIterator currentCommand;
 
-    if (command -> header.command == ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE)
-      unreliableSequenceNumber = ENET_NET_TO_HOST_32 (command -> sendUnreliable.unreliableSequenceNumber);
-
-    if (unreliableSequenceNumber == 0)
+    switch (command -> header.command)
     {
+    case ENET_PROTOCOL_COMMAND_SEND_RELIABLE:
        for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingReliableCommands));
             currentCommand != enet_list_end (& channel -> incomingReliableCommands);
             currentCommand = enet_list_previous (currentCommand))
@@ -554,9 +573,11 @@
              goto freePacket;
           }
        }
-    }
-    else
-    {
+       break;
+
+    case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE:
+       unreliableSequenceNumber = ENET_NET_TO_HOST_32 (command -> sendUnreliable.unreliableSequenceNumber);
+
        if (command -> header.reliableSequenceNumber < channel -> incomingReliableSequenceNumber)
          goto freePacket;
 
@@ -577,8 +598,16 @@
              goto freePacket;
           }
        }
+       break;
+
+    case ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED:
+       currentCommand = enet_list_end (& channel -> incomingUnreliableCommands);
+       break;
+
+    default:
+       goto freePacket;
     }
-        
+
     incomingCommand = (ENetIncomingCommand *) enet_malloc (sizeof (ENetIncomingCommand));
 
     incomingCommand -> reliableSequenceNumber = command -> header.reliableSequenceNumber;
@@ -587,11 +616,13 @@
     incomingCommand -> fragmentCount = fragmentCount;
     incomingCommand -> fragmentsRemaining = fragmentCount;
     incomingCommand -> packet = packet;
-
+    incomingCommand -> fragments = NULL;
+    
     if (fragmentCount > 0)
-      incomingCommand -> fragments = (enet_uint32 *) enet_calloc ((fragmentCount + 31) / 32, sizeof (enet_uint32));
-    else
-      incomingCommand -> fragments = NULL;
+    { 
+       incomingCommand -> fragments = (enet_uint32 *) enet_malloc ((fragmentCount + 31) / 32 * sizeof (enet_uint32));
+       memset (incomingCommand -> fragments, 0, (fragmentCount + 31) / 32 * sizeof (enet_uint32));
+    }
 
     if (packet != NULL)
       ++ packet -> referenceCount;

Index: protocol.c
===================================================================
RCS file: /home/enet/cvsroot/enet/protocol.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- protocol.c	2004/01/06 02:30:26	1.36
+++ protocol.c	2004/03/29 21:43:14	1.37
@@ -6,7 +6,6 @@
 #include <string.h>
 #define ENET_BUILDING_LIB 1
 #include "enet/utility.h"
-#include "enet/memory.h"
 #include "enet/time.h"
 #include "enet/enet.h"
 
@@ -279,6 +278,41 @@
 }
 
 static void
+enet_protocol_handle_send_unsequenced (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
+{
+    ENetPacket * packet;
+    enet_uint32 unsequencedGroup, index;
+
+    if (command -> header.commandLength <= sizeof (ENetProtocolSendUnsequenced) ||
+        command -> header.channelID >= peer -> channelCount ||
+        peer -> state != ENET_PEER_STATE_CONNECTED)
+      return;
+
+    unsequencedGroup = ENET_NET_TO_HOST_32 (command -> sendUnsequenced.unsequencedGroup);
+    index = unsequencedGroup % ENET_PEER_UNSEQUENCED_WINDOW_SIZE;
+    
+    if (unsequencedGroup >= peer -> incomingUnsequencedGroup + ENET_PEER_UNSEQUENCED_WINDOW_SIZE)
+    {
+        peer -> incomingUnsequencedGroup = unsequencedGroup - index;
+
+        memeset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow));
+    }
+    else
+    if (unsequencedGroup < peer -> incomingUnsequencedGroup ||
+        peer -> unsequencedWindow [index / 32] & (1 << (index % 32)))
+      return;
+      
+    peer -> unsequencedWindow [index / 32] |= 1 << (index % 32);
+    
+                        
+    packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnsequenced),
+                                 command -> header.commandLength - sizeof (ENetProtocolSendUnsequenced),
+                                 ENET_PACKET_FLAG_UNSEQUENCED);
+
+    enet_peer_queue_incoming_command (peer, command, packet, 0);
+}
+
+static void
 enet_protocol_handle_send_unreliable (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
 {
     ENetPacket * packet;
@@ -676,6 +710,11 @@
 
        case ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE:
           enet_protocol_handle_send_unreliable (host, peer, command);
+
+          break;
+
+       case ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED:
+          enet_protocol_handle_send_unsequenced (host, peer, command);
 
           break;
 

Index: unix.c
===================================================================
RCS file: /home/enet/cvsroot/enet/unix.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- unix.c	2003/10/30 15:55:31	1.11
+++ unix.c	2004/03/29 21:43:15	1.12
@@ -25,6 +25,10 @@
 #include <sys/poll.h>
 #endif
 
+#ifndef HAS_SOCKLEN_T
+typedef int socklen_t;
+#endif
+
 #ifndef MSG_NOSIGNAL
 #define MSG_NOSIGNAL 0
 #endif

Index: win32.c
===================================================================
RCS file: /home/enet/cvsroot/enet/win32.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- win32.c	2003/10/30 15:55:31	1.10
+++ win32.c	2004/03/29 21:43:15	1.11
@@ -27,25 +27,29 @@
        return -1;
     }
 
+    timeBeginPeriod (1);
+
     return 0;
 }
 
 void
 enet_deinitialize (void)
 {
+    timeEndPeriod (1);
+
     WSACleanup ();
 }
 
 enet_uint32
 enet_time_get (void)
 {
-    return (enet_uint32) GetTickCount () - timeBase;
+    return (enet_uint32) timeGetTime () - timeBase;
 }
 
 void
 enet_time_set (enet_uint32 newTimeBase)
 {
-    timeBase = (enet_uint32) GetTickCount () - newTimeBase;
+    timeBase = (enet_uint32) timeGetTime () - newTimeBase;
 }
 
 int



More information about the enet-cvs mailing list