diff --git a/src/mux_pt.c b/src/mux_pt.c index 7f9ce26db..32f803fa2 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -137,7 +137,7 @@ static void pt_trace(enum trace_level level, uint64_t mask, const struct trace_s const struct buffer *buf = a3; const size_t *val = a4; - if (!ctx|| src->verbosity < PT_VERB_CLEAN) + if (!ctx || src->verbosity < PT_VERB_CLEAN) return; /* Display frontend/backend info by default */ @@ -146,12 +146,16 @@ static void pt_trace(enum trace_level level, uint64_t mask, const struct trace_s if (src->verbosity == PT_VERB_CLEAN) return; + if (!cs) + cs = ctx->cs; + /* Display the value to the 4th argument (level > STATE) */ if (src->level > TRACE_LEVEL_STATE && val) chunk_appendf(&trace_buf, " - VAL=%lu", (long)*val); /* Display conn and cs info, if defined (pointer + flags) */ chunk_appendf(&trace_buf, " - conn=%p(0x%08x)", conn, conn->flags); + chunk_appendf(&trace_buf, " endp=%p(0x%08x)", ctx->endp, ctx->endp->flags); if (cs) chunk_appendf(&trace_buf, " cs=%p(0x%08x)", cs, cs->flags); @@ -233,8 +237,8 @@ struct task *mux_pt_io_cb(struct task *t, void *tctx, unsigned int status) { struct mux_pt_ctx *ctx = tctx; - TRACE_ENTER(PT_EV_CONN_WAKE, ctx->conn, ctx->cs); - if (ctx->cs) { + TRACE_ENTER(PT_EV_CONN_WAKE, ctx->conn); + if (!(ctx->endp->flags & CS_EP_ORPHAN)) { /* There's a small race condition. * mux_pt_io_cb() is only supposed to be called if we have no * stream attached. However, maybe the tasklet got woken up, @@ -249,7 +253,7 @@ struct task *mux_pt_io_cb(struct task *t, void *tctx, unsigned int status) ctx->conn->subs = NULL; } else if (ctx->cs->data_cb->wake) ctx->cs->data_cb->wake(ctx->cs); - TRACE_DEVEL("leaving waking up CS", PT_EV_CONN_WAKE, ctx->conn, ctx->cs); + TRACE_DEVEL("leaving waking up CS", PT_EV_CONN_WAKE, ctx->conn); return t; } conn_ctrl_drain(ctx->conn); @@ -312,16 +316,15 @@ static int mux_pt_init(struct connection *conn, struct proxy *prx, struct sessio } else { cs_attach_mux(cs, ctx, conn); - ctx->cs = cs; ctx->endp = cs->endp; } conn->ctx = ctx; ctx->cs = cs; - cs->endp->flags |= CS_EP_RCV_MORE; + ctx->endp->flags |= CS_EP_RCV_MORE; if (global.tune.options & GTUNE_USE_SPLICE) - cs->endp->flags |= CS_EP_MAY_SPLICE; + ctx->endp->flags |= CS_EP_MAY_SPLICE; - TRACE_LEAVE(PT_EV_CONN_NEW, conn, cs); + TRACE_LEAVE(PT_EV_CONN_NEW, conn); return 0; fail_free_endp: @@ -341,15 +344,14 @@ static int mux_pt_init(struct connection *conn, struct proxy *prx, struct sessio static int mux_pt_wake(struct connection *conn) { struct mux_pt_ctx *ctx = conn->ctx; - struct conn_stream *cs = ctx->cs; int ret = 0; - TRACE_ENTER(PT_EV_CONN_WAKE, ctx->conn, cs); - if (cs) { - ret = cs->data_cb->wake ? cs->data_cb->wake(cs) : 0; + TRACE_ENTER(PT_EV_CONN_WAKE, ctx->conn); + if (!(ctx->endp->flags & CS_EP_ORPHAN)) { + ret = ctx->cs->data_cb->wake ? ctx->cs->data_cb->wake(ctx->cs) : 0; if (ret < 0) { - TRACE_DEVEL("leaving waking up CS", PT_EV_CONN_WAKE, ctx->conn, cs); + TRACE_DEVEL("leaving waking up CS", PT_EV_CONN_WAKE, ctx->conn); return ret; } } else { @@ -385,7 +387,8 @@ static int mux_pt_attach(struct connection *conn, struct conn_stream *cs, struct conn->xprt->unsubscribe(ctx->conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event); cs_attach_mux(cs, ctx, conn); ctx->cs = cs; - cs->endp->flags |= CS_EP_RCV_MORE; + ctx->endp = cs->endp; + ctx->endp->flags |= CS_EP_RCV_MORE; TRACE_LEAVE(PT_EV_STRM_NEW, conn, cs); return 0; @@ -397,9 +400,8 @@ static int mux_pt_attach(struct connection *conn, struct conn_stream *cs, struct static const struct conn_stream *mux_pt_get_first_cs(const struct connection *conn) { struct mux_pt_ctx *ctx = conn->ctx; - struct conn_stream *cs = ctx->cs; - return cs; + return ctx->cs; } /* Destroy the mux and the associated connection if still attached to this mux @@ -409,7 +411,7 @@ static void mux_pt_destroy_meth(void *ctx) struct mux_pt_ctx *pt = ctx; TRACE_POINT(PT_EV_CONN_END, pt->conn, pt->cs); - if (!(pt->cs) || !(pt->conn) || pt->conn->ctx != pt) { + if ((pt->endp->flags & CS_EP_ORPHAN) || !(pt->conn) || pt->conn->ctx != pt) { if (pt->conn->ctx != pt) pt->endp = NULL; mux_pt_destroy(pt); @@ -447,7 +449,7 @@ static int mux_pt_used_streams(struct connection *conn) { struct mux_pt_ctx *ctx = conn->ctx; - return ctx->cs ? 1 : 0; + return (!(ctx->endp->flags & CS_EP_ORPHAN) ? 1 : 0); } /* returns the number of streams still available on a connection */