]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stream: isolate connection-specific initialization code
authorWilly Tarreau <w@1wt.eu>
Sat, 4 Apr 2015 23:30:42 +0000 (01:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Apr 2015 09:37:34 +0000 (11:37 +0200)
In stream_accept_session(), we perform some operations that explicitly
want a connection as the origin, but we'll soon have other types of
origin (eg: applet). Thus change the test to ensure we only call this
code with connections. Additionally, we refrain from calling fe->accept()
if the origin is not a connection, because for now the only fe->accept()
may only use a connection (frontend_accept).

src/stream.c

index 0d9a202063e2dce1e24c0c670a3d7acf9f785ded..7fa399c6a034713e3035b0a06d1e85aec6acb199 100644 (file)
@@ -69,7 +69,7 @@ int stream_accept_session(struct session *sess, struct task *t)
        struct stream *s;
        struct listener *l = sess->listener;
        struct proxy *p = sess->fe;
-       struct connection *conn = __objt_conn(sess->origin);
+       struct connection *conn = objt_conn(sess->origin);
        int ret;
        int i;
 
@@ -151,7 +151,8 @@ int stream_accept_session(struct session *sess, struct task *t)
        si_set_state(&s->si[0], SI_ST_EST);
 
        /* attach the incoming connection to the stream interface now. */
-       si_attach_conn(&s->si[0], conn);
+       if (conn)
+               si_attach_conn(&s->si[0], conn);
 
        if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
                s->si[0].flags |= SI_FL_INDEP_STR;
@@ -204,9 +205,13 @@ int stream_accept_session(struct session *sess, struct task *t)
        HLUA_INIT(&s->hlua);
 
        /* finish initialization of the accepted file descriptor */
-       conn_data_want_recv(conn);
+       if (conn)
+               conn_data_want_recv(conn);
 
-       if (p->accept && (ret = p->accept(s)) <= 0) {
+       /* FIXME: we shouldn't restrict ourselves to connections but for now
+        * the only ->accept() only works with sessions.
+        */
+       if (conn && p->accept && (ret = p->accept(s)) <= 0) {
                /* Either we had an unrecoverable error (<0) or work is
                 * finished (=0, eg: monitoring), in both situations,
                 * we can release everything and close.
@@ -214,12 +219,14 @@ int stream_accept_session(struct session *sess, struct task *t)
                goto out_free_strm;
        }
 
-       /* if logs require transport layer information, note it on the connection */
-       if (s->logs.logwait & LW_XPRT)
-               conn->flags |= CO_FL_XPRT_TRACKED;
+       if (conn) {
+               /* if logs require transport layer information, note it on the connection */
+               if (s->logs.logwait & LW_XPRT)
+                       conn->flags |= CO_FL_XPRT_TRACKED;
 
-       /* we want the connection handler to notify the stream interface about updates. */
-       conn->flags |= CO_FL_WAKE_DATA;
+               /* we want the connection handler to notify the stream interface about updates. */
+               conn->flags |= CO_FL_WAKE_DATA;
+       }
 
        /* it is important not to call the wakeup function directly but to
         * pass through task_wakeup(), because this one knows how to apply