From e5f72b87542d9e848be75408d83ab96fb5ab47e2 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 25 Nov 2022 16:15:20 +0100 Subject: [PATCH] DEV: tcploop: add support for POLLRDHUP when supported This is just in order to closer match what haproxy does. --- dev/tcploop/tcploop.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dev/tcploop/tcploop.c b/dev/tcploop/tcploop.c index 43e171d86..9956835a9 100644 --- a/dev/tcploop/tcploop.c +++ b/dev/tcploop/tcploop.c @@ -24,6 +24,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#define _GNU_SOURCE // for POLLRDHUP #include #include #include @@ -50,6 +51,11 @@ #include #include +/* for OSes which don't have it */ +#ifndef POLLRDHUP +#define POLLRDHUP 0 +#endif + #ifndef MSG_MORE #define MSG_MORE 0 #endif @@ -299,7 +305,7 @@ int addr_to_ss(const char *str, struct sockaddr_storage *ss, struct err_msg *err return 0; } -/* waits up to milliseconds on fd for events (POLLIN|POLLOUT). +/* waits up to milliseconds on fd for events (POLLIN|POLLRDHUP|POLLOUT). * returns poll's status, or -2 if the poller sets POLLERR. */ int wait_on_fd(int fd, int events, int ms) @@ -538,7 +544,7 @@ int tcp_recv(int sock, const char *arg) dolog("recv %d\n", ret); return -1; } - while (!wait_on_fd(sock, POLLIN, 1000)); + while (!wait_on_fd(sock, POLLIN | POLLRDHUP, 1000)); continue; } dolog("recv %d\n", ret); @@ -636,7 +642,7 @@ int tcp_echo(int sock, const char *arg) dolog("recv %d\n", rcvd); return -1; } - while (!wait_on_fd(sock, POLLIN, 1000)); + while (!wait_on_fd(sock, POLLIN | POLLRDHUP, 1000)); continue; } dolog("recv %d\n", rcvd); @@ -690,7 +696,7 @@ int tcp_wait(int sock, const char *arg) } /* FIXME: this doesn't take into account delivered signals */ - ret = wait_on_fd(sock, POLLIN | POLLOUT, delay); + ret = wait_on_fd(sock, POLLIN | POLLRDHUP | POLLOUT, delay); if (ret < 0) return ret; @@ -702,7 +708,7 @@ int tcp_wait_in(int sock, const char *arg) { int ret; - ret = wait_on_fd(sock, POLLIN, 1000); + ret = wait_on_fd(sock, POLLIN | POLLRDHUP, 1000); if (ret < 0) return ret;