]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: spoe: use the new buffer API for the SPOE buffer
authorWilly Tarreau <w@1wt.eu>
Fri, 15 Jun 2018 17:37:42 +0000 (19:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:42 +0000 (16:23 +0200)
The buffer is not used as a forwarding buffer so we can simply map ->i
to ->len and ->p to b_head(). It *seems* that p is never modified, so
that we could even always use b_orig(). This needs to be rechecked.

src/flt_spoe.c

index d1323ae3e9bfe084efda2677a3b9a8e88dc87d22..2a4f05ef018087f3182917a3161d6e2f0939e7ea 100644 (file)
@@ -573,10 +573,10 @@ spoe_prepare_hanotify_frame(struct appctx *appctx, struct spoe_context *ctx,
                goto too_big;
 
        /* Copy encoded messages, if possible */
-       sz = ctx->buffer->i;
+       sz = b_data(ctx->buffer);
        if (p + sz >= end)
                goto too_big;
-       memcpy(p, ctx->buffer->p, sz);
+       memcpy(p, b_head(ctx->buffer), sz);
        p += sz;
 
        return (p - frame);
@@ -633,10 +633,10 @@ spoe_prepare_hafrag_frame(struct appctx *appctx, struct spoe_context *ctx,
                goto end;
 
        /* Copy encoded messages, if possible */
-       sz = ctx->buffer->i;
+       sz = b_data(ctx->buffer);
        if (p + sz >= end)
                goto too_big;
-       memcpy(p, ctx->buffer->p, sz);
+       memcpy(p, b_head(ctx->buffer), sz);
        p += sz;
 
   end:
@@ -1044,8 +1044,8 @@ spoe_handle_agentack_frame(struct appctx *appctx, struct spoe_context **ctx,
 
        /* Copy encoded actions */
        len = (end - p);
-       memcpy(SPOE_APPCTX(appctx)->buffer->p, p, len);
-       SPOE_APPCTX(appctx)->buffer->i = len;
+       memcpy(b_head(SPOE_APPCTX(appctx)->buffer), p, len);
+       b_set_data(SPOE_APPCTX(appctx)->buffer, len);
        p += len;
 
        /* Transfer the buffer ownership to the SPOE context */
@@ -2212,7 +2212,7 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
        struct spoe_message *msg;
        char   *p, *end;
 
-       p   = ctx->buffer->p;
+       p   = b_head(ctx->buffer);
        end =  p + agent->rt[tid].frame_size - FRAME_HDR_SIZE;
 
        if (type == SPOE_MSGS_BY_EVENT) { /* Loop on messages by event */
@@ -2254,7 +2254,7 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
 
 
        /* nothing has been encoded for an unfragmented payload */
-       if (!(ctx->flags & SPOE_CTX_FL_FRAGMENTED) && p == ctx->buffer->p)
+       if (!(ctx->flags & SPOE_CTX_FL_FRAGMENTED) && p == b_head(ctx->buffer))
                goto skip;
 
        SPOE_PRINTF(stderr, "%d.%06d [SPOE/%-15s] %s: stream=%p"
@@ -2266,7 +2266,7 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
                    ctx->spoe_appctx, (agent->rt[tid].frame_size - FRAME_HDR_SIZE),
                    p - ctx->buffer->p);
 
-       ctx->buffer->i = p - ctx->buffer->p;
+       b_set_data(ctx->buffer, p - b_head(ctx->buffer));
        ctx->frag_ctx.curmsg = NULL;
        ctx->frag_ctx.curarg = NULL;
        ctx->frag_ctx.curoff = 0;
@@ -2287,9 +2287,9 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
                    (int)now.tv_sec, (int)now.tv_usec,
                    agent->id, __FUNCTION__, s, ctx->spoe_appctx,
                    ctx->frag_ctx.curmsg, ctx->frag_ctx.curarg, ctx->frag_ctx.curoff,
-                   (agent->rt[tid].frame_size - FRAME_HDR_SIZE), p - ctx->buffer->p);
+                   (agent->rt[tid].frame_size - FRAME_HDR_SIZE), p - b_head(ctx->buffer));
 
-       ctx->buffer->i = p - ctx->buffer->p;
+       b_set_data(ctx->buffer, p - b_head(ctx->buffer));
        ctx->flags |= SPOE_CTX_FL_FRAGMENTED;
        ctx->frag_ctx.flags &= ~SPOE_FRM_FL_FIN;
        return 1;
@@ -2445,8 +2445,8 @@ spoe_process_actions(struct stream *s, struct spoe_context *ctx, int dir)
        char *p, *end;
        int   ret;
 
-       p   = ctx->buffer->p;
-       end = p + ctx->buffer->i;
+       p   = b_head(ctx->buffer);
+       end = p + b_data(ctx->buffer);
 
        while (p < end)  {
                enum spoe_action_type type;