From a553ae96f56070c9dada03d2598177ccca5b2689 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 5 Oct 2017 18:52:17 +0200 Subject: [PATCH] MEDIUM: connection: replace conn_full_close() with cs_close() At all call places where a conn_stream is in use, we can now use cs_close() to get rid of a conn_stream and of its underlying connection if the mux estimates it makes sense. This is what is currently being done for the pass-through mux. --- src/checks.c | 9 ++++----- src/stream.c | 4 ++-- src/stream_interface.c | 32 +++++++++----------------------- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/checks.c b/src/checks.c index ee0458deaa..49d9467032 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1400,7 +1400,7 @@ static int wake_srv_chk(struct conn_stream *cs) * sure want to abort the hard way. */ conn_sock_drain(conn); - conn_full_close(conn); + cs_close(cs); ret = -1; } @@ -2207,7 +2207,7 @@ static struct task *process_chk_conn(struct task *t) * server state to be suddenly changed. */ conn_sock_drain(conn); - conn_full_close(conn); + cs_close(cs); } if (conn) { @@ -2686,9 +2686,8 @@ static int tcpcheck_main(struct check *check) * 3: release and replace the old one on success */ if (check->cs) { - /* XXX: need to kill all CS here as well but not to free them yet */ - conn_full_close(check->cs->conn); - retcode = -1; /* do not reuse the fd! */ + cs_close(check->cs); + retcode = -1; /* do not reuse the fd in the caller! */ } /* mark the step as started */ diff --git a/src/stream.c b/src/stream.c index 722d2f4fd6..d347f472f7 100644 --- a/src/stream.c +++ b/src/stream.c @@ -579,7 +579,7 @@ static int sess_update_st_con_tcp(struct stream *s) struct stream_interface *si = &s->si[1]; struct channel *req = &s->req; struct channel *rep = &s->res; - struct connection *srv_conn = __objt_cs(si->end)->conn; + struct conn_stream *srv_cs = __objt_cs(si->end); /* If we got an error, or if nothing happened and the connection timed * out, we must give up. The CER state handler will take care of retry @@ -602,7 +602,7 @@ static int sess_update_st_con_tcp(struct stream *s) /* XXX cognet: do we really want to kill the connection here ? * Probably not for multiple streams. */ - conn_full_close(srv_conn); + cs_close(srv_cs); if (si->err_type) return 0; diff --git a/src/stream_interface.c b/src/stream_interface.c index 9353d08ebf..2c48b031b6 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -821,8 +821,7 @@ static void stream_int_shutr_conn(struct stream_interface *si) return; if (si_oc(si)->flags & CF_SHUTW) { - /* XXX: should just close cs ? */ - conn_full_close(conn); + cs_close(cs); si->state = SI_ST_DIS; si->exp = TICK_ETERNITY; } @@ -890,22 +889,13 @@ static void stream_int_shutw_conn(struct stream_interface *si) * layer to try to signal it to the peer before we close. */ cs_shutw(cs, CS_SHW_NORMAL); - conn_sock_shutw(conn); - /* If the stream interface is configured to disable half-open - * connections, we'll skip the shutdown(), but only if the - * read size is already closed. Otherwise we can't support - * closed write with pending read (eg: abortonclose while - * waiting for the server). - */ - if (!(si->flags & SI_FL_NOHALF) || !(ic->flags & (CF_SHUTR|CF_DONT_READ))) { - if (!(ic->flags & (CF_SHUTR|CF_DONT_READ))) { - /* OK just a shutw, but we want the caller - * to disable polling on this FD if exists. - */ - conn_cond_update_polling(conn); - return; - } + if (!(ic->flags & (CF_SHUTR|CF_DONT_READ))) { + /* OK just a shutw, but we want the caller + * to disable polling on this FD if exists. + */ + conn_cond_update_polling(conn); + return; } } @@ -914,7 +904,7 @@ static void stream_int_shutw_conn(struct stream_interface *si) /* we may have to close a pending connection, and mark the * response buffer as shutr */ - conn_full_close(conn); + cs_close(cs); /* fall through */ case SI_ST_CER: case SI_ST_QUE: @@ -1369,11 +1359,7 @@ void stream_sock_read0(struct stream_interface *si) do_close: /* OK we completely close the socket here just as if we went through si_shut[rw]() */ - conn_full_close(cs->conn); - - ic->flags &= ~CF_SHUTR_NOW; - ic->flags |= CF_SHUTR; - ic->rex = TICK_ETERNITY; + cs_close(cs); oc->flags &= ~CF_SHUTW_NOW; oc->flags |= CF_SHUTW; -- 2.39.5