Browse Source

allow ckpmsg to set the unix recv timeout

master
kanoi 10 years ago
parent
commit
063d723a31
  1. 12
      src/ckpmsg.c
  2. 6
      src/libckpool.c
  3. 8
      src/libckpool.h

12
src/ckpmsg.c

@ -19,9 +19,11 @@ int main(int argc, char **argv)
{ {
char *name = NULL, *socket_dir = NULL, *buf = NULL; char *name = NULL, *socket_dir = NULL, *buf = NULL;
bool proxy = false; bool proxy = false;
int tmo1 = RECV_UNIX_TIMEOUT1;
int tmo2 = RECV_UNIX_TIMEOUT2;
int c; int c;
while ((c = getopt(argc, argv, "n:s:p")) != -1) { while ((c = getopt(argc, argv, "n:s:pt:T:")) != -1) {
switch(c) { switch(c) {
case 'n': case 'n':
name = strdup(optarg); name = strdup(optarg);
@ -32,6 +34,12 @@ int main(int argc, char **argv)
case 'p': case 'p':
proxy = true; proxy = true;
break; break;
case 't':
tmo1 = atoi(optarg);
break;
case 'T':
tmo2 = atoi(optarg);
break;
} }
} }
if (!socket_dir) if (!socket_dir)
@ -76,7 +84,7 @@ int main(int argc, char **argv)
break; break;
} }
dealloc(buf); dealloc(buf);
buf = recv_unix_msg(sockd); buf = recv_unix_msg_tmo2(sockd, tmo1, tmo2);
close(sockd); close(sockd);
if (!buf) { if (!buf) {
LOGERR("Received empty message"); LOGERR("Received empty message");

6
src/libckpool.c

@ -739,13 +739,13 @@ int read_length(int sockd, void *buf, int len)
/* Use a standard message across the unix sockets: /* Use a standard message across the unix sockets:
* 4 byte length of message as little endian encoded uint32_t followed by the * 4 byte length of message as little endian encoded uint32_t followed by the
* string. Return NULL in case of failure. */ * string. Return NULL in case of failure. */
char *_recv_unix_msg(int sockd, const char *file, const char *func, const int line) char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, const char *func, const int line)
{ {
char *buf = NULL; char *buf = NULL;
uint32_t msglen; uint32_t msglen;
int ret; int ret;
ret = wait_read_select(sockd, 30); ret = wait_read_select(sockd, timeout1);
if (unlikely(ret < 1)) { if (unlikely(ret < 1)) {
LOGERR("Select1 failed in recv_unix_msg"); LOGERR("Select1 failed in recv_unix_msg");
goto out; goto out;
@ -761,7 +761,7 @@ char *_recv_unix_msg(int sockd, const char *file, const char *func, const int li
LOGWARNING("Invalid message length %u sent to recv_unix_msg", msglen); LOGWARNING("Invalid message length %u sent to recv_unix_msg", msglen);
goto out; goto out;
} }
ret = wait_read_select(sockd, 5); ret = wait_read_select(sockd, timeout2);
if (unlikely(ret < 1)) { if (unlikely(ret < 1)) {
LOGERR("Select2 failed in recv_unix_msg"); LOGERR("Select2 failed in recv_unix_msg");
goto out; goto out;

8
src/libckpool.h

@ -441,8 +441,12 @@ int _open_unix_client(const char *server_path, const char *file, const char *fun
#define open_unix_client(server_path) _open_unix_client(server_path, __FILE__, __func__, __LINE__) #define open_unix_client(server_path) _open_unix_client(server_path, __FILE__, __func__, __LINE__)
int wait_read_select(int sockd, int timeout); int wait_read_select(int sockd, int timeout);
int read_length(int sockd, void *buf, int len); int read_length(int sockd, void *buf, int len);
char *_recv_unix_msg(int sockd, const char *file, const char *func, const int line); char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, const char *func, const int line);
#define recv_unix_msg(sockd) _recv_unix_msg(sockd, __FILE__, __func__, __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_tmo2(sockd, tmo1, tmo2) _recv_unix_msg(sockd, tmo1, tmo2, __FILE__, __func__, __LINE__)
int wait_write_select(int sockd, int timeout); int wait_write_select(int sockd, int timeout);
int write_length(int sockd, const void *buf, int len); int write_length(int sockd, const void *buf, int len);
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, const char *file, const char *func, const int line);

Loading…
Cancel
Save