diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 889a8557b..70b2ac8d8 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -94,6 +94,15 @@ static inline struct task *si_task(struct stream_interface *si) return LIST_ELEM(si, struct session *, si[0])->task; } +/* returns the stream interface on the other side. Used during forwarding. */ +static inline struct stream_interface *si_opposite(struct stream_interface *si) +{ + if (si->flags & SI_FL_ISBACK) + return &LIST_ELEM(si, struct session *, si[1])->si[0]; + else + return &LIST_ELEM(si, struct session *, si[0])->si[1]; +} + /* Initializes all required fields for a new appctx. Note that it does the * minimum acceptable initialization for an appctx. This means only the * 3 integer states st0, st1, st2 are zeroed. diff --git a/src/hlua.c b/src/hlua.c index b00375097..0aa92e9be 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -1095,7 +1095,7 @@ __LJMP static struct hlua_socket *hlua_checksocket(lua_State *L, int ud) static void hlua_socket_handler(struct stream_interface *si) { struct appctx *appctx = objt_appctx(si->end); - struct connection *c = objt_conn(si_ic(si)->cons->end); + struct connection *c = objt_conn(si_opposite(si)->end); /* Wakeup the main session if the client connection is closed. */ if (!c || channel_output_closed(si_ic(si)) || channel_input_closed(si_oc(si))) { diff --git a/src/stream_interface.c b/src/stream_interface.c index f45678fe2..87df334b2 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -176,13 +176,13 @@ static void stream_int_update_embedded(struct stream_interface *si) old_flags = si->flags; if (likely((si_oc(si)->flags & (CF_SHUTW|CF_WRITE_PARTIAL|CF_DONT_READ)) == CF_WRITE_PARTIAL && channel_may_recv(si_oc(si)) && - (si_oc(si)->prod->flags & SI_FL_WAIT_ROOM))) - si_chk_rcv(si_oc(si)->prod); + (si_opposite(si)->flags & SI_FL_WAIT_ROOM))) + si_chk_rcv(si_opposite(si)); if (((si_ic(si)->flags & CF_READ_PARTIAL) && !channel_is_empty(si_ic(si))) && (si_ic(si)->pipe /* always try to send spliced data */ || - (si_ib(si)->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) { - si_chk_snd(si_ic(si)->cons); + (si_ib(si)->i == 0 && (si_opposite(si)->flags & SI_FL_WAIT_DATA)))) { + si_chk_snd(si_opposite(si)); /* check if the consumer has freed some space */ if (channel_may_recv(si_ic(si)) && !si_ic(si)->pipe) si->flags &= ~SI_FL_WAIT_ROOM; @@ -203,14 +203,14 @@ static void stream_int_update_embedded(struct stream_interface *si) si->state != SI_ST_EST || (si->flags & SI_FL_ERR) || ((si_ic(si)->flags & CF_READ_PARTIAL) && - (!si_ic(si)->to_forward || si_ic(si)->cons->state != SI_ST_EST)) || + (!si_ic(si)->to_forward || si_opposite(si)->state != SI_ST_EST)) || /* changes on the consumption side */ (si_oc(si)->flags & (CF_WRITE_NULL|CF_WRITE_ERROR)) || ((si_oc(si)->flags & CF_WRITE_ACTIVITY) && ((si_oc(si)->flags & CF_SHUTW) || ((si_oc(si)->flags & CF_WAKE_WRITE) && - (si_oc(si)->prod->state != SI_ST_EST || + (si_opposite(si)->state != SI_ST_EST || (channel_is_empty(si_oc(si)) && !si_oc(si)->to_forward)))))) { if (!(si->flags & SI_FL_DONT_WAKE)) task_wakeup(si_task(si), TASK_WOKEN_IO); @@ -424,7 +424,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag) */ if (conn->data == &si_conn_cb) { struct stream_interface *si = conn->owner; - struct connection *remote = objt_conn(si_oc(si)->prod->end); + struct connection *remote = objt_conn(si_opposite(si)->end); ret = make_proxy_line(trash.str, trash.size, objt_server(conn->target), remote); } else { @@ -586,8 +586,8 @@ static int si_conn_wake_cb(struct connection *conn) if (likely((si_oc(si)->flags & (CF_SHUTW|CF_WRITE_PARTIAL|CF_DONT_READ)) == CF_WRITE_PARTIAL && channel_may_recv(si_oc(si)) && - (si_oc(si)->prod->flags & SI_FL_WAIT_ROOM))) - si_chk_rcv(si_oc(si)->prod); + (si_opposite(si)->flags & SI_FL_WAIT_ROOM))) + si_chk_rcv(si_opposite(si)); } /* process producer side. @@ -599,10 +599,10 @@ static int si_conn_wake_cb(struct connection *conn) */ if (((si_ic(si)->flags & CF_READ_PARTIAL) && !channel_is_empty(si_ic(si))) && (si_ic(si)->pipe /* always try to send spliced data */ || - (si_ib(si)->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) { + (si_ib(si)->i == 0 && (si_opposite(si)->flags & SI_FL_WAIT_DATA)))) { int last_len = si_ic(si)->pipe ? si_ic(si)->pipe->data : 0; - si_chk_snd(si_ic(si)->cons); + si_chk_snd(si_opposite(si)); /* check if the consumer has freed some space either in the * buffer or in the pipe. @@ -630,14 +630,14 @@ static int si_conn_wake_cb(struct connection *conn) si->state != SI_ST_EST || (si->flags & SI_FL_ERR) || ((si_ic(si)->flags & CF_READ_PARTIAL) && - (!si_ic(si)->to_forward || si_ic(si)->cons->state != SI_ST_EST)) || + (!si_ic(si)->to_forward || si_opposite(si)->state != SI_ST_EST)) || /* changes on the consumption side */ (si_oc(si)->flags & (CF_WRITE_NULL|CF_WRITE_ERROR)) || ((si_oc(si)->flags & CF_WRITE_ACTIVITY) && ((si_oc(si)->flags & CF_SHUTW) || ((si_oc(si)->flags & CF_WAKE_WRITE) && - (si_oc(si)->prod->state != SI_ST_EST || + (si_opposite(si)->state != SI_ST_EST || (channel_is_empty(si_oc(si)) && !si_oc(si)->to_forward)))))) { task_wakeup(si_task(si), TASK_WOKEN_IO); }