From ecdb3fe9f4b27ffe053d34d92a4c37692af49737 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 5 Oct 2017 15:25:48 +0200 Subject: [PATCH] MINOR: conn_stream: modify cs_shut{r,w} API to pass the desired mode 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 | 33 ++++++++------------------------- include/types/connection.h | 4 ++-- src/checks.c | 2 +- src/mux_pt.c | 8 ++++---- src/stream_interface.c | 6 +++--- 5 files changed, 18 insertions(+), 35 deletions(-) diff --git a/include/proto/connection.h b/include/proto/connection.h index e55ec8bef..1ce0b0537 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -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) { diff --git a/include/types/connection.h b/include/types/connection.h index 1b3e73a8c..ff9868e47 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -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 */ diff --git a/src/checks.c b/src/checks.c index 57468e0b3..ee0458dea 100644 --- a/src/checks.c +++ b/src/checks.c @@ -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) diff --git a/src/mux_pt.c b/src/mux_pt.c index 9438d641a..e5d3dff48 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -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)); } /* diff --git a/src/stream_interface.c b/src/stream_interface.c index 5b04b8ea9..42656ca16 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -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; }