From a4380b211f629237e7ccf22d30bb76ad091ad5f3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 4 Nov 2020 13:59:04 +0100 Subject: [PATCH] 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. --- src/proto_sockpair.c | 10 ++++------ src/proto_tcp.c | 10 ++++------ src/proto_udp.c | 10 ++++------ src/proto_uxst.c | 10 ++++------ src/sock.c | 14 +++++--------- 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index f8e673d0b..cc9275379 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 e59aa961c..06adf9b47 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 0724680a9..ae5562afb 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 d33f8c3a7..f558e5f34 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 192559bfb..3e2f20887 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); }