]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: conn_stream: modify cs_shut{r,w} API to pass the desired mode
authorWilly Tarreau <w@1wt.eu>
Thu, 5 Oct 2017 13:25:48 +0000 (15:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 17:03:23 +0000 (18:03 +0100)
Now we can specify how we want to shutdown (drain vs reset, and normal
vs silent), and this propagates to the mux then the transport layer.

include/proto/connection.h
include/types/connection.h
src/checks.c
src/mux_pt.c
src/stream_interface.c

index e55ec8bef516072f5616291d7726bac2fb799a2a..1ce0b05371e0adea151e7e30d6c27a1539e64345 100644 (file)
@@ -537,45 +537,28 @@ static inline void conn_xprt_shutw_hard(struct connection *c)
                c->xprt->shutw(c, 0);
 }
 
-/* shut read after draining possibly pending data */
-static inline void cs_shutr(struct conn_stream *cs)
+/* shut read */
+static inline void cs_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
 {
        __cs_stop_recv(cs);
 
        /* clean data-layer shutdown */
        if (cs->conn->mux && cs->conn->mux->shutr)
-               cs->conn->mux->shutr(cs, 1);
+               cs->conn->mux->shutr(cs, mode);
+       cs->flags |= (mode == CS_SHR_DRAIN) ? CS_FL_SHRD : CS_FL_SHRR;
 }
 
-/* shut read after disabling lingering */
-static inline void cs_shutr_hard(struct conn_stream *cs)
-{
-       __cs_stop_recv(cs);
-
-       /* clean data-layer shutdown */
-       if (cs->conn->mux && cs->conn->mux->shutr)
-               cs->conn->mux->shutr(cs, 0);
-}
-
-static inline void cs_shutw(struct conn_stream *cs)
+/* shut write */
+static inline void cs_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
 {
        __cs_stop_send(cs);
 
        /* clean data-layer shutdown */
        if (cs->conn->mux && cs->conn->mux->shutw)
-               cs->conn->mux->shutw(cs, 1);
+               cs->conn->mux->shutw(cs, mode);
+       cs->flags |= (mode == CS_SHW_NORMAL) ? CS_FL_SHWN : CS_FL_SHWS;
 }
 
-static inline void cs_shutw_hard(struct conn_stream *cs)
-{
-       __cs_stop_send(cs);
-
-       /* unclean data-layer shutdown */
-       if (cs->conn->mux && cs->conn->mux->shutw)
-               cs->conn->mux->shutw(cs, 0);
-}
-
-
 /* detect sock->data read0 transition */
 static inline int conn_xprt_read0_pending(struct connection *c)
 {
index 1b3e73a8c087663cca9acb810f051a15142583ee..ff9868e4759a31205a1e7f60f0c937085ef50514 100644 (file)
@@ -292,8 +292,8 @@ struct mux_ops {
        int  (*snd_buf)(struct conn_stream *cs, struct buffer *buf, int flags); /* Called from the upper layer to send data */
        int  (*rcv_pipe)(struct conn_stream *cs, struct pipe *pipe, unsigned int count); /* recv-to-pipe callback */
        int  (*snd_pipe)(struct conn_stream *cs, struct pipe *pipe); /* send-to-pipe callback */
-       void (*shutr)(struct conn_stream *cs, int clean); /* shutr function */
-       void (*shutw)(struct conn_stream *cs, int clean); /* shutw function */
+       void (*shutr)(struct conn_stream *cs, enum cs_shr_mode);     /* shutr function */
+       void (*shutw)(struct conn_stream *cs, enum cs_shw_mode);     /* shutw function */
 
        void (*release)(struct connection *conn);     /* release all resources allocated by the mux */
        struct conn_stream *(*attach)(struct connection *); /* Create and attach a conn_stream to an outgoing connection */
index 57468e0b330fe1c371ceba0b1e44860a6a2d4d4f..ee0458deaaa3b4b5f4aef1190733a8f96f830c10 100644 (file)
@@ -1344,7 +1344,7 @@ static void event_srv_chk_r(struct conn_stream *cs)
         * drain pending data.
         */
        __cs_stop_both(cs);
-       cs_shutw(cs);
+       cs_shutw(cs, CS_SHW_NORMAL);
 
        /* OK, let's not stay here forever */
        if (check->result == CHK_RES_FAILED)
index 9438d641add7b0d49d62379f5944a14dea3f8557..e5d3dff4800d934755412e23cf0d1fa63e9468be 100644 (file)
@@ -120,16 +120,16 @@ static void mux_pt_detach(struct conn_stream *cs)
 {
 }
 
-static void mux_pt_shutr(struct conn_stream *cs, int clean)
+static void mux_pt_shutr(struct conn_stream *cs, enum cs_shr_mode mode)
 {
        if (conn_xprt_ready(cs->conn) && cs->conn->xprt->shutr)
-               cs->conn->xprt->shutr(cs->conn, clean);
+               cs->conn->xprt->shutr(cs->conn, (mode == CS_SHR_DRAIN));
 }
 
-static void mux_pt_shutw(struct conn_stream *cs, int clean)
+static void mux_pt_shutw(struct conn_stream *cs, enum cs_shw_mode mode)
 {
        if (conn_xprt_ready(cs->conn) && cs->conn->xprt->shutw)
-               cs->conn->xprt->shutw(cs->conn, clean);
+               cs->conn->xprt->shutw(cs->conn, (mode == CS_SHW_NORMAL));
 }
 
 /*
index 5b04b8ea9801629d5392660e43fa90311d0db1c2..42656ca165a837fe72f85591af58b312fb3a8b27 100644 (file)
@@ -880,7 +880,7 @@ static void stream_int_shutw_conn(struct stream_interface *si)
                         * option abortonclose. No need for the TLS layer to try to
                         * emit a shutdown message.
                         */
-                       cs_shutw_hard(cs);
+                       cs_shutw(cs, CS_SHW_SILENT);
                }
                else {
                        /* clean data-layer shutdown. This only happens on the
@@ -889,7 +889,7 @@ static void stream_int_shutw_conn(struct stream_interface *si)
                         * while option abortonclose is set. We want the TLS
                         * layer to try to signal it to the peer before we close.
                         */
-                       cs_shutw(cs);
+                       cs_shutw(cs, CS_SHW_NORMAL);
 
                        /* If the stream interface is configured to disable half-open
                         * connections, we'll skip the shutdown(), but only if the
@@ -1358,7 +1358,7 @@ void stream_sock_read0(struct stream_interface *si)
        if (si->flags & SI_FL_NOHALF) {
                /* we want to immediately forward this close to the write side */
                /* force flag on ssl to keep stream in cache */
-               cs_shutw_hard(cs);
+               cs_shutw(cs, CS_SHW_SILENT);
                goto do_close;
        }