Browse Source

Use epoll for wait_read_select

master
Con Kolivas 9 years ago
parent
commit
83dbc9db12
  1. 2
      src/ckpool.c
  2. 4
      src/generator.c
  3. 47
      src/libckpool.c
  4. 5
      src/libckpool.h

2
src/ckpool.c

@ -528,7 +528,7 @@ rewait:
ret = 0; ret = 0;
goto out; goto out;
} }
ret = wait_recv_select(cs->fd, eom ? 0 : *timeout); ret = wait_read_select(cs->fd, eom ? 0 : *timeout);
polled = true; polled = true;
if (ret < 1) { if (ret < 1) {
if (!ret) { if (!ret) {

4
src/generator.c

@ -293,7 +293,7 @@ retry:
Close(sockd); Close(sockd);
do { do {
selret = wait_recv_select(us->sockd, 5); selret = wait_read_select(us->sockd, 5);
if (!selret && !ping_main(ckp)) { if (!selret && !ping_main(ckp)) {
LOGEMERG("Generator failed to ping main process, exiting"); LOGEMERG("Generator failed to ping main process, exiting");
ret = 1; ret = 1;
@ -1626,7 +1626,7 @@ retry:
ckmsgq_add(gdata->srvchk, proxi->si); ckmsgq_add(gdata->srvchk, proxi->si);
do { do {
selret = wait_recv_select(us->sockd, 5); selret = wait_read_select(us->sockd, 5);
if (!selret && !ping_main(ckp)) { if (!selret && !ping_main(ckp)) {
LOGEMERG("Generator failed to ping main process, exiting"); LOGEMERG("Generator failed to ping main process, exiting");
ret = 1; ret = 1;

47
src/libckpool.c

@ -16,6 +16,7 @@
#else #else
#include <sys/un.h> #include <sys/un.h>
#endif #endif
#include <sys/epoll.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -905,46 +906,18 @@ int wait_close(int sockd, int timeout)
return sfd.revents & (POLLHUP | POLLRDHUP | POLLERR); return sfd.revents & (POLLHUP | POLLRDHUP | POLLERR);
} }
/* Emulate a select read wait for high fds that select doesn't support. /* 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 int wait_read_select(int sockd, float timeout)
* sockets. */
int _wait_read_select(int *sockd, float timeout)
{ {
struct pollfd sfd; struct epoll_event event;
int ret = -1; int epfd, ret;
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;
if (unlikely(*sockd < 0)) epfd = epoll_create1(EPOLL_CLOEXEC);
goto out; event.events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT;
sfd.fd = *sockd; epoll_ctl(epfd, EPOLL_CTL_ADD, sockd, &event);
sfd.events = POLLIN | POLLRDHUP;
timeout *= 1000; timeout *= 1000;
ret = poll(&sfd, 1, timeout); ret = epoll_wait(epfd, &event, 1, timeout);
/* If POLLRDHUP occurs, we may still have data to read so let recv() close(epfd);
* after this determine if the socket can still be used. */
if (ret > 0 && sfd.revents & (POLLHUP | POLLERR)) {
ret = -1;
_Close(sockd);
}
out:
return ret; return ret;
} }

5
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); 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__) #define open_unix_client(server_path) _open_unix_client(server_path, __FILE__, __func__, __LINE__)
int wait_close(int sockd, int timeout); int wait_close(int sockd, int timeout);
int _wait_read_select(int *sockd, float 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 read_length(int sockd, void *buf, int len); 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); char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, const char *func, const int line);
#define RECV_UNIX_TIMEOUT1 30 #define RECV_UNIX_TIMEOUT1 30

Loading…
Cancel
Save