mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-12 15:17:14 +03:00
refactor: take time only once when computing UPD timeouts
This commit is contained in:
parent
63f9c4a582
commit
e4936454c5
@ -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);
|
||||
|
@ -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)) {
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user