From e70c7977f2db37d6228834c98306712fb30f3fd4 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 25 Sep 2020 19:00:01 +0200 Subject: [PATCH] MINOR: sock: provide a set of generic enable/disable functions These will be used on receivers, to enable or disable receiving on a listener, which most of the time just consists in enabling/disabling the file descriptor. We have to take care of the existence of fd_updt to know if we may or not call fd_{want,stop}_recv() since it's not permitted in very early boot. --- include/haproxy/sock.h | 2 ++ src/sock.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/haproxy/sock.h b/include/haproxy/sock.h index 90dbc07ca..700023292 100644 --- a/include/haproxy/sock.h +++ b/include/haproxy/sock.h @@ -33,6 +33,8 @@ extern struct xfer_sock_list *xfer_sock_list; int sock_create_server_socket(struct connection *conn); +void sock_enable(struct receiver *rx); +void sock_disable(struct receiver *rx); int sock_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir); int sock_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir); int sock_get_old_sockets(const char *unixsocket); diff --git a/src/sock.c b/src/sock.c index 3e414a8b9..c06a28149 100644 --- a/src/sock.c +++ b/src/sock.c @@ -55,6 +55,24 @@ 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). + */ +void sock_enable(struct receiver *rx) +{ + if (rx->flags & RX_F_BOUND && fd_updt) + fd_want_recv(rx->fd); +} + +/* Disables receiving on receiver once already bound. Does nothing in early + * boot (needs fd_updt). + */ +void sock_disable(struct receiver *rx) +{ + if (rx->flags & RX_F_BOUND && fd_updt) + fd_stop_recv(rx->fd); +} + /* * Retrieves the source address for the socket , with indicating * if we're a listener (=0) or an initiator (!=0). It returns 0 in case of