diff --git a/sslh-select.c b/sslh-select.c index 95c16e4..00dfa32 100644 --- a/sslh-select.c +++ b/sslh-select.c @@ -462,12 +462,14 @@ void cnx_accept_process(struct select_info* fd_info, struct listen_endpoint* lis void udp_timeouts(struct select_info* fd_info) { + time_t now = time(NULL); + for (int i = 0; i < fd_info->max_fd; i++) { /* if it's either in read or write set, there is a connection * behind that file descriptor */ if (FD_ISSET(i, &fd_info->fds_r) || FD_ISSET(i, &fd_info->fds_w)) { struct connection* cnx = collection_get_cnx_from_fd(fd_info->collection, i); - if (cnx && udp_timedout(cnx)) { + if (cnx && udp_timedout(now, cnx)) { close(cnx->target_sock); FD_CLR(i, &fd_info->fds_r); FD_CLR(i, &fd_info->fds_w); diff --git a/udp-listener.c b/udp-listener.c index 4d0bb97..6209980 100644 --- a/udp-listener.c +++ b/udp-listener.c @@ -130,10 +130,8 @@ void udp_s2c_forward(struct connection* cnx) /* Checks if a connection timed out, in which case close the socket and return * 1; otherwise return 0. */ -int udp_timedout(struct connection* cnx) +int udp_timedout(time_t now, struct connection* cnx) { - time_t now = time(NULL); - if (cnx->type != SOCK_DGRAM) return 0; /* Not a UDP connection */ if ((now - cnx->last_active > cnx->proto->udp_timeout)) { diff --git a/udp-listener.h b/udp-listener.h index bbaf3c2..6c043ff 100644 --- a/udp-listener.h +++ b/udp-listener.h @@ -22,6 +22,6 @@ void udp_s2c_forward(struct connection* cnx); /* Checks if a connection timed out, in which case close the socket and return * 1; otherwise return 0. */ -int udp_timedout(struct connection* cnx); +int udp_timedout(time_t now, struct connection* cnx); #endif /* UDPLISTENER_H */