Fix 100% CPU usage on idle dedicated servers.
This commit is contained in:
parent
55bddd58fd
commit
5e88acf217
3 changed files with 38 additions and 9 deletions
|
@ -2660,9 +2660,9 @@ int Com_ModifyMsec( int msec ) {
|
||||||
// dedicated servers don't want to clamp for a much longer
|
// dedicated servers don't want to clamp for a much longer
|
||||||
// period, because it would mess up all the client's views
|
// period, because it would mess up all the client's views
|
||||||
// of time.
|
// of time.
|
||||||
if ( msec > 500 ) {
|
if (com_sv_running->integer && msec > 500)
|
||||||
Com_Printf( "Hitch warning: %i msec frame time\n", msec );
|
Com_Printf( "Hitch warning: %i msec frame time\n", msec );
|
||||||
}
|
|
||||||
clampTime = 5000;
|
clampTime = 5000;
|
||||||
} else
|
} else
|
||||||
if ( !com_sv_running->integer ) {
|
if ( !com_sv_running->integer ) {
|
||||||
|
|
|
@ -777,7 +777,15 @@ void SV_Frame( int msec ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !com_sv_running->integer ) {
|
if (!com_sv_running->integer)
|
||||||
|
{
|
||||||
|
if(com_dedicated->integer)
|
||||||
|
{
|
||||||
|
// Block indefinitely until something interesting happens
|
||||||
|
// on STDIN.
|
||||||
|
NET_Sleep(-1);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -651,16 +651,37 @@ void NET_Sleep(int msec)
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
fd_set fdset;
|
fd_set fdset;
|
||||||
extern qboolean stdin_active;
|
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
|
return; // we're not a server, just run full speed
|
||||||
|
|
||||||
FD_ZERO(&fdset);
|
FD_ZERO(&fdset);
|
||||||
if (stdin_active)
|
if (stdin_active)
|
||||||
|
{
|
||||||
FD_SET(0, &fdset); // stdin is processed too
|
FD_SET(0, &fdset); // stdin is processed too
|
||||||
|
not_empty = qtrue;
|
||||||
|
}
|
||||||
|
if(ip_socket && com_sv_running->integer)
|
||||||
|
{
|
||||||
FD_SET(ip_socket, &fdset); // network socket
|
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_sec = msec/1000;
|
||||||
timeout.tv_usec = (msec%1000)*1000;
|
timeout.tv_usec = (msec%1000)*1000;
|
||||||
select(ip_socket+1, &fdset, NULL, NULL, &timeout);
|
select(ip_socket+1, &fdset, NULL, NULL, &timeout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Block indefinitely
|
||||||
|
select(ip_socket+1, &fdset, NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue