From: Willy Tarreau Date: Wed, 4 Nov 2020 12:59:04 +0000 (+0100) Subject: MEDIUM: listeners: make use of fd_want_recv_safe() to enable early receivers X-Git-Tag: v2.3.0~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4380b211f629237e7ccf22d30bb76ad091ad5f3;p=thirdparty%2Fhaproxy.git MEDIUM: listeners: make use of fd_want_recv_safe() to enable early receivers We used to refrain from calling fd_want_recv() if fd_updt was not allocated but it's not the right solution as this does not allow the FD to be set. Instead, let's use the new fd_want_recv_safe() which will update the FD and create an update entry only if possible. In addition, the equivalent test before calling fd_stop_recv() was removed as totally useless since there's not fd_updt creation in this case. --- diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index f8e673d0b5..cc92753792 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -107,21 +107,19 @@ static void sockpair_add_listener(struct listener *listener, int port) } /* Enable receipt of incoming connections for listener . The receiver must - * still be valid. Does nothing in early boot (needs fd_updt). + * still be valid. */ static void sockpair_enable_listener(struct listener *l) { - if (fd_updt) - fd_want_recv(l->rx.fd); + fd_want_recv_safe(l->rx.fd); } /* Disable receipt of incoming connections for listener . The receiver must - * still be valid. Does nothing in early boot (needs fd_updt). + * still be valid. */ static void sockpair_disable_listener(struct listener *l) { - if (fd_updt) - fd_stop_recv(l->rx.fd); + fd_stop_recv(l->rx.fd); } /* Binds receiver , and assigns rx->iocb and rx->owner as the callback diff --git a/src/proto_tcp.c b/src/proto_tcp.c index e59aa961cb..06adf9b478 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -749,21 +749,19 @@ static void tcpv6_add_listener(struct listener *listener, int port) } /* Enable receipt of incoming connections for listener . The receiver must - * still be valid. Does nothing in early boot (needs fd_updt). + * still be valid. */ static void tcp_enable_listener(struct listener *l) { - if (fd_updt) - fd_want_recv(l->rx.fd); + fd_want_recv_safe(l->rx.fd); } /* Disable receipt of incoming connections for listener . The receiver must - * still be valid. Does nothing in early boot (needs fd_updt). + * still be valid. */ static void tcp_disable_listener(struct listener *l) { - if (fd_updt) - fd_stop_recv(l->rx.fd); + fd_stop_recv(l->rx.fd); } /* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver diff --git a/src/proto_udp.c b/src/proto_udp.c index 0724680a9a..ae5562afb2 100644 --- a/src/proto_udp.c +++ b/src/proto_udp.c @@ -173,21 +173,19 @@ static void udp6_add_listener(struct listener *listener, int port) } /* Enable receipt of incoming connections for listener . The receiver must - * still be valid. Does nothing in early boot (needs fd_updt). + * still be valid. */ static void udp_enable_listener(struct listener *l) { - if (fd_updt) - fd_want_recv(l->rx.fd); + fd_want_recv_safe(l->rx.fd); } /* Disable receipt of incoming connections for listener . The receiver must - * still be valid. Does nothing in early boot (needs fd_updt). + * still be valid. */ static void udp_disable_listener(struct listener *l) { - if (fd_updt) - fd_stop_recv(l->rx.fd); + fd_stop_recv(l->rx.fd); } /* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver diff --git a/src/proto_uxst.c b/src/proto_uxst.c index d33f8c3a7a..f558e5f34b 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -153,21 +153,19 @@ static void uxst_add_listener(struct listener *listener, int port) } /* Enable receipt of incoming connections for listener . The receiver must - * still be valid. Does nothing in early boot (needs fd_updt). + * still be valid. */ static void uxst_enable_listener(struct listener *l) { - if (fd_updt) - fd_want_recv(l->rx.fd); + fd_want_recv_safe(l->rx.fd); } /* Disable receipt of incoming connections for listener . The receiver must - * still be valid. Does nothing in early boot (needs fd_updt). + * still be valid. */ static void uxst_disable_listener(struct listener *l) { - if (fd_updt) - fd_stop_recv(l->rx.fd); + fd_stop_recv(l->rx.fd); } /* Suspend a receiver. Returns < 0 in case of failure, 0 if the receiver diff --git a/src/sock.c b/src/sock.c index 192559bfbf..3e2f208879 100644 --- a/src/sock.c +++ b/src/sock.c @@ -186,21 +186,17 @@ int sock_create_server_socket(struct connection *conn) return my_socketat(ns, conn->dst->ss_family, SOCK_STREAM, 0); } -/* Enables receiving on receiver once already bound. Does nothing in early - * boot (needs fd_updt). - */ +/* Enables receiving on receiver once already bound. */ void sock_enable(struct receiver *rx) { - if (rx->flags & RX_F_BOUND && fd_updt) - fd_want_recv(rx->fd); + if (rx->flags & RX_F_BOUND) + fd_want_recv_safe(rx->fd); } -/* Disables receiving on receiver once already bound. Does nothing in early - * boot (needs fd_updt). - */ +/* Disables receiving on receiver once already bound. */ void sock_disable(struct receiver *rx) { - if (rx->flags & RX_F_BOUND && fd_updt) + if (rx->flags & RX_F_BOUND) fd_stop_recv(rx->fd); }