added NetConn_SleepMicroseconds function, and LHNET_SleepUntilPacket_Microseconds...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 29 Mar 2007 00:33:16 +0000 (00:33 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 29 Mar 2007 00:33:16 +0000 (00:33 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7016 d7cf8633-e32d-0410-b094-e92efae38249

lhnet.c
lhnet.h
netconn.c
netconn.h

diff --git a/lhnet.c b/lhnet.c
index 4f82009..b3f392d 100644 (file)
--- a/lhnet.c
+++ b/lhnet.c
@@ -495,6 +495,28 @@ static const char *LHNETPRIVATE_StrError(void)
 #endif
 }
 
+void LHNET_SleepUntilPacket_Microseconds(int microseconds)
+{
+       fd_set fdreadset;
+       struct timeval tv;
+       int lastfd;
+       lhnetsocket_t *s;
+       FD_ZERO(&fdreadset);
+       lastfd = 0;
+       for (s = lhnet_socketlist.next;s != &lhnet_socketlist;s = s->next)
+       {
+               if (s->address.addresstype == LHNETADDRESSTYPE_INET4 || s->address.addresstype == LHNETADDRESSTYPE_INET6)
+               {
+                       if (lastfd < s->inetsocket)
+                               lastfd = s->inetsocket;
+                       FD_SET(s->inetsocket, &fdreadset);
+               }
+       }
+       tv.tv_sec = microseconds / 1000000;
+       tv.tv_usec = microseconds % 1000000;
+       select(lastfd + 1, &fdreadset, NULL, NULL, &tv);
+}
+
 lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address)
 {
        lhnetsocket_t *lhnetsocket, *s;
diff --git a/lhnet.h b/lhnet.h
index 1d0de94..c865f9a 100644 (file)
--- a/lhnet.h
+++ b/lhnet.h
@@ -74,6 +74,7 @@ lhnetsocket_t;
 
 void LHNET_Init(void);
 void LHNET_Shutdown(void);
+void LHNET_SleepUntilPacket_Microseconds(int microseconds);
 lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address);
 void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket);
 lhnetaddress_t *LHNET_AddressFromSocket(lhnetsocket_t *sock);
index cac6d1a..8dec086 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -2294,6 +2294,11 @@ void NetConn_ServerFrame(void)
        }
 }
 
+void NetConn_SleepMicroseconds(int microseconds)
+{
+       LHNET_SleepUntilPacket_Microseconds(microseconds);
+}
+
 void NetConn_QueryMasters(qboolean querydp, qboolean queryqw)
 {
        int i;
index f158e35..9b54313 100755 (executable)
--- a/netconn.h
+++ b/netconn.h
@@ -350,6 +350,7 @@ int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnet
 int NetConn_IsLocalGame(void);
 void NetConn_ClientFrame(void);
 void NetConn_ServerFrame(void);
+void NetConn_SleepMicroseconds(int microseconds);
 void NetConn_QueryMasters(qboolean querydp, qboolean queryqw);
 void NetConn_Heartbeat(int priority);
 void NetConn_QueryQueueFrame(void);