Browse Source

Wait for the other end to close a unix socket to ensure the message has gone through

master
Con Kolivas 10 years ago
parent
commit
90c682177f
  1. 2
      src/ckpool.c
  2. 14
      src/libckpool.c
  3. 1
      src/libckpool.h

2
src/ckpool.c

@ -526,6 +526,8 @@ bool _send_proc(proc_instance_t *pi, const char *msg, const char *file, const ch
else
ret = true;
shutdown(sockd, SHUT_WR);
if (!wait_close(sockd, 5))
LOGWARNING("send_proc did not close from %s %s:%d", file, func, line);
out:
if (unlikely(!ret)) {
LOGERR("Failure in send_proc from %s %s:%d", file, func, line);

14
src/libckpool.c

@ -910,6 +910,20 @@ out:
return sockd;
}
/* Wait till a socket has been closed at the other end */
int wait_close(int sockd, int timeout)
{
struct pollfd sfd;
if (unlikely(sockd < 0))
return -1;
sfd.fd = sockd;
sfd.events = POLLHUP;
sfd.revents = 0;
timeout *= 1000;
return poll(&sfd, 1, timeout);
}
/* Emulate a select read wait for high fds that select doesn't support */
int wait_read_select(int sockd, int timeout)
{

1
src/libckpool.h

@ -493,6 +493,7 @@ int _open_unix_server(const char *server_path, const char *file, const char *fun
#define open_unix_server(server_path) _open_unix_server(server_path, __FILE__, __func__, __LINE__)
int _open_unix_client(const char *server_path, const char *file, const char *func, const int line);
#define open_unix_client(server_path) _open_unix_client(server_path, __FILE__, __func__, __LINE__)
int wait_close(int sockd, int timeout);
int wait_read_select(int sockd, int timeout);
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);

Loading…
Cancel
Save