From 491df26e7e8c66fab2db0c89d2017a815986c0d7 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 29 Mar 2007 00:33:16 +0000 Subject: [PATCH] added NetConn_SleepMicroseconds function, and LHNET_SleepUntilPacket_Microseconds function, this uses select() to wait for a specified amount of time or until a packet is received git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7016 d7cf8633-e32d-0410-b094-e92efae38249 --- lhnet.c | 22 ++++++++++++++++++++++ lhnet.h | 1 + netconn.c | 5 +++++ netconn.h | 1 + 4 files changed, 29 insertions(+) diff --git a/lhnet.c b/lhnet.c index 4f820099..b3f392d8 100644 --- 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 1d0de942..c865f9a9 100644 --- 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); diff --git a/netconn.c b/netconn.c index cac6d1ad..8dec0869 100755 --- 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; diff --git a/netconn.h b/netconn.h index f158e359..9b54313d 100755 --- 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); -- 2.39.2