From 8b6fc3d10e6319821353095d56b0c6a8c70f2713 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 13 Oct 2020 16:34:19 +0200 Subject: [PATCH] MINOR: proto-tcp: make use of connect(AF_UNSPEC) for the pause Currently the suspend/resume mechanism for listeners only works on Linux and we resort to a number of tricks involving shutdown+listen+shutdown to try to detect failures on other operating systems that do not support it. But on Linux connect(AF_UNSPEC) also works pretty well and is much cleaner. It still doesn't work on other operating systems but the error is easier to detect and appears safer. So let's switch to this. --- src/proto_tcp.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 9e6a3d722..aadac7c07 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -770,17 +770,12 @@ static void tcp_disable_listener(struct listener *l) */ static int tcp_suspend_receiver(struct receiver *rx) { - struct listener *l = LIST_ELEM(rx, struct listener *, rx); socklen_t opt_val, opt_len; + struct sockaddr sa; - if (shutdown(rx->fd, SHUT_WR) != 0) - goto check_already_done; /* usually Solaris fails here */ - - if (listen(rx->fd, listener_backlog(l)) != 0) - goto check_already_done; /* Usually OpenBSD fails here */ - - if (shutdown(rx->fd, SHUT_RD) != 0) - goto check_already_done; /* show always be OK */ + sa.sa_family = AF_UNSPEC; + if (connect(rx->fd, &sa, sizeof(sa)) < 0) + goto check_already_done; fd_stop_recv(rx->fd); return 1; -- 2.47.3