From: Willy Tarreau Date: Fri, 28 Nov 2014 11:18:45 +0000 (+0100) Subject: CLEANUP: stream-int: add si_ib/si_ob to dereference the buffers X-Git-Tag: v1.6-dev1~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4e4292b9af1a5bfb2e2791b6d3b0d5390ac62437;p=thirdparty%2Fhaproxy.git CLEANUP: stream-int: add si_ib/si_ob to dereference the buffers This makes the code cleaner and is more intuitive to use. --- diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 745bbcb00f..889a8557b5 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -64,6 +64,18 @@ static inline struct channel *si_oc(struct stream_interface *si) return &LIST_ELEM(si, struct session *, si[0])->res; } +/* returns the buffer which receives data from this stream interface (input channel's buffer) */ +static inline struct buffer *si_ib(struct stream_interface *si) +{ + return si_ic(si)->buf; +} + +/* returns the buffer which feeds data to this stream interface (output channel's buffer) */ +static inline struct buffer *si_ob(struct stream_interface *si) +{ + return si_oc(si)->buf; +} + /* returns the session associated to a stream interface */ static inline struct session *si_sess(struct stream_interface *si) { diff --git a/src/dumpstats.c b/src/dumpstats.c index dab7189a5d..56512e7971 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -2263,7 +2263,7 @@ static void cli_io_handler(struct stream_interface *si) /* ensure we have some output room left in the event we * would want to return some info right after parsing. */ - if (buffer_almost_full(si_ic(si)->buf)) { + if (buffer_almost_full(si_ib(si))) { si_ic(si)->flags |= CF_WAKE_WRITE; break; } @@ -3625,7 +3625,7 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px scope_txt[0] = 0; if (appctx->ctx.stats.scope_len) { strcpy(scope_txt, STAT_SCOPE_PATTERN); - memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_oc(si)->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); + memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; } @@ -3778,7 +3778,7 @@ static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy * name does not match, skip it. */ if (appctx->ctx.stats.scope_len && - strnistr(px->id, strlen(px->id), bo_ptr(si_oc(si)->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL) + strnistr(px->id, strlen(px->id), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL) return 1; if ((appctx->ctx.stats.flags & STAT_BOUND) && @@ -4134,7 +4134,7 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u ); /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ - memcpy(scope_txt, bo_ptr(si_oc(si)->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); + memcpy(scope_txt, bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); scope_txt[appctx->ctx.stats.scope_len] = '\0'; chunk_appendf(&trash, @@ -4149,7 +4149,7 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u scope_txt[0] = 0; if (appctx->ctx.stats.scope_len) { strcpy(scope_txt, STAT_SCOPE_PATTERN); - memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_oc(si)->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); + memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; } @@ -4756,7 +4756,7 @@ static int stats_send_http_redirect(struct stream_interface *si) scope_txt[0] = 0; if (appctx->ctx.stats.scope_len) { strcpy(scope_txt, STAT_SCOPE_PATTERN); - memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_oc(si)->buf) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); + memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; } @@ -4820,7 +4820,7 @@ static void http_stats_io_handler(struct stream_interface *si) } if (appctx->st0 == STAT_HTTP_DUMP) { - unsigned int prev_len = si_ic(si)->buf->i; + unsigned int prev_len = si_ib(si)->i; unsigned int data_len; unsigned int last_len; unsigned int last_fwd = 0; @@ -4840,11 +4840,11 @@ static void http_stats_io_handler(struct stream_interface *si) } } - data_len = si_ic(si)->buf->i; + data_len = si_ib(si)->i; if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) appctx->st0 = STAT_HTTP_DONE; - last_len = si_ic(si)->buf->i; + last_len = si_ib(si)->i; /* Now we must either adjust or remove the chunk size. This is * not easy because the chunk size might wrap at the end of the @@ -4854,15 +4854,15 @@ static void http_stats_io_handler(struct stream_interface *si) * applet. */ if (appctx->ctx.stats.flags & STAT_CHUNKED) { - si_ic(si)->total -= (last_len - prev_len); - si_ic(si)->buf->i -= (last_len - prev_len); + si_ic(si)->total -= (last_len - prev_len); + si_ib(si)->i -= (last_len - prev_len); if (last_len != data_len) { chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); bi_putchk(si_ic(si), &trash); - si_ic(si)->total += (last_len - data_len); - si_ic(si)->buf->i += (last_len - data_len); + si_ic(si)->total += (last_len - data_len); + si_ib(si)->i += (last_len - data_len); } /* now re-enable forwarding */ channel_forward(si_ic(si), last_fwd); @@ -4888,7 +4888,7 @@ static void http_stats_io_handler(struct stream_interface *si) goto fail; } /* eat the whole request */ - bo_skip(si_oc(si), si_oc(si)->buf->o); + bo_skip(si_oc(si), si_ob(si)->o); res->flags |= CF_READ_NULL; si_shutr(si); } diff --git a/src/hlua.c b/src/hlua.c index 83a8683624..b003750979 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -1445,7 +1445,7 @@ static int hlua_socket_write_yield(struct lua_State *L,int status, lua_KContext } /* Check for avalaible space. */ - len = buffer_total_space(si_ic(&socket->s->si[0])->buf); + len = buffer_total_space(si_ib(&socket->s->si[0])); if (len <= 0) goto hlua_socket_write_yield_return; diff --git a/src/peers.c b/src/peers.c index 10cc7ff1d9..805b8d089f 100644 --- a/src/peers.c +++ b/src/peers.c @@ -647,7 +647,7 @@ switchstate: to_store = 0; to_read = ntohl(netinteger); - if (to_read + totl > si_oc(si)->buf->size) { + if (to_read + totl > si_ob(si)->size) { /* impossible to read a key this large, abort */ reql = -1; goto incomplete; diff --git a/src/stream_interface.c b/src/stream_interface.c index bfc67c24c0..f45678fe2b 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -181,7 +181,7 @@ static void stream_int_update_embedded(struct stream_interface *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_ic(si)->buf->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) { + (si_ib(si)->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) { si_chk_snd(si_ic(si)->cons); /* check if the consumer has freed some space */ if (channel_may_recv(si_ic(si)) && !si_ic(si)->pipe) @@ -599,7 +599,7 @@ 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_ic(si)->buf->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) { + (si_ib(si)->i == 0 && (si_ic(si)->cons->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);