MINOR: stream-interface: introduce si_reset() and si_set_state()

The first function is used to (re)initialize a stream interface and
the second to force it into a known state. These are intended for
cleaning up the stream interface initialization code in session.c
and peers.c and avoiding future issues with missing initializations.
This commit is contained in:
Willy Tarreau 2013-10-24 11:51:38 +02:00
parent f79c8171b2
commit 3ed35ef05b
3 changed files with 39 additions and 31 deletions

View File

@ -46,6 +46,30 @@ struct task *stream_int_register_handler(struct stream_interface *si,
struct si_applet *app);
void stream_int_unregister_handler(struct stream_interface *si);
/* initializes a stream interface in the SI_ST_INI state. It's detached from
* any endpoint and is only attached to an owner (generally a task).
*/
static inline void si_reset(struct stream_interface *si, void *owner)
{
si->owner = owner;
si->err_type = SI_ET_NONE;
si->conn_retries = 0; /* used for logging too */
si->send_proxy_ofs = 0;
si->exp = TICK_ETERNITY;
si->flags = SI_FL_NONE;
si->end = NULL;
si->state = si->prev_state = SI_ST_INI;
}
/* sets the current and previous state of a stream interface to <state>. This
* is mainly used to create one in the established state on incoming
* conncetions.
*/
static inline void si_set_state(struct stream_interface *si, int state)
{
si->state = si->prev_state = state;
}
static inline void si_prepare_none(struct stream_interface *si)
{
si->ops = &si_embedded_ops;

View File

@ -1164,12 +1164,9 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
s->req = s->rep = NULL; /* will be allocated later */
s->si[0].conn = NULL;
s->si[0].owner = t;
s->si[0].state = s->si[0].prev_state = SI_ST_EST;
s->si[0].err_type = SI_ET_NONE;
s->si[0].send_proxy_ofs = 0;
s->si[0].exp = TICK_ETERNITY;
s->si[0].flags = SI_FL_NONE;
si_reset(&s->si[0], t);
si_set_state(&s->si[0], SI_ST_EST);
if (s->fe->options2 & PR_O2_INDEPSTR)
s->si[0].flags |= SI_FL_INDEP_STR;
@ -1177,13 +1174,12 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
s->si[0].appctx.st0 = PEER_SESSION_CONNECT;
s->si[0].appctx.ctx.peers.ptr = (void *)ps;
s->si[1].owner = t;
s->si[1].state = s->si[1].prev_state = SI_ST_ASS;
si_reset(&s->si[1], t);
/* initiate an outgoing connection */
si_set_state(&s->si[1], SI_ST_ASS);
s->si[1].conn_retries = p->conn_retries;
s->si[1].err_type = SI_ET_NONE;
s->si[1].send_proxy_ofs = 0;
s->si[1].exp = TICK_ETERNITY;
s->si[1].flags = SI_FL_NONE;
if (s->be->options2 & PR_O2_INDEPSTR)
s->si[1].flags |= SI_FL_INDEP_STR;

View File

@ -426,6 +426,12 @@ int session_complete(struct session *s)
LIST_INIT(&s->back_refs);
/* attach the incoming connection to the stream interface now */
si_reset(&s->si[0], t);
si_set_state(&s->si[0], SI_ST_EST);
if (likely(s->fe->options2 & PR_O2_INDEPSTR))
s->si[0].flags |= SI_FL_INDEP_STR;
s->si[0].conn = conn;
si_prepare_conn(&s->si[0], l->proto, l->xprt);
@ -463,28 +469,10 @@ int session_complete(struct session *s)
s->stkctr[i].table->data_arg[STKTABLE_DT_SESS_RATE].u, 1);
}
/* this part should be common with other protocols */
s->si[0].owner = t;
s->si[0].state = s->si[0].prev_state = SI_ST_EST;
s->si[0].err_type = SI_ET_NONE;
s->si[0].send_proxy_ofs = 0;
s->si[0].exp = TICK_ETERNITY;
s->si[0].flags = SI_FL_NONE;
if (likely(s->fe->options2 & PR_O2_INDEPSTR))
s->si[0].flags |= SI_FL_INDEP_STR;
/* pre-initialize the other side's stream interface to an INIT state. The
* callbacks will be initialized before attempting to connect.
*/
s->si[1].owner = t;
s->si[1].state = s->si[1].prev_state = SI_ST_INI;
s->si[1].err_type = SI_ET_NONE;
s->si[1].conn_retries = 0; /* used for logging too */
s->si[1].send_proxy_ofs = 0;
s->si[1].exp = TICK_ETERNITY;
s->si[1].flags = SI_FL_NONE;
si_reset(&s->si[1], t);
conn_init(s->si[1].conn);
s->si[1].conn->target = NULL;
si_prepare_none(&s->si[1]);