From 649461ff0142416139c48db74eb8f8b258a4d561 Mon Sep 17 00:00:00 2001 From: kanoi Date: Fri, 19 Aug 2016 12:33:25 +1000 Subject: [PATCH] ckdb - add a simple socketer timeout for quiet pools :) --- src/ckdb.c | 25 +++++++++++++++++++++++-- src/ckdb.h | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index a24a51eb..2412e174 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -5940,8 +5940,9 @@ static void *socketer(void *arg) char *end, *buf = NULL; K_ITEM *bq_item = NULL; BREAKQUEUE *bq = NULL; - int sockd; - tv_t now, nowacc, now1, now2; + int ret, sockd; + fd_set rfds; + tv_t now, nowacc, now1, now2, tmo; pthread_detach(pthread_self()); @@ -5972,9 +5973,29 @@ static void *socketer(void *arg) create_pthread(&proc_pt, process_socket, arg); } + ret = 0; setnow(&sock_stt); while (!everyone_die) { setnow(&now1); + while (!everyone_die) { + FD_ZERO(&rfds); + FD_SET(us->sockd, &rfds); + tmo.tv_sec = 1; + tmo.tv_usec = 0; + ret = select(us->sockd + 1, &rfds, NULL, NULL, &tmo); + if (ret > 0) + break; + if (ret < 0) { + int e = errno; + LOGERR("%s() Failed to select on socket (%d:%s)", + __func__, e, strerror(e)); + break; + } + } + // Timeout exit on no input (or error) + if (everyone_die || ret < 0) + break; + sockd = accept(us->sockd, NULL, NULL); if (sockd < 0) { int e = errno; diff --git a/src/ckdb.h b/src/ckdb.h index 2c8d8b02..c2e3d54e 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.405" +#define CKDB_VERSION DB_VERSION"-2.406" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__