MINOR: conn-stream: Rename CS functions dedicated to connections

Some conn-stream functions are only used when there is a connection. Thus,
they was renamed with "cs_conn_" prefix. In addition, we expect to have a
connection, so a BUG_ON is added to be sure the functions are never called
in another context.
diff --git a/include/haproxy/conn_stream.h b/include/haproxy/conn_stream.h
index 4411469..269d129 100644
--- a/include/haproxy/conn_stream.h
+++ b/include/haproxy/conn_stream.h
@@ -167,11 +167,13 @@
 }
 
 /* shut read */
-static inline void cs_shutr(struct conn_stream *cs, enum co_shr_mode mode)
+static inline void cs_conn_shutr(struct conn_stream *cs, enum co_shr_mode mode)
 {
 	const struct mux_ops *mux;
 
-	if (!cs_conn(cs) || cs->endp->flags & CS_EP_SHR)
+	BUG_ON(!cs_conn(cs));
+
+	if (cs->endp->flags & CS_EP_SHR)
 		return;
 
 	/* clean data-layer shutdown */
@@ -182,11 +184,13 @@
 }
 
 /* shut write */
-static inline void cs_shutw(struct conn_stream *cs, enum co_shw_mode mode)
+static inline void cs_conn_shutw(struct conn_stream *cs, enum co_shw_mode mode)
 {
 	const struct mux_ops *mux;
 
-	if (!cs_conn(cs) || cs->endp->flags & CS_EP_SHW)
+	BUG_ON(!cs_conn(cs));
+
+	if (cs->endp->flags & CS_EP_SHW)
 		return;
 
 	/* clean data-layer shutdown */
@@ -197,17 +201,17 @@
 }
 
 /* completely close a conn_stream (but do not detach it) */
-static inline void cs_close(struct conn_stream *cs)
+static inline void cs_conn_close(struct conn_stream *cs)
 {
-	cs_shutw(cs, CO_SHW_SILENT);
-	cs_shutr(cs, CO_SHR_RESET);
+	cs_conn_shutw(cs, CO_SHW_SILENT);
+	cs_conn_shutr(cs, CO_SHR_RESET);
 }
 
 /* completely close a conn_stream after draining possibly pending data (but do not detach it) */
-static inline void cs_drain_and_close(struct conn_stream *cs)
+static inline void cs_conn_drain_and_close(struct conn_stream *cs)
 {
-	cs_shutw(cs, CO_SHW_SILENT);
-	cs_shutr(cs, CO_SHR_DRAIN);
+	cs_conn_shutw(cs, CO_SHW_SILENT);
+	cs_conn_shutr(cs, CO_SHR_DRAIN);
 }
 
 /* sets CS_EP_ERROR or CS_EP_ERR_PENDING on the cs */
@@ -228,9 +232,11 @@
  * conn_stream, NULL is returned. The output pointer is purposely marked
  * const to discourage the caller from modifying anything there.
  */
-static inline const struct conn_stream *cs_get_first(const struct connection *conn)
+static inline const struct conn_stream *cs_conn_get_first(const struct connection *conn)
 {
-	if (!conn || !conn->mux || !conn->mux->get_first_cs)
+	BUG_ON(!conn || !conn->mux);
+
+	if (!conn->mux->get_first_cs)
 		return NULL;
 	return conn->mux->get_first_cs(conn);
 }
diff --git a/src/check.c b/src/check.c
index 058b233..f0793fe 100644
--- a/src/check.c
+++ b/src/check.c
@@ -1053,11 +1053,12 @@
 		/* Check complete or aborted. If connection not yet closed do it
 		 * now and wake the check task up to be sure the result is
 		 * handled ASAP. */
-		cs_drain_and_close(cs);
 		ret = -1;
-
-		if (check->wait_list.events)
-			conn->mux->unsubscribe(cs, check->wait_list.events, &check->wait_list);
+		if (conn)  {
+			cs_conn_drain_and_close(cs);
+			if (check->wait_list.events)
+				conn->mux->unsubscribe(cs, check->wait_list.events, &check->wait_list);
+		}
 
 		/* We may have been scheduled to run, and the
 		 * I/O handler expects to have a cs, so remove
@@ -1192,7 +1193,7 @@
 		 * as a failed response coupled with "observe layer7" caused the
 		 * server state to be suddenly changed.
 		 */
-		cs_drain_and_close(check->cs);
+		cs_conn_drain_and_close(check->cs);
 	}
 
 	/* TODO: must be handled by cs_detach_endp */
diff --git a/src/stream_interface.c b/src/stream_interface.c
index d206e9c..68df64f 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -314,7 +314,7 @@
 		/* If there is no mux attached to the connection, it means the
 		 * connection context is a conn-stream.
 		 */
-		cs = (conn->mux ? cs_get_first(conn) : conn->ctx);
+		cs = (conn->mux ? cs_conn_get_first(conn) : conn->ctx);
 
 		/* The target server expects a PROXY line to be sent first.
 		 * If the send_proxy_ofs is negative, it corresponds to the
@@ -1006,7 +1006,7 @@
 		return;
 
 	if (si_oc(si)->flags & CF_SHUTW) {
-		cs_close(cs);
+		cs_conn_close(cs);
 		cs->state = CS_ST_DIS;
 		__cs_strm(cs)->conn_exp = TICK_ETERNITY;
 	}
@@ -1063,7 +1063,7 @@
 			 * option abortonclose. No need for the TLS layer to try to
 			 * emit a shutdown message.
 			 */
-			cs_shutw(cs, CO_SHW_SILENT);
+			cs_conn_shutw(cs, CO_SHW_SILENT);
 		}
 		else {
 			/* clean data-layer shutdown. This only happens on the
@@ -1072,7 +1072,7 @@
 			 * while option abortonclose is set. We want the TLS
 			 * layer to try to signal it to the peer before we close.
 			 */
-			cs_shutw(cs, CO_SHW_NORMAL);
+			cs_conn_shutw(cs, CO_SHW_NORMAL);
 
 			if (!(ic->flags & (CF_SHUTR|CF_DONT_READ)))
 				return;
@@ -1083,7 +1083,7 @@
 		/* we may have to close a pending connection, and mark the
 		 * response buffer as shutr
 		 */
-		cs_close(cs);
+		cs_conn_close(cs);
 		/* fall through */
 	case CS_ST_CER:
 	case CS_ST_QUE:
@@ -1567,7 +1567,7 @@
 	if (cs->flags & CS_FL_NOHALF) {
 		/* we want to immediately forward this close to the write side */
 		/* force flag on ssl to keep stream in cache */
-		cs_shutw(cs, CO_SHW_SILENT);
+		cs_conn_shutw(cs, CO_SHW_SILENT);
 		goto do_close;
 	}
 
@@ -1576,7 +1576,7 @@
 
  do_close:
 	/* OK we completely close the socket here just as if we went through si_shut[rw]() */
-	cs_close(cs);
+	cs_conn_close(cs);
 
 	oc->flags &= ~CF_SHUTW_NOW;
 	oc->flags |= CF_SHUTW;