Browse Source

Allow _send_recv_proc to take custom timeouts

master
Con Kolivas 10 years ago
parent
commit
e94115d6e2
  1. 7
      src/ckpool.c
  2. 5
      src/ckpool.h
  3. 6
      src/libckpool.c
  4. 4
      src/libckpool.h

7
src/ckpool.c

@ -640,7 +640,8 @@ out:
/* Send a single message to a process instance and retrieve the response, then /* Send a single message to a process instance and retrieve the response, then
* close the socket. */ * 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; char *path = pi->us.path, *buf = NULL;
int sockd; 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); LOGWARNING("Failed to open socket %s in send_recv_proc", path);
goto out; 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); LOGWARNING("Failed to send %s to socket %s", msg, path);
else else
buf = recv_unix_msg(sockd); buf = _recv_unix_msg(sockd, readtimedout, readtimedout, file, func, line);
Close(sockd); Close(sockd);
out: out:
if (unlikely(!buf)) if (unlikely(!buf))

5
src/ckpool.h

@ -245,8 +245,9 @@ void empty_buffer(connsock_t *cs);
int read_socket_line(connsock_t *cs, float *timeout); 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); 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__) #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); char *_send_recv_proc(proc_instance_t *pi, int writetimeout, int readtimedout,
#define send_recv_proc(pi, msg) _send_recv_proc(pi, msg, __FILE__, __func__, __LINE__) 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); 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__) #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, char *_ckdb_msg_call(const ckpool_t *ckp, const char *msg, const char *file, const char *func,

6
src/libckpool.c

@ -1030,7 +1030,7 @@ int _write_length(int sockd, const void *buf, int len, const char *file, const c
return ofs; 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; uint32_t msglen, len;
bool retval = false; bool retval = false;
@ -1050,7 +1050,7 @@ bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *fu
goto out; goto out;
} }
msglen = htole32(len); msglen = htole32(len);
ret = wait_write_select(sockd, UNIX_WRITE_TIMEOUT); ret = wait_write_select(sockd, timeout);
if (unlikely(ret < 1)) { if (unlikely(ret < 1)) {
ern = errno; ern = errno;
LOGERR("Select1 failed in send_unix_msg (%d)", ern); 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"); LOGERR("Failed to write 4 byte length in send_unix_msg");
goto out; goto out;
} }
ret = wait_write_select(sockd, UNIX_WRITE_TIMEOUT); ret = wait_write_select(sockd, timeout);
if (unlikely(ret < 1)) { if (unlikely(ret < 1)) {
ern = errno; ern = errno;
LOGERR("Select2 failed in send_unix_msg (%d)", ern); LOGERR("Select2 failed in send_unix_msg (%d)", ern);

4
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); int wait_write_select(int sockd, float timeout);
#define write_length(sockd, buf, len) _write_length(sockd, buf, len, __FILE__, __func__, __LINE__) #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); 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); 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, __FILE__, __func__, __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); 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__) #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); bool _recv_unix_data(int sockd, struct msghdr *msg, const char *file, const char *func, const int line);

Loading…
Cancel
Save