1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-06-05 16:04:08 +00:00

Don't wait for the network when read buffers possibly hold commands

There is no point in waiting up to one second for the network receiving
new data when there is still a read buffer holding at least one command;
we shouldn't waste time but handle it immediately!
This commit is contained in:
Alexander Barton 2020-05-03 02:55:34 +02:00
parent 54fac57603
commit 387a29a7fd

View File

@ -660,12 +660,14 @@ Conn_Handler(void)
size_t wdatalen; size_t wdatalen;
struct timeval tv; struct timeval tv;
time_t t; time_t t;
bool command_available;
Log(LOG_NOTICE, "Server \"%s\" (on \"%s\") ready.", Log(LOG_NOTICE, "Server \"%s\" (on \"%s\") ready.",
Client_ID(Client_ThisServer()), Client_Hostname(Client_ThisServer())); Client_ID(Client_ThisServer()), Client_Hostname(Client_ThisServer()));
while (!NGIRCd_SignalQuit && !NGIRCd_SignalRestart) { while (!NGIRCd_SignalQuit && !NGIRCd_SignalRestart) {
t = time(NULL); t = time(NULL);
command_available = false;
/* Check configured servers and established links */ /* Check configured servers and established links */
Check_Servers(); Check_Servers();
@ -743,19 +745,22 @@ Conn_Handler(void)
* this command(s) to be handled first! */ * this command(s) to be handled first! */
io_event_del(My_Connections[i].sock, io_event_del(My_Connections[i].sock,
IO_WANTREAD); IO_WANTREAD);
command_available = true;
continue; continue;
} }
io_event_add(My_Connections[i].sock, IO_WANTREAD); io_event_add(My_Connections[i].sock, IO_WANTREAD);
} }
/* Set the timeout for reading from the network to 1 second, /* Don't wait for data when there is still at least one command
* which is the granularity with witch we handle "penalty * available in a read buffer which can be handled immediately;
* times" for example. * set the timeout for reading from the network to 1 second
* otherwise, which is the granularity with witch we handle
* "penalty times" for example.
* Note: tv_sec/usec are undefined(!) after io_dispatch() * Note: tv_sec/usec are undefined(!) after io_dispatch()
* returns, so we have to set it before each call to it! */ * returns, so we have to set it before each call to it! */
tv.tv_usec = 0; tv.tv_usec = 0;
tv.tv_sec = 1; tv.tv_sec = command_available ? 0 : 1;
/* Wait for activity ... */ /* Wait for activity ... */
i = io_dispatch(&tv); i = io_dispatch(&tv);