fix negative timeout resulting in select() EINVAL

This commit is contained in:
rofl0r 2020-09-09 11:59:40 +01:00
parent 78cc5b72b1
commit b4e3f1a896

View File

@ -1177,13 +1177,18 @@ static void relay_connection (struct conn_s *connptr)
last_access = time (NULL); last_access = time (NULL);
for (;;) { for (;;) {
FD_ZERO (&rset);
FD_ZERO (&wset);
tv.tv_sec = tv.tv_sec =
config->idletimeout - difftime (time (NULL), last_access); config->idletimeout - difftime (time (NULL), last_access);
tv.tv_usec = 0; tv.tv_usec = 0;
if (tv.tv_sec < 0) {
tdiff = config->idletimeout + 1;
goto e_timedout;
}
FD_ZERO (&rset);
FD_ZERO (&wset);
if (buffer_size (connptr->sbuffer) > 0) if (buffer_size (connptr->sbuffer) > 0)
FD_SET (connptr->client_fd, &wset); FD_SET (connptr->client_fd, &wset);
if (buffer_size (connptr->cbuffer) > 0) if (buffer_size (connptr->cbuffer) > 0)
@ -1198,6 +1203,7 @@ static void relay_connection (struct conn_s *connptr)
if (ret == 0) { if (ret == 0) {
tdiff = difftime (time (NULL), last_access); tdiff = difftime (time (NULL), last_access);
if (tdiff > config->idletimeout) { if (tdiff > config->idletimeout) {
e_timedout:;
log_message (LOG_INFO, log_message (LOG_INFO,
"Idle Timeout (after select) as %g > %u.", "Idle Timeout (after select) as %g > %u.",
tdiff, config->idletimeout); tdiff, config->idletimeout);