From d1769b8b9a4d897a17f14ddac4faf400e0713433 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 6 Apr 2015 00:25:48 +0200 Subject: [PATCH] MEDIUM: stream: don't rely on the session's listener anymore in stream_new() When the stream is instanciated from an applet, it doesn't necessarily have a listener. The listener was sparsely used there, just to retrieve the task function, update the listeners' stats, and set the analysers and default target, both of which are often zero from applets. Thus these elements are now initialized with default values that the caller is free to change if desired. --- src/peers.c | 9 --------- src/session.c | 29 +++++++++++++++++++++++------ src/stream.c | 21 +++++++++------------ 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/peers.c b/src/peers.c index 4899ee7a0..d1a06d801 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1166,17 +1166,8 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session conn->target = s->target = &s->be->obj_type; memcpy(&conn->addr.to, &peer->addr, sizeof(conn->addr.to)); s->do_log = NULL; - - /* default error reporting function, may be changed by analysers */ - s->srv_error = default_srv_error; s->uniq_id = 0; - /* note: this should not happen anymore since there's always at least the switching rules */ - if (!s->req.analysers) { - channel_auto_connect(&s->req);/* don't wait to establish connection */ - channel_auto_close(&s->req); /* let the producer forward close requests */ - } - s->req.rto = s->sess->fe->timeout.client; s->req.wto = s->be->timeout.server; s->res.rto = s->be->timeout.server; diff --git a/src/session.c b/src/session.c index 247e4927d..6ae2592fe 100644 --- a/src/session.c +++ b/src/session.c @@ -88,6 +88,7 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr struct connection *cli_conn; struct proxy *p = l->frontend; struct session *sess; + struct stream *strm; struct task *t; int ret; @@ -224,9 +225,15 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr /* OK let's complete stream initialization since there is no handshake */ cli_conn->flags |= CO_FL_CONNECTED; - if (stream_new(sess, t)) - return 1; + strm = stream_new(sess, t); + if (!strm) + goto out_free_task; + strm->target = sess->listener->default_target; + strm->req.analysers = sess->listener->analysers; + return 1; + + out_free_task: task_free(t); out_free_sess: p->feconn--; @@ -369,12 +376,22 @@ static int conn_complete_session(struct connection *conn) { struct task *task = conn->owner; struct session *sess = task->context; + struct stream *strm; - if (!(conn->flags & CO_FL_ERROR) && (stream_new(sess, task) != NULL)) { - conn->flags &= ~CO_FL_INIT_DATA; - return 0; - } + if (conn->flags & CO_FL_ERROR) + goto fail; + task->process = sess->listener->handler; + strm = stream_new(sess, task); + if (!strm) + goto fail; + + strm->target = sess->listener->default_target; + strm->req.analysers = sess->listener->analysers; + conn->flags &= ~CO_FL_INIT_DATA; + return 0; + + fail: session_kill_embryonic(sess); return -1; } diff --git a/src/stream.c b/src/stream.c index dca1c8884..863075b0b 100644 --- a/src/stream.c +++ b/src/stream.c @@ -61,11 +61,12 @@ struct list buffer_wq = LIST_HEAD_INIT(buffer_wq); * be called with an embryonic session. It returns the pointer to the newly * created stream, or NULL in case of fatal error. For now the client-side * end point is taken from the session's origin, which must be valid. + * The task's context is set to the new stream, and its function is set to + * process_stream(). Target and analysers are null. */ struct stream *stream_new(struct session *sess, struct task *t) { struct stream *s; - struct listener *l = sess->listener; struct connection *conn = objt_conn(sess->origin); struct appctx *appctx = objt_appctx(sess->origin); int i; @@ -121,7 +122,7 @@ struct stream *stream_new(struct session *sess, struct task *t) s->unique_id = NULL; s->task = t; - t->process = l->handler; + t->process = process_stream; t->context = s; t->expire = TICK_ETERNITY; @@ -136,7 +137,8 @@ struct stream *stream_new(struct session *sess, struct task *t) s->res_cap = NULL; /* Let's count a stream now */ - proxy_inc_fe_sess_ctr(l, sess->fe); + if (conn) + proxy_inc_fe_sess_ctr(sess->listener, sess->fe); for (i = 0; i < MAX_SESS_STKCTR; i++) { void *ptr; @@ -178,7 +180,7 @@ struct stream *stream_new(struct session *sess, struct task *t) s->si[1].flags |= SI_FL_INDEP_STR; stream_init_srv_conn(s); - s->target = l->default_target; /* used by peers and CLI */ + s->target = NULL; s->pend_pos = NULL; /* init store persistence */ @@ -186,14 +188,9 @@ struct stream *stream_new(struct session *sess, struct task *t) channel_init(&s->req); s->req.flags |= CF_READ_ATTACHED; /* the producer is already connected */ - - /* activate default analysers enabled for this listener */ - s->req.analysers = l->analysers; - - if (!s->req.analysers) { - channel_auto_connect(&s->req); /* don't wait to establish connection */ - channel_auto_close(&s->req); /* let the producer forward close requests */ - } + s->req.analysers = 0; + channel_auto_connect(&s->req); /* don't wait to establish connection */ + channel_auto_close(&s->req); /* let the producer forward close requests */ s->req.rto = sess->fe->timeout.client; s->req.wto = TICK_ETERNITY;