From e94115d6e28b7407f5b90b1f3b6016e30cdfd106 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 12 Jul 2015 14:56:12 +1000 Subject: [PATCH] Allow _send_recv_proc to take custom timeouts --- src/ckpool.c | 7 ++++--- src/ckpool.h | 5 +++-- src/libckpool.c | 6 +++--- src/libckpool.h | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 4d00084e..f7ec1fbe 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -640,7 +640,8 @@ out: /* Send a single message to a process instance and retrieve the response, then * close the socket. */ -char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line) +char *_send_recv_proc(proc_instance_t *pi, int writetimeout, int readtimedout, + const char *msg, const char *file, const char *func, const int line) { char *path = pi->us.path, *buf = NULL; int sockd; @@ -670,10 +671,10 @@ char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, co LOGWARNING("Failed to open socket %s in send_recv_proc", path); goto out; } - if (unlikely(!send_unix_msg(sockd, msg))) + if (unlikely(!_send_unix_msg(sockd, msg, writetimeout, file, func, line))) LOGWARNING("Failed to send %s to socket %s", msg, path); else - buf = recv_unix_msg(sockd); + buf = _recv_unix_msg(sockd, readtimedout, readtimedout, file, func, line); Close(sockd); out: if (unlikely(!buf)) diff --git a/src/ckpool.h b/src/ckpool.h index d859ce89..12ee8612 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -245,8 +245,9 @@ void empty_buffer(connsock_t *cs); int read_socket_line(connsock_t *cs, float *timeout); void _send_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line); #define send_proc(pi, msg) _send_proc(pi, msg, __FILE__, __func__, __LINE__) -char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line); -#define send_recv_proc(pi, msg) _send_recv_proc(pi, msg, __FILE__, __func__, __LINE__) +char *_send_recv_proc(proc_instance_t *pi, int writetimeout, int readtimedout, + const char *msg, const char *file, const char *func, const int line); +#define send_recv_proc(pi, msg) _send_recv_proc(pi, UNIX_WRITE_TIMEOUT, UNIX_READ_TIMEOUT, msg, __FILE__, __func__, __LINE__) char *_send_recv_ckdb(const ckpool_t *ckp, const char *msg, const char *file, const char *func, const int line); #define send_recv_ckdb(ckp, msg) _send_recv_ckdb(ckp, msg, __FILE__, __func__, __LINE__) char *_ckdb_msg_call(const ckpool_t *ckp, const char *msg, const char *file, const char *func, diff --git a/src/libckpool.c b/src/libckpool.c index a72dba24..50358ab9 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1030,7 +1030,7 @@ int _write_length(int sockd, const void *buf, int len, const char *file, const c return ofs; } -bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *func, const int line) +bool _send_unix_msg(int sockd, const char *buf, int timeout, const char *file, const char *func, const int line) { uint32_t msglen, len; bool retval = false; @@ -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, UNIX_WRITE_TIMEOUT); + ret = wait_write_select(sockd, 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, UNIX_WRITE_TIMEOUT); + ret = wait_write_select(sockd, timeout); if (unlikely(ret < 1)) { ern = errno; LOGERR("Select2 failed in send_unix_msg (%d)", ern); diff --git a/src/libckpool.h b/src/libckpool.h index 26aff16d..aed291dc 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -507,8 +507,8 @@ char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, co int wait_write_select(int sockd, float timeout); #define write_length(sockd, buf, len) _write_length(sockd, buf, len, __FILE__, __func__, __LINE__) int _write_length(int sockd, const void *buf, int len, const char *file, const char *func, const int line); -bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *func, const int line); -#define send_unix_msg(sockd, buf) _send_unix_msg(sockd, buf, __FILE__, __func__, __LINE__) +bool _send_unix_msg(int sockd, const char *buf, int timeout, const char *file, const char *func, const int line); +#define send_unix_msg(sockd, buf) _send_unix_msg(sockd, buf, UNIX_WRITE_TIMEOUT, __FILE__, __func__, __LINE__) bool _send_unix_data(int sockd, const struct msghdr *msg, const char *file, const char *func, const int line); #define send_unix_data(sockd, msg) _send_unix_data(sockd, msg, __FILE__, __func__, __LINE__) bool _recv_unix_data(int sockd, struct msghdr *msg, const char *file, const char *func, const int line);