diff --git a/src/ckpool.c b/src/ckpool.c index 9ed16c86..256ae602 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -528,7 +528,7 @@ rewait: ret = 0; goto out; } - ret = wait_recv_select(cs->fd, eom ? 0 : *timeout); + ret = wait_read_select(cs->fd, eom ? 0 : *timeout); polled = true; if (ret < 1) { if (!ret) { diff --git a/src/generator.c b/src/generator.c index 7d1dc1a0..600cc211 100644 --- a/src/generator.c +++ b/src/generator.c @@ -293,7 +293,7 @@ retry: Close(sockd); do { - selret = wait_recv_select(us->sockd, 5); + selret = wait_read_select(us->sockd, 5); if (!selret && !ping_main(ckp)) { LOGEMERG("Generator failed to ping main process, exiting"); ret = 1; @@ -1626,7 +1626,7 @@ retry: ckmsgq_add(gdata->srvchk, proxi->si); do { - selret = wait_recv_select(us->sockd, 5); + selret = wait_read_select(us->sockd, 5); if (!selret && !ping_main(ckp)) { LOGEMERG("Generator failed to ping main process, exiting"); ret = 1; diff --git a/src/libckpool.c b/src/libckpool.c index 50a12089..69918a4a 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -16,6 +16,7 @@ #else #include #endif +#include #include #include #include @@ -905,46 +906,18 @@ int wait_close(int sockd, int timeout) return sfd.revents & (POLLHUP | POLLRDHUP | POLLERR); } -/* Emulate a select read wait for high fds that select doesn't support. - * wait_read_select is for unix sockets and _wait_recv_select for regular - * sockets. */ -int _wait_read_select(int *sockd, float timeout) +/* Emulate a select read wait for high fds that select doesn't support. */ +int wait_read_select(int sockd, float timeout) { - struct pollfd sfd; - int ret = -1; - - if (unlikely(*sockd < 0)) - goto out; - sfd.fd = *sockd; - sfd.events = POLLIN | POLLRDHUP; - timeout *= 1000; - ret = poll(&sfd, 1, timeout); - if (ret > 0 && sfd.revents & (POLLERR)) { - ret = -1; - _Close(sockd); - } -out: - return ret; -} - -int _wait_recv_select(int *sockd, float timeout) -{ - struct pollfd sfd; - int ret = -1; + struct epoll_event event; + int epfd, ret; - if (unlikely(*sockd < 0)) - goto out; - sfd.fd = *sockd; - sfd.events = POLLIN | POLLRDHUP; + epfd = epoll_create1(EPOLL_CLOEXEC); + event.events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT; + epoll_ctl(epfd, EPOLL_CTL_ADD, sockd, &event); timeout *= 1000; - ret = poll(&sfd, 1, timeout); - /* If POLLRDHUP occurs, we may still have data to read so let recv() - * after this determine if the socket can still be used. */ - if (ret > 0 && sfd.revents & (POLLHUP | POLLERR)) { - ret = -1; - _Close(sockd); - } -out: + ret = epoll_wait(epfd, &event, 1, timeout); + close(epfd); return ret; } diff --git a/src/libckpool.h b/src/libckpool.h index 222ce26f..9d8ba341 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -496,10 +496,7 @@ int _open_unix_server(const char *server_path, const char *file, const char *fun 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, float timeout); -#define wait_read_select(SOCKD, TIMEOUT) _wait_read_select(&(SOCKD), TIMEOUT) -int _wait_recv_select(int *sockd, float timeout); -#define wait_recv_select(SOCKD, TIMEOUT) _wait_recv_select(&(SOCKD), TIMEOUT) +int wait_read_select(int sockd, float 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); #define RECV_UNIX_TIMEOUT1 30