From 6dec2b468bca5f4df3bccf4854811d6dc1146672 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 28 Nov 2019 16:19:57 +0000 Subject: [PATCH] Remove redundant expiry checks This is all now handled in session_expiry.c, through session expiry interval/time. --- src/loop.c | 31 ------------------------------- src/session_expiry.c | 6 ++++++ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src/loop.c b/src/loop.c index 92673db2..2fee9ac7 100644 --- a/src/loop.c +++ b/src/loop.c @@ -138,8 +138,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li int err; socklen_t len; #endif - time_t expiration_check_time = 0; - char *id; #if defined(WITH_WEBSOCKETS) && LWS_LIBRARY_VERSION_NUMBER == 3002000 @@ -169,10 +167,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li } #endif - if(db->config->persistent_client_expiration > 0){ - expiration_check_time = time(NULL) + 3600; - } - #ifdef WITH_EPOLL db->epollfd = 0; if ((db->epollfd = epoll_create(MAX_EVENTS)) == -1) { @@ -471,31 +465,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li } } #endif - now = time(NULL); - if(db->config->persistent_client_expiration > 0 && now > expiration_check_time){ - HASH_ITER(hh_id, db->contexts_by_id, context, ctxt_tmp){ - if(context->sock == INVALID_SOCKET && context->session_expiry_interval > 0 && context->session_expiry_interval != UINT32_MAX){ - /* This is a persistent client, check to see if the - * last time it connected was longer than - * persistent_client_expiration seconds ago. If so, - * expire it and clean up. - */ - if(now > context->session_expiry_time){ - if(context->id){ - id = context->id; - }else{ - id = ""; - } - log__printf(NULL, MOSQ_LOG_NOTICE, "Expiring persistent client %s due to timeout.", id); - G_CLIENTS_EXPIRED_INC(); - context->session_expiry_interval = 0; - mosquitto__set_state(context, mosq_cs_expiring); - do_disconnect(db, context, MOSQ_ERR_SUCCESS); - } - } - } - expiration_check_time = time(NULL) + 3600; - } #ifndef WIN32 sigprocmask(SIG_SETMASK, &sigblock, &origsig); diff --git a/src/session_expiry.c b/src/session_expiry.c index 5732c106..59e4c2f6 100644 --- a/src/session_expiry.c +++ b/src/session_expiry.c @@ -22,6 +22,7 @@ Contributors: #include "mosquitto_broker_internal.h" #include "memory_mosq.h" +#include "sys_tree.h" #include "time_mosq.h" static struct session_expiry_list *expiry_list = NULL; @@ -115,6 +116,11 @@ void session_expiry__check(struct mosquitto_db *db, time_t now) context = item->context; session_expiry__remove(context); + if(context->id){ + log__printf(NULL, MOSQ_LOG_NOTICE, "Expiring client %s due to timeout.", context->id); + } + G_CLIENTS_EXPIRED_INC(); + /* Session has now expired, so clear interval */ context->session_expiry_interval = 0; /* Session has expired, so will delay should be cleared. */