remove bogus custom timeout handling code
in networking, hitting a timeout requires that *nothing* happens during the
interval. whenever anything happens, the timeout is reset.
there's no need to do custom time calculations, it's perfectly fine to let
the kernel handle it using the select() syscall.
additionally the code added in 0b9a74c290
assures that read and write syscalls() don't block indefinitely and return
on the timeout too, so there's no need to switch sockets back and forth
between blocking/nonblocking.
This commit is contained in:
parent
b4e3f1a896
commit
b549ba5af3
16
src/child.c
16
src/child.c
@ -130,14 +130,6 @@ void child_main_loop (void)
|
||||
for (i = 0; i < vector_length(listen_fds); i++) {
|
||||
int *fd = (int *) vector_getentry(listen_fds, i, NULL);
|
||||
|
||||
ret = socket_nonblocking(*fd);
|
||||
if (ret != 0) {
|
||||
log_message(LOG_ERR, "Failed to set the listening "
|
||||
"socket %d to non-blocking: %s",
|
||||
fd, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
FD_SET(*fd, &rfds);
|
||||
maxfd = max(maxfd, *fd);
|
||||
}
|
||||
@ -175,14 +167,6 @@ void child_main_loop (void)
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = socket_blocking(listenfd);
|
||||
if (ret != 0) {
|
||||
log_message(LOG_ERR, "Failed to set listening "
|
||||
"socket %d to blocking for accept: %s",
|
||||
listenfd, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have a socket that is readable.
|
||||
* Continue handling this connection.
|
||||
|
52
src/reqs.c
52
src/reqs.c
@ -1154,38 +1154,14 @@ static void relay_connection (struct conn_s *connptr)
|
||||
{
|
||||
fd_set rset, wset;
|
||||
struct timeval tv;
|
||||
time_t last_access;
|
||||
int ret;
|
||||
double tdiff;
|
||||
int maxfd = max (connptr->client_fd, connptr->server_fd) + 1;
|
||||
ssize_t bytes_received;
|
||||
|
||||
ret = socket_nonblocking (connptr->client_fd);
|
||||
if (ret != 0) {
|
||||
log_message(LOG_ERR, "Failed to set the client socket "
|
||||
"to non-blocking: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
ret = socket_nonblocking (connptr->server_fd);
|
||||
if (ret != 0) {
|
||||
log_message(LOG_ERR, "Failed to set the server socket "
|
||||
"to non-blocking: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
last_access = time (NULL);
|
||||
|
||||
for (;;) {
|
||||
tv.tv_sec =
|
||||
config->idletimeout - difftime (time (NULL), last_access);
|
||||
tv.tv_sec = config->idletimeout;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
if (tv.tv_sec < 0) {
|
||||
tdiff = config->idletimeout + 1;
|
||||
goto e_timedout;
|
||||
}
|
||||
|
||||
FD_ZERO (&rset);
|
||||
FD_ZERO (&wset);
|
||||
|
||||
@ -1201,16 +1177,9 @@ static void relay_connection (struct conn_s *connptr)
|
||||
ret = select (maxfd, &rset, &wset, NULL, &tv);
|
||||
|
||||
if (ret == 0) {
|
||||
tdiff = difftime (time (NULL), last_access);
|
||||
if (tdiff > config->idletimeout) {
|
||||
e_timedout:;
|
||||
log_message (LOG_INFO,
|
||||
"Idle Timeout (after select) as %g > %u.",
|
||||
tdiff, config->idletimeout);
|
||||
"Idle Timeout (after select)");
|
||||
return;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else if (ret < 0) {
|
||||
log_message (LOG_ERR,
|
||||
"relay_connection: select() error \"%s\". "
|
||||
@ -1218,11 +1187,6 @@ static void relay_connection (struct conn_s *connptr)
|
||||
strerror (errno), connptr->client_fd,
|
||||
connptr->server_fd);
|
||||
return;
|
||||
} else {
|
||||
/*
|
||||
* All right, something was actually selected so mark it.
|
||||
*/
|
||||
last_access = time (NULL);
|
||||
}
|
||||
|
||||
if (FD_ISSET (connptr->server_fd, &rset)) {
|
||||
@ -1249,18 +1213,6 @@ static void relay_connection (struct conn_s *connptr)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Here the server has closed the connection... write the
|
||||
* remainder to the client and then exit.
|
||||
*/
|
||||
ret = socket_blocking (connptr->client_fd);
|
||||
if (ret != 0) {
|
||||
log_message(LOG_ERR,
|
||||
"Failed to set client socket to blocking: %s",
|
||||
strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
while (buffer_size (connptr->sbuffer) > 0) {
|
||||
if (write_buffer (connptr->client_fd, connptr->sbuffer) < 0)
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user