CLEANUP: conn_stream: merge cs_new_from_{mux,applet} into cs_new_from_endp()

The two functions became exact copies since there's no more special case
for the appctx owner. Let's merge them into a single one, that simplifies
the code.
This commit is contained in:
Willy Tarreau 2022-05-11 16:11:24 +02:00
parent 0698c80a58
commit 6796a06278
12 changed files with 12 additions and 33 deletions

View File

@ -38,8 +38,7 @@ struct check;
struct cs_endpoint *cs_endpoint_new();
void cs_endpoint_free(struct cs_endpoint *endp);
struct conn_stream *cs_new_from_mux(struct cs_endpoint *endp, struct session *sess, struct buffer *input);
struct conn_stream *cs_new_from_applet(struct cs_endpoint *endp, struct session *sess, struct buffer *input);
struct conn_stream *cs_new_from_endp(struct cs_endpoint *endp, struct session *sess, struct buffer *input);
struct conn_stream *cs_new_from_strm(struct stream *strm, unsigned int flags);
struct conn_stream *cs_new_from_check(struct check *check, unsigned int flags);
void cs_free(struct conn_stream *cs);

View File

@ -91,7 +91,7 @@ static inline int qcc_install_app_ops(struct qcc *qcc,
static inline struct conn_stream *qc_attach_cs(struct qcs *qcs, struct buffer *buf)
{
if (!cs_new_from_mux(qcs->endp, qcs->qcc->conn->owner, buf))
if (!cs_new_from_endp(qcs->endp, qcs->qcc->conn->owner, buf))
return NULL;
++qcs->qcc->nb_cs;

View File

@ -156,27 +156,7 @@ static struct conn_stream *cs_new(struct cs_endpoint *endp)
* defined. It returns NULL on error. On success, the new conn-stream is
* returned. In this case, CS_EP_ORPHAN flag is removed.
*/
struct conn_stream *cs_new_from_mux(struct cs_endpoint *endp, struct session *sess, struct buffer *input)
{
struct conn_stream *cs;
cs = cs_new(endp);
if (unlikely(!cs))
return NULL;
if (unlikely(!stream_new(sess, cs, input))) {
pool_free(pool_head_connstream, cs);
cs = NULL;
}
endp->flags &= ~CS_EP_ORPHAN;
return cs;
}
/* Creates a new conn-stream and its associated stream from an applet. <endp>
* must be defined. It returns NULL on error. On success, the new conn-stream is
* returned. In this case, CS_EP_ORPHAN flag is removed. The created CS is used
* to set the appctx owner.
*/
struct conn_stream *cs_new_from_applet(struct cs_endpoint *endp, struct session *sess, struct buffer *input)
struct conn_stream *cs_new_from_endp(struct cs_endpoint *endp, struct session *sess, struct buffer *input)
{
struct conn_stream *cs;

View File

@ -938,7 +938,7 @@ static struct appctx *dns_session_create(struct dns_session *ds)
if (!sockaddr_alloc(&addr, &ds->dss->srv->addr, sizeof(ds->dss->srv->addr)))
goto out_free_sess;
cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs) {
ha_alert("Failed to initialize stream in dns_session_create().\n");
goto out_free_addr;

View File

@ -2026,7 +2026,7 @@ spoe_create_appctx(struct spoe_config *conf)
if (!sess)
goto out_free_spoe;
cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs)
goto out_free_sess;

View File

@ -3004,7 +3004,7 @@ __LJMP static int hlua_socket_new(lua_State *L)
goto out_fail_appctx;
}
cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs) {
hlua_pusherror(L, "socket: out of memory");
goto out_fail_sess;

View File

@ -607,7 +607,7 @@ struct appctx *httpclient_start(struct httpclient *hc)
if (!sockaddr_alloc(&addr, ss_dst, sizeof(*ss_dst)))
goto out_free_sess;
cs = cs_new_from_applet(appctx->endp, sess, &hc->req.buf);
cs = cs_new_from_endp(appctx->endp, sess, &hc->req.buf);
if (!cs) {
ha_alert("httpclient: Failed to initialize stream %s:%d.\n", __FUNCTION__, __LINE__);
goto out_free_addr;

View File

@ -726,7 +726,7 @@ static struct conn_stream *h1s_new_cs(struct h1s *h1s, struct buffer *input)
if (h1s->req.flags & H1_MF_UPG_WEBSOCKET)
h1s->endp->flags |= CS_EP_WEBSOCKET;
if (!cs_new_from_mux(h1s->endp, h1c->conn->owner, input)) {
if (!cs_new_from_endp(h1s->endp, h1c->conn->owner, input)) {
TRACE_ERROR("CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1c->conn, h1s);
goto err;
}

View File

@ -1629,7 +1629,7 @@ static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *in
*/
sess->t_idle = tv_ms_elapsed(&sess->tv_accept, &now) - sess->t_handshake;
if (!cs_new_from_mux(h2s->endp, sess, input))
if (!cs_new_from_endp(h2s->endp, sess, input))
goto out_close;
h2c->nb_cs++;

View File

@ -302,7 +302,7 @@ static int mux_pt_init(struct connection *conn, struct proxy *prx, struct sessio
ctx->endp->ctx = conn;
ctx->endp->flags |= (CS_EP_T_MUX|CS_EP_ORPHAN);
cs = cs_new_from_mux(ctx->endp, sess, input);
cs = cs_new_from_endp(ctx->endp, sess, input);
if (!cs) {
TRACE_ERROR("CS allocation failure", PT_EV_STRM_NEW|PT_EV_STRM_END|PT_EV_STRM_ERR, conn);
goto fail_free_endp;

View File

@ -3194,7 +3194,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
if (!sockaddr_alloc(&addr, &peer->addr, sizeof(peer->addr)))
goto out_free_sess;
cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs) {
ha_alert("Failed to initialize stream in peer_session_create().\n");
goto out_free_addr;

View File

@ -654,7 +654,7 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink
if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr)))
goto out_free_sess;
cs = cs_new_from_applet(appctx->endp, sess, &BUF_NULL);
cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
if (!cs) {
ha_alert("Failed to initialize stream in sink_forward_session_create().\n");
goto out_free_addr;