]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: session: use a specific data_cb for embryonic sessions
authorWilly Tarreau <w@1wt.eu>
Tue, 2 Oct 2012 19:21:20 +0000 (21:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 4 Oct 2012 20:26:10 +0000 (22:26 +0200)
We don't want to have the recv or send callbacks in embryonic
sessions, and we want the stream interface to be referenced as
the connection owner only once the session is instanciated. So
let's first have the embryonic session be the owner, then replaced
later by the stream interface once the transport layer is ready.

src/session.c

index b697599cd8eb585ec9ee7b8b3aef02ba63f1baee..62099213dfa6a8a4534603161b04e3414b62c5c1 100644 (file)
@@ -53,6 +53,14 @@ struct list sessions;
 static struct task *expire_mini_session(struct task *t);
 int session_complete(struct session *s);
 
+/* data layer callbacks for an embryonic session */
+struct data_cb sess_conn_cb = {
+       .recv = NULL,
+       .send = NULL,
+       .wake = NULL,
+       .init = NULL,
+};
+
 /* This function is called from the protocol layer accept() in order to
  * instanciate a new embryonic session on behalf of a given listener and
  * frontend. It returns a positive value upon success, 0 if the connection
@@ -165,7 +173,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
         * but not initialized. Also note we need to be careful as the stream
         * int is not initialized yet.
         */
-       si_prepare_conn(&s->si[0], l->proto, l->xprt);
+       conn_prepare(&s->si[0].conn, &sess_conn_cb, l->proto, l->xprt, s);
 
        /* finish initialization of the accepted file descriptor */
        fd_insert(cfd);
@@ -260,7 +268,7 @@ static void kill_mini_session(struct session *s)
  */
 int conn_session_complete(struct connection *conn, int flag)
 {
-       struct session *s = container_of(conn->owner, struct session, si[0]);
+       struct session *s = conn->owner;
 
        if (!(conn->flags & CO_FL_ERROR) && (session_complete(s) > 0)) {
                conn->flags &= ~flag;
@@ -305,6 +313,7 @@ int session_complete(struct session *s)
        /* OK, we're keeping the session, so let's properly initialize the session */
        LIST_ADDQ(&sessions, &s->list);
        LIST_INIT(&s->back_refs);
+       si_takeover_conn(&s->si[0], l->proto, l->xprt);
        s->flags |= SN_INITIALIZED;
 
        s->unique_id = NULL;