]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: protocol: implement an ->rx_resume() method
authorWilly Tarreau <w@1wt.eu>
Fri, 25 Sep 2020 17:40:31 +0000 (19:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 09:27:30 +0000 (11:27 +0200)
This one undoes ->rx_suspend(), it tries to restore an operational socket.
It was only implemented for TCP since it's the only one we support right
now.

include/haproxy/protocol-t.h
src/proto_tcp.c

index 75da65b4687b112b8d035ace16b6b7b12b48a212..3d5ce82cdc4ac88fa57f5d32d193d194c4d75a6b 100644 (file)
@@ -74,8 +74,9 @@ struct proto_fam {
 
 /* This structure contains all information needed to easily handle a protocol.
  * Its primary goal is to ease listeners maintenance. Specifically, the
- * bind() primitive must be used before any fork(). rx_* may be null if the
- * protocol doesn't provide direct access to the receiver.
+ * bind() primitive must be used before any fork(). rx_suspend()/rx_resume()
+ * return >0 on success, 0 if rx stopped, -1 on failure to proceed. rx_* may
+ * be null if the protocol doesn't provide direct access to the receiver.
  */
 struct protocol {
        char name[PROTO_NAME_LEN];                      /* protocol name, zero-terminated */
@@ -91,6 +92,7 @@ struct protocol {
 
        /* functions acting on the receiver */
        int (*rx_suspend)(struct receiver *rx);         /* temporarily suspend this receiver for a soft restart */
+       int (*rx_resume)(struct receiver *rx);          /* try to resume a temporarily suspended receiver */
 
        /* functions acting on connections */
        void (*accept)(int fd);                         /* generic accept function */
index b3dbdd467d06145db2567abd601a2939ebf3793a..5aa7bfd60f712f609a69d0228aa602bfe5548164 100644 (file)
@@ -46,6 +46,7 @@
 
 static int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen);
 static int tcp_suspend_receiver(struct receiver *rx);
+static int tcp_resume_receiver(struct receiver *rx);
 static void tcpv4_add_listener(struct listener *listener, int port);
 static void tcpv6_add_listener(struct listener *listener, int port);
 
@@ -60,6 +61,7 @@ static struct protocol proto_tcpv4 = {
        .add = tcpv4_add_listener,
        .listen = tcp_bind_listener,
        .rx_suspend = tcp_suspend_receiver,
+       .rx_resume = tcp_resume_receiver,
        .accept = &listener_accept,
        .connect = tcp_connect_server,
        .receivers = LIST_HEAD_INIT(proto_tcpv4.receivers),
@@ -79,6 +81,7 @@ static struct protocol proto_tcpv6 = {
        .add = tcpv6_add_listener,
        .listen = tcp_bind_listener,
        .rx_suspend = tcp_suspend_receiver,
+       .rx_resume = tcp_resume_receiver,
        .accept = &listener_accept,
        .connect = tcp_connect_server,
        .receivers = LIST_HEAD_INIT(proto_tcpv6.receivers),
@@ -767,6 +770,23 @@ static int tcp_suspend_receiver(struct receiver *rx)
        return -1;
 }
 
+/* Resume a receiver. Returns < 0 in case of failure, 0 if the receiver
+ * was totally stopped, or > 0 if correctly suspended.
+ */
+static int tcp_resume_receiver(struct receiver *rx)
+{
+       struct listener *l = LIST_ELEM(rx, struct listener *, rx);
+
+       if (rx->fd < 0)
+               return 0;
+
+       if (listen(rx->fd, listener_backlog(l)) == 0) {
+               fd_want_recv(l->rx.fd);
+               return 1;
+       }
+       return -1;
+}
+
 
 /*
  * Local variables: