From: Willy Tarreau Date: Fri, 25 Sep 2020 17:00:01 +0000 (+0200) Subject: MINOR: sock: provide a set of generic enable/disable functions X-Git-Tag: v2.3-dev6~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e70c7977f2db37d6228834c98306712fb30f3fd4;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/haproxy/sock.h b/include/haproxy/sock.h index 90dbc07ca1..7000232924 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 3e414a8b9c..c06a28149e 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