diff options
author | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2006-08-18 01:50:51 +0000 |
---|---|---|
committer | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2006-08-18 01:50:51 +0000 |
commit | f053285852be89ef4238b1a6682a63233501f342 (patch) | |
tree | f2e96d101bf89ef0b3ab747f9ad555104a7a2be1 /code/unix | |
parent | 8f07dfd1a98d8a6128a731acd0ac3792579b216b (diff) | |
download | ioquake3-aero-f053285852be89ef4238b1a6682a63233501f342.tar.gz ioquake3-aero-f053285852be89ef4238b1a6682a63233501f342.zip |
Fix 100% CPU usage on idle dedicated servers.
git-svn-id: svn://svn.icculus.org/quake3/trunk@850 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/unix')
-rw-r--r-- | code/unix/unix_net.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/code/unix/unix_net.c b/code/unix/unix_net.c index 73c0fd6..12908eb 100644 --- a/code/unix/unix_net.c +++ b/code/unix/unix_net.c @@ -648,19 +648,40 @@ char *NET_ErrorString (void) // sleeps msec or until net socket is ready void NET_Sleep(int msec) { - struct timeval timeout; + struct timeval timeout; fd_set fdset; extern qboolean stdin_active; + qboolean not_empty = qfalse; - if (!ip_socket || !com_dedicated->integer) + if (!com_dedicated->integer) return; // we're not a server, just run full speed FD_ZERO(&fdset); if (stdin_active) + { FD_SET(0, &fdset); // stdin is processed too - FD_SET(ip_socket, &fdset); // network socket - timeout.tv_sec = msec/1000; - timeout.tv_usec = (msec%1000)*1000; - select(ip_socket+1, &fdset, NULL, NULL, &timeout); + not_empty = qtrue; + } + if(ip_socket && com_sv_running->integer) + { + FD_SET(ip_socket, &fdset); // network socket + not_empty = qtrue; + } + + // There's no reason to call select() with an empty set. + if(not_empty) + { + if(msec >= 0) + { + timeout.tv_sec = msec/1000; + timeout.tv_usec = (msec%1000)*1000; + select(ip_socket+1, &fdset, NULL, NULL, &timeout); + } + else + { + // Block indefinitely + select(ip_socket+1, &fdset, NULL, NULL, NULL); + } + } } |