]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sock: provide a set of generic enable/disable functions
authorWilly Tarreau <w@1wt.eu>
Fri, 25 Sep 2020 17:00:01 +0000 (19:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 09:27:30 +0000 (11:27 +0200)
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
src/sock.c

index 90dbc07ca1c84ea620f11c01151ec4ec14914dba..70002329249aba01aee29d993f619e4b963b5375 100644 (file)
@@ -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);
index 3e414a8b9ccfb711703c34ae76d932d1ae22149c..c06a28149e79b929dbdd180c97788e82b9ddbc02 100644 (file)
@@ -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 <rx> 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 <rx> 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 <fd>, with <dir> indicating
  * if we're a listener (=0) or an initiator (!=0). It returns 0 in case of