mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
MEDIUM: stream: return the stream upon accept()
The function was called stream_accept_session(), let's rename it stream_new() and make it return the newly allocated pointer. It's more convenient for some callers who need it.
This commit is contained in:
parent
c5a7ff4a86
commit
02d863866d
@ -36,7 +36,7 @@ extern struct list buffer_wq;
|
|||||||
|
|
||||||
extern struct data_cb sess_conn_cb;
|
extern struct data_cb sess_conn_cb;
|
||||||
|
|
||||||
int stream_accept_session(struct session *sess, struct task *t);
|
struct stream *stream_new(struct session *sess, struct task *t);
|
||||||
|
|
||||||
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
|
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
|
||||||
int init_stream();
|
int init_stream();
|
||||||
|
@ -1140,7 +1140,7 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
|
|||||||
}
|
}
|
||||||
t->nice = l->nice;
|
t->nice = l->nice;
|
||||||
|
|
||||||
if (stream_accept_session(sess, t) <= 0) {
|
if ((s = stream_new(sess, t)) == NULL) {
|
||||||
Alert("Failed to initialize stream in peer_session_create().\n");
|
Alert("Failed to initialize stream in peer_session_create().\n");
|
||||||
goto out_free_task;
|
goto out_free_task;
|
||||||
}
|
}
|
||||||
@ -1148,7 +1148,6 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
|
|||||||
/* The tasks below are normally what is supposed to be done by
|
/* The tasks below are normally what is supposed to be done by
|
||||||
* fe->accept().
|
* fe->accept().
|
||||||
*/
|
*/
|
||||||
s = t->context; // For now the session is not stored anywhere else :-/
|
|
||||||
s->flags = SF_ASSIGNED|SF_ADDR_SET;
|
s->flags = SF_ASSIGNED|SF_ADDR_SET;
|
||||||
|
|
||||||
/* initiate an outgoing connection */
|
/* initiate an outgoing connection */
|
||||||
|
@ -195,9 +195,8 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
|
|||||||
|
|
||||||
/* OK let's complete stream initialization since there is no handshake */
|
/* OK let's complete stream initialization since there is no handshake */
|
||||||
cli_conn->flags |= CO_FL_CONNECTED;
|
cli_conn->flags |= CO_FL_CONNECTED;
|
||||||
ret = stream_accept_session(sess, t);
|
if (stream_new(sess, t))
|
||||||
if (ret > 0)
|
return 1;
|
||||||
return ret;
|
|
||||||
|
|
||||||
task_free(t);
|
task_free(t);
|
||||||
out_free_sess:
|
out_free_sess:
|
||||||
@ -342,7 +341,7 @@ static int conn_complete_session(struct connection *conn)
|
|||||||
struct task *task = conn->owner;
|
struct task *task = conn->owner;
|
||||||
struct session *sess = task->context;
|
struct session *sess = task->context;
|
||||||
|
|
||||||
if (!(conn->flags & CO_FL_ERROR) && (stream_accept_session(sess, task) > 0)) {
|
if (!(conn->flags & CO_FL_ERROR) && (stream_new(sess, task) != NULL)) {
|
||||||
conn->flags &= ~CO_FL_INIT_DATA;
|
conn->flags &= ~CO_FL_INIT_DATA;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
20
src/stream.c
20
src/stream.c
@ -58,26 +58,21 @@ struct list buffer_wq = LIST_HEAD_INIT(buffer_wq);
|
|||||||
|
|
||||||
/* This function is called from the session handler which detects the end of
|
/* 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
|
* handshake, in order to complete initialization of a valid stream. It must
|
||||||
* be called with an embryonic session. It returns a positive value upon
|
* be called with an embryonic session. It returns the pointer to the newly
|
||||||
* success, 0 if the connection can be ignored, or a negative value upon
|
* created stream, or NULL in case of fatal error. For now the client-side
|
||||||
* critical failure. The accepted file descriptor is closed if we return <= 0.
|
* end point is taken from the session's origin, which must be valid.
|
||||||
* The client-side end point is assumed to be a connection, whose pointer is
|
|
||||||
* taken from sess->origin which is assumed to be valid.
|
|
||||||
*/
|
*/
|
||||||
int stream_accept_session(struct session *sess, struct task *t)
|
struct stream *stream_new(struct session *sess, struct task *t)
|
||||||
{
|
{
|
||||||
struct stream *s;
|
struct stream *s;
|
||||||
struct listener *l = sess->listener;
|
struct listener *l = sess->listener;
|
||||||
struct proxy *p = sess->fe;
|
struct proxy *p = sess->fe;
|
||||||
struct connection *conn = objt_conn(sess->origin);
|
struct connection *conn = objt_conn(sess->origin);
|
||||||
struct appctx *appctx = objt_appctx(sess->origin);
|
struct appctx *appctx = objt_appctx(sess->origin);
|
||||||
int ret;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
ret = -1; /* assume unrecoverable error by default */
|
|
||||||
|
|
||||||
if (unlikely((s = pool_alloc2(pool2_stream)) == NULL))
|
if (unlikely((s = pool_alloc2(pool2_stream)) == NULL))
|
||||||
goto out_return;
|
return s;
|
||||||
|
|
||||||
/* minimum stream initialization required for an embryonic stream is
|
/* minimum stream initialization required for an embryonic stream is
|
||||||
* fairly low. We need very little to execute L4 ACLs, then we need a
|
* fairly low. We need very little to execute L4 ACLs, then we need a
|
||||||
@ -230,14 +225,13 @@ int stream_accept_session(struct session *sess, struct task *t)
|
|||||||
* priorities to tasks.
|
* priorities to tasks.
|
||||||
*/
|
*/
|
||||||
task_wakeup(t, TASK_WOKEN_INIT);
|
task_wakeup(t, TASK_WOKEN_INIT);
|
||||||
return 1;
|
return s;
|
||||||
|
|
||||||
/* Error unrolling */
|
/* Error unrolling */
|
||||||
out_fail_accept:
|
out_fail_accept:
|
||||||
LIST_DEL(&s->list);
|
LIST_DEL(&s->list);
|
||||||
pool_free2(pool2_stream, s);
|
pool_free2(pool2_stream, s);
|
||||||
out_return:
|
return NULL;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user