MEDIUM: tree-wide: Use unsafe conn-stream API when it is relevant
The unsafe conn-stream API (__cs_*) is now used when we are sure the good
endpoint or application is attached to the conn-stream. This avoids compiler
warnings about possible null derefs. It also simplify the code and clear up
any ambiguity about manipulated entities.
diff --git a/src/stream_interface.c b/src/stream_interface.c
index 4442b22..21e9d08 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -387,12 +387,10 @@
*/
if (cs && cs->data_cb == &si_conn_cb) {
- struct stream *strm = cs_strm(cs);
-
ret = make_proxy_line(trash.area, trash.size,
objt_server(conn->target),
cs_conn(si_opposite(cs_si(cs))->cs),
- strm);
+ cs_strm(cs));
}
else {
/* The target server expects a LOCAL line to be sent first. Retrieving
@@ -595,7 +593,7 @@
*/
static int si_cs_process(struct conn_stream *cs)
{
- struct connection *conn = cs_conn(cs);
+ struct connection *conn = __cs_conn(cs);
struct stream_interface *si = cs_si(cs);
struct channel *ic = si_ic(si);
struct channel *oc = si_oc(si);
@@ -683,14 +681,12 @@
*/
int si_cs_send(struct conn_stream *cs)
{
- struct connection *conn = cs_conn(cs);
+ struct connection *conn = __cs_conn(cs);
struct stream_interface *si = cs_si(cs);
struct channel *oc = si_oc(si);
int ret;
int did_send = 0;
- BUG_ON(!conn);
-
if (conn->flags & CO_FL_ERROR || cs->flags & (CS_FL_ERROR|CS_FL_ERR_PENDING)) {
/* We're probably there because the tasklet was woken up,
* but process_stream() ran before, detected there were an
@@ -998,12 +994,12 @@
if (cs_appctx(si_f->cs) &&
((si_rx_endp_ready(si_f) && !si_rx_blocked(si_f)) ||
(si_tx_endp_ready(si_f) && !si_tx_blocked(si_f))))
- appctx_wakeup(cs_appctx(si_f->cs));
+ appctx_wakeup(__cs_appctx(si_f->cs));
if (cs_appctx(si_b->cs) &&
((si_rx_endp_ready(si_b) && !si_rx_blocked(si_b)) ||
(si_tx_endp_ready(si_b) && !si_tx_blocked(si_b))))
- appctx_wakeup(cs_appctx(si_b->cs));
+ appctx_wakeup(__cs_appctx(si_b->cs));
}
/*
@@ -1251,15 +1247,13 @@
*/
int si_cs_recv(struct conn_stream *cs)
{
- struct connection *conn = cs_conn(cs);
+ struct connection *conn = __cs_conn(cs);
struct stream_interface *si = cs_si(cs);
struct channel *ic = si_ic(si);
int ret, max, cur_read = 0;
int read_poll = MAX_READ_POLL_LOOPS;
int flags = 0;
- BUG_ON(!conn);
-
/* If not established yet, do nothing. */
if (si->state != SI_ST_EST)
return 0;
@@ -1638,6 +1632,8 @@
{
struct channel *ic = si_ic(si);
+ BUG_ON(cs_appctx(si->cs));
+
/* If the applet wants to write and the channel is closed, it's a
* broken pipe and it must be reported.
*/
@@ -1661,7 +1657,7 @@
*/
if ((si_rx_endp_ready(si) && !si_rx_blocked(si)) ||
(si_tx_endp_ready(si) && !si_tx_blocked(si)))
- appctx_wakeup(cs_appctx(si->cs));
+ appctx_wakeup(__cs_appctx(si->cs));
}
/*
@@ -1676,6 +1672,8 @@
{
struct channel *ic = si_ic(si);
+ BUG_ON(cs_appctx(si->cs));
+
si_rx_shut_blk(si);
if (ic->flags & CF_SHUTR)
return;
@@ -1710,6 +1708,8 @@
struct channel *ic = si_ic(si);
struct channel *oc = si_oc(si);
+ BUG_ON(cs_appctx(si->cs));
+
oc->flags &= ~CF_SHUTW_NOW;
if (oc->flags & CF_SHUTW)
return;
@@ -1723,7 +1723,7 @@
}
/* on shutw we always wake the applet up */
- appctx_wakeup(cs_appctx(si->cs));
+ appctx_wakeup(__cs_appctx(si->cs));
switch (si->state) {
case SI_ST_RDY:
@@ -1761,13 +1761,15 @@
{
struct channel *ic = si_ic(si);
+ BUG_ON(cs_appctx(si->cs));
+
DPRINTF(stderr, "%s: si=%p, si->state=%d ic->flags=%08x oc->flags=%08x\n",
__FUNCTION__,
si, si->state, ic->flags, si_oc(si)->flags);
if (!ic->pipe) {
/* (re)start reading */
- appctx_wakeup(cs_appctx(si->cs));
+ appctx_wakeup(__cs_appctx(si->cs));
}
}
@@ -1776,6 +1778,8 @@
{
struct channel *oc = si_oc(si);
+ BUG_ON(cs_appctx(si->cs));
+
DPRINTF(stderr, "%s: si=%p, si->state=%d ic->flags=%08x oc->flags=%08x\n",
__FUNCTION__,
si, si->state, si_ic(si)->flags, oc->flags);
@@ -1793,7 +1797,7 @@
if (!channel_is_empty(oc)) {
/* (re)start sending */
- appctx_wakeup(cs_appctx(si->cs));
+ appctx_wakeup(__cs_appctx(si->cs));
}
}