From aa8460c0ba92bb92d0afaf80f0df518f4d5724fc Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 12 Jul 2015 12:40:23 +1000 Subject: [PATCH] Set default unix read timeout back to 5 seconds except for ckpmsg and ckdb which need the 30s defaults, and double the write timeout --- src/ckdb.c | 2 +- src/libckpool.c | 8 ++++---- src/libckpool.h | 10 ++++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 7a469159..d8eba810 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -3743,7 +3743,7 @@ static void *socketer(__maybe_unused void *arg) cmdnum = CMD_UNSET; - buf = recv_unix_msg(sockd); + buf = recv_unix_msg_tmo2(sockd, RECV_UNIX_TIMEOUT1, RECV_UNIX_TIMEOUT2); // Once we've read the message setnow(&now); if (buf) { diff --git a/src/libckpool.c b/src/libckpool.c index a2714c2f..a72dba24 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1050,7 +1050,7 @@ bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *fu goto out; } msglen = htole32(len); - ret = wait_write_select(sockd, 5); + ret = wait_write_select(sockd, UNIX_WRITE_TIMEOUT); if (unlikely(ret < 1)) { ern = errno; LOGERR("Select1 failed in send_unix_msg (%d)", ern); @@ -1061,7 +1061,7 @@ bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *fu LOGERR("Failed to write 4 byte length in send_unix_msg"); goto out; } - ret = wait_write_select(sockd, 5); + ret = wait_write_select(sockd, UNIX_WRITE_TIMEOUT); if (unlikely(ret < 1)) { ern = errno; LOGERR("Select2 failed in send_unix_msg (%d)", ern); @@ -1089,7 +1089,7 @@ bool _send_unix_data(int sockd, const struct msghdr *msg, const char *file, cons LOGWARNING("Null message sent to send_unix_data"); goto out; } - ret = wait_write_select(sockd, 5); + ret = wait_write_select(sockd, UNIX_WRITE_TIMEOUT); if (unlikely(ret < 1)) { LOGERR("Select1 failed in send_unix_data"); goto out; @@ -1112,7 +1112,7 @@ bool _recv_unix_data(int sockd, struct msghdr *msg, const char *file, const char bool retval = false; int ret; - ret = wait_read_select(sockd, 5); + ret = wait_read_select(sockd, UNIX_READ_TIMEOUT); if (unlikely(ret < 1)) { LOGERR("Select1 failed in recv_unix_data"); goto out; diff --git a/src/libckpool.h b/src/libckpool.h index 10611916..26aff16d 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -236,6 +236,12 @@ void logmsg(int loglevel, const char *fmt, ...); #define PAGESIZE (4096) +/* Default timeouts for unix socket reads and writes in seconds. Set write + * timeout to double the read timeout in case of one read blocking the next + * writer. */ +#define UNIX_READ_TIMEOUT 5 +#define UNIX_WRITE_TIMEOUT 10 + /* Share error values */ enum share_err { @@ -495,8 +501,8 @@ int read_length(int sockd, void *buf, int len); char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, const char *func, const int line); #define RECV_UNIX_TIMEOUT1 30 #define RECV_UNIX_TIMEOUT2 5 -#define recv_unix_msg(sockd) _recv_unix_msg(sockd, RECV_UNIX_TIMEOUT1, RECV_UNIX_TIMEOUT2, __FILE__, __func__, __LINE__) -#define recv_unix_msg_tmo(sockd, tmo) _recv_unix_msg(sockd, tmo, RECV_UNIX_TIMEOUT2, __FILE__, __func__, __LINE__) +#define recv_unix_msg(sockd) _recv_unix_msg(sockd, UNIX_READ_TIMEOUT, UNIX_READ_TIMEOUT, __FILE__, __func__, __LINE__) +#define recv_unix_msg_tmo(sockd, tmo) _recv_unix_msg(sockd, tmo, UNIX_READ_TIMEOUT, __FILE__, __func__, __LINE__) #define recv_unix_msg_tmo2(sockd, tmo1, tmo2) _recv_unix_msg(sockd, tmo1, tmo2, __FILE__, __func__, __LINE__) int wait_write_select(int sockd, float timeout); #define write_length(sockd, buf, len) _write_length(sockd, buf, len, __FILE__, __func__, __LINE__)