]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stream-int: add si_ib/si_ob to dereference the buffers
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Nov 2014 11:18:45 +0000 (12:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 Mar 2015 19:41:46 +0000 (20:41 +0100)
This makes the code cleaner and is more intuitive to use.

include/proto/stream_interface.h
src/dumpstats.c
src/hlua.c
src/peers.c
src/stream_interface.c

index 745bbcb00fc5f070dfddb0e9331779f58086d57e..889a8557b55ac39c23aefe9409994cdf4dd7d966 100644 (file)
@@ -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)
 {
index dab7189a5db63846f7dae832ad4ed6d46c6baab1..56512e797115d30da57240b32daf6d362ba4927a 100644 (file)
@@ -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);
        }
index 83a86836242c5a5c12864b125c08fa3e6713fe52..b003750979752368ca5c0b4113f4f386391de87f 100644 (file)
@@ -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;
 
index 10cc7ff1d9fdc9d8475269ab53edb865ea7bbd7b..805b8d089f7e30cd3bcc5d7c85f495688c7695fd 100644 (file)
@@ -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;
index bfc67c24c0a7c78194915e9ceac848e58fa48b29..f45678fe2b10b86bcca7eca3aff5b6bd84ad8f88 100644 (file)
@@ -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);