]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream: provide a new stream creation function for connections
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Aug 2017 15:18:36 +0000 (17:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Aug 2017 05:06:39 +0000 (07:06 +0200)
The purpose will be to create new streams for a given connection so
that we can later abstract this from a mux.

include/proto/stream.h
src/session.c
src/stream.c

index 44fc8bea5505fd5d665357ca43df9a8fdf847d36..00f452c163f10571bb1b7df22e3efc58f8d00e63 100644 (file)
@@ -36,6 +36,7 @@ extern struct list streams;
 extern struct data_cb sess_conn_cb;
 
 struct stream *stream_new(struct session *sess, enum obj_type *origin);
+int stream_create_from_conn(struct connection *conn);
 
 /* perform minimal intializations, report 0 in case of error, 1 if OK. */
 int init_stream();
index 69ca2cbd0abe98be39e2786f210b5e81fb57d039..c86baff60019d860243311771de6966bb91aba95 100644 (file)
@@ -111,7 +111,6 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
        struct connection *cli_conn;
        struct proxy *p = l->bind_conf->frontend;
        struct session *sess;
-       struct stream *strm;
        int ret;
 
 
@@ -268,10 +267,9 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
                goto out_free_sess;
 
        session_count_new(sess);
-       if ((strm = stream_new(sess, &cli_conn->obj_type)) == NULL)
+       if (stream_create_from_conn(cli_conn) < 0)
                goto out_free_sess;
 
-       task_wakeup(strm->task, TASK_WOKEN_INIT);
        return 1;
 
  out_free_sess:
@@ -417,7 +415,6 @@ static struct task *session_expire_embryonic(struct task *t)
 static int conn_complete_session(struct connection *conn)
 {
        struct session *sess = conn->owner;
-       struct stream *strm;
 
        conn_clear_xprt_done_cb(conn);
 
@@ -436,11 +433,9 @@ static int conn_complete_session(struct connection *conn)
                goto fail;
 
        session_count_new(sess);
-       if ((strm = stream_new(sess, &conn->obj_type)) == NULL)
+       if (stream_create_from_conn(conn) < 0)
                goto fail;
 
-       task_wakeup(strm->task, TASK_WOKEN_INIT);
-
        /* the embryonic session's task is not needed anymore */
        task_delete(sess->task);
        task_free(sess->task);
index 8527c297fc205a7c78ab5ce9930c373a7963d599..1985ed98a916c57157e977669f2fbf290db3d253 100644 (file)
@@ -65,6 +65,23 @@ struct list streams;
 /* List of all use-service keywords. */
 static struct list service_keywords = LIST_HEAD_INIT(service_keywords);
 
+
+/* Create a new stream for connection <conn>. Return < 0 on error. This is only
+ * valid right after the handshake, before the connection's data layer is
+ * initialized, because it relies on the session to be in conn->owner.
+ */
+int stream_create_from_conn(struct connection *conn)
+{
+       struct stream *strm;
+
+       strm = stream_new(conn->owner, &conn->obj_type);
+       if (strm == NULL)
+               return -1;
+
+       task_wakeup(strm->task, TASK_WOKEN_INIT);
+       return 0;
+}
+
 /* This function is called from the session handler which detects the end of
  * handshake, in order to complete initialization of a valid stream. It must be
  * called with a completley initialized session. It returns the pointer to