]> www.vanbest.org Git - sasc-ng.git/commitdiff
allow microsecond network timeouts
authorleslie <unknown>
Tue, 4 Aug 2009 13:29:58 +0000 (21:29 +0800)
committerleslie <unknown>
Tue, 4 Aug 2009 13:29:58 +0000 (21:29 +0800)
network.c
network.h

index 702d9a6091232cba8ae7f0362b9907049381b50a..5cd86213260c5c36a7e08603286d60f2e904e688 100644 (file)
--- a/network.c
+++ b/network.c
@@ -336,7 +336,8 @@ int cNetSocket::Select(bool forRead, int timeout)
     fd_set fds;
     FD_ZERO(&fds); FD_SET(sd,&fds);
     struct timeval tv;
-    tv.tv_sec=timeout; tv.tv_usec=0;
+    if(timeout&MSTIMEOUT) { tv.tv_sec=0; tv.tv_usec=(timeout&~MSTIMEOUT)*1000; }
+    else { tv.tv_sec=timeout; tv.tv_usec=0; }
     int r=select(sd+1,forRead ? &fds:0,forRead ? 0:&fds,0,&tv);
     if(r>0) return 1;
     else if(r<0) {
@@ -344,7 +345,7 @@ int cNetSocket::Select(bool forRead, int timeout)
       return -1;
       }
     else {
-      if(timeout>0 && !quietlog) PRINTF(L_CORE_NET,"socket: select timed out (%d secs)",timeout);
+      if(timeout>0 && !quietlog) PRINTF(L_CORE_NET,"socket: select timed out (%d %s)",timeout&~MSTIMEOUT,(timeout&MSTIMEOUT)?"ms":"secs");
       return 0;
       }
     }
index 5a01aac6f0feb6c1f544a30aa5cdc1b624663ceb..c19d5c78b0fa26bda3d9f3562c6b3c461d0b436e 100644 (file)
--- a/network.h
+++ b/network.h
@@ -30,6 +30,8 @@
 #define DEFAULT_READWRITE_TIMEOUT 3
 #define DEFAULT_IDLE_TIMEOUT      120
 
+#define MSTIMEOUT 0x800000
+
 extern const char *netscript;
 extern int netTimeout;