]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - lhnet.c
added NetConn_SleepMicroseconds function, and LHNET_SleepUntilPacket_Microseconds...
[xonotic/darkplaces.git] / lhnet.c
diff --git a/lhnet.c b/lhnet.c
index 4f820099e2e6e2efe3e6707a359fa6ea064d9552..b3f392d85e4a0280b750cb2e4fce40f525d6d169 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;