MEDIUM: stconn: Use only one SC function to shut connection endpoints

The SC API to perform shutdowns on connection endpoints was unified to have
only one function, sc_conn_shut(), with read/write shut modes passed
explicitly. It means sc_conn_shutr() and sc_conn_shutw() were removed. The
next step is to do the same at the mux level.
This commit is contained in:
Christopher Faulet 2024-04-16 17:42:38 +02:00
parent 61fbbbe42f
commit c96a873ba3
3 changed files with 18 additions and 46 deletions

View File

@ -318,52 +318,25 @@ static inline const char *sc_get_data_name(const struct stconn *sc)
return sc->app_ops->name;
}
/* shut read */
static inline void sc_conn_shutr(struct stconn *sc, enum se_shut_mode mode)
static inline void sc_conn_shut(struct stconn *sc, enum se_shut_mode mode)
{
const struct mux_ops *mux;
BUG_ON(!sc_conn(sc));
if (sc_ep_test(sc, SE_FL_SHR))
return;
/* clean data-layer shutdown */
mux = sc_mux_ops(sc);
if (mux && mux->shutr)
mux->shutr(sc, mode);
sc_ep_set(sc, (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
}
/* shut write */
static inline void sc_conn_shutw(struct stconn *sc, enum se_shut_mode mode)
{
const struct mux_ops *mux;
if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !sc_ep_test(sc, SE_FL_SHW)) {
if (mux && mux->shutw)
mux->shutw(sc, mode);
sc_ep_set(sc, (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
}
BUG_ON(!sc_conn(sc));
if (sc_ep_test(sc, SE_FL_SHW))
return;
/* clean data-layer shutdown */
mux = sc_mux_ops(sc);
if (mux && mux->shutw)
mux->shutw(sc, mode);
sc_ep_set(sc, (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
}
/* completely close a stream connector (but do not detach it) */
static inline void sc_conn_shut(struct stconn *sc)
{
sc_conn_shutw(sc, SE_SHW_SILENT);
sc_conn_shutr(sc, SE_SHR_RESET);
}
/* completely close a stream connector after draining possibly pending data (but do not detach it) */
static inline void sc_conn_drain_and_shut(struct stconn *sc)
{
sc_conn_shutw(sc, SE_SHW_SILENT);
sc_conn_shutr(sc, SE_SHR_DRAIN);
if ((mode & (SE_SHR_RESET|SE_SHR_DRAIN)) && !sc_ep_test(sc, SE_FL_SHR)) {
if (mux && mux->shutr)
mux->shutr(sc, mode);
sc_ep_set(sc, (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
}
}
/* Returns non-zero if the stream connector's Rx path is blocked because of
@ -572,7 +545,7 @@ static inline size_t se_done_ff(struct sedesc *se)
sc_ep_report_blocked_send(se->sc, 0);
if (se->iobuf.flags & IOBUF_FL_FF_BLOCKED) {
sc_ep_report_blocked_send(se->sc, 0);
if (!(se->sc->wait_event.events & SUB_RETRY_SEND)) {
/* The SC must be subs for send to be notify when some
* space is made

View File

@ -1382,7 +1382,7 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
* as a failed response coupled with "observe layer7" caused the
* server state to be suddenly changed.
*/
sc_conn_drain_and_shut(sc);
sc_conn_shut(sc, SE_SHR_DRAIN|SE_SHW_SILENT);
}
if (sc) {

View File

@ -700,7 +700,7 @@ static void sc_app_abort_conn(struct stconn *sc)
return;
if (sc->flags & SC_FL_SHUT_DONE) {
sc_conn_shut(sc);
sc_conn_shut(sc, SE_SHR_RESET|SE_SHW_SILENT);
sc->state = SC_ST_DIS;
if (sc->flags & SC_FL_ISBACK)
__sc_strm(sc)->conn_exp = TICK_ETERNITY;
@ -742,12 +742,11 @@ static void sc_app_shut_conn(struct stconn *sc)
* no risk so we close both sides immediately.
*/
if (!(sc->flags & (SC_FL_NOLINGER|SC_FL_EOS|SC_FL_ABRT_DONE)) && !(ic->flags & CF_DONT_READ)) {
sc_conn_shutw(sc, SE_SHW_NORMAL);
sc_conn_shut(sc, SE_SHW_NORMAL);
return;
}
sc_conn_shutw(sc, (sc->flags & SC_FL_NOLINGER) ? SE_SHW_SILENT : SE_SHW_NORMAL);
sc_conn_shut(sc);
sc_conn_shut(sc, SE_SHR_RESET|((sc->flags & SC_FL_NOLINGER) ? SE_SHW_SILENT : SE_SHW_NORMAL));
sc->state = SC_ST_DIS;
break;
@ -755,7 +754,7 @@ static void sc_app_shut_conn(struct stconn *sc)
/* we may have to close a pending connection, and mark the
* response buffer as abort
*/
sc_conn_shut(sc);
sc_conn_shut(sc, SE_SHR_RESET|SE_SHW_SILENT);
sc->state = SC_ST_DIS;
break;
case SC_ST_CER:
@ -1203,7 +1202,7 @@ static void sc_conn_eos(struct stconn *sc)
do_close:
/* OK we completely close the socket here just as if we went through sc_shut[rw]() */
sc_conn_shut(sc);
sc_conn_shut(sc, SE_SHR_RESET|SE_SHW_SILENT);
sc->flags &= ~SC_FL_SHUT_WANTED;
sc->flags |= SC_FL_SHUT_DONE;