mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-14 15:34:35 +00:00
MINOR: spoe: Add a type to qualify the message list during encoding
Because we can have messages chained by event or by group, we need to have a way to know which kind of list we manipulate during the encoding. So 2 types of list has been added, SPOE_MSGS_BY_EVENT and SPOE_MSGS_BY_GROUP. And the right type is passed when spoe_encode_messages is called.
This commit is contained in:
parent
10e376727a
commit
c718b82dfe
@ -32,6 +32,10 @@
|
||||
#include <types/stream.h>
|
||||
#include <types/task.h>
|
||||
|
||||
/* Type of list of messages */
|
||||
#define SPOE_MSGS_BY_EVENT 0x01
|
||||
#define SPOE_MSGS_BY_GROUP 0x02
|
||||
|
||||
/* Flags set on the SPOE agent */
|
||||
#define SPOE_FL_CONT_ON_ERR 0x00000001 /* Do not stop events processing when an error occurred */
|
||||
#define SPOE_FL_PIPELINING 0x00000002 /* Set when SPOE agent supports pipelining (set by default) */
|
||||
|
@ -2174,13 +2174,13 @@ spoe_encode_message(struct stream *s, struct spoe_context *ctx,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Encode SPOE messages for a specific event. Info in <ctx->frag_ctx>, if any,
|
||||
* are used to handle fragmented content. On success it returns 1. If an error
|
||||
* occurred, -1 is returned. If nothing has been encoded, it returns 0 (this is
|
||||
* only possible for unfragmented payload). */
|
||||
/* Encode list of SPOE messages. Info in <ctx->frag_ctx>, if any, are used to
|
||||
* handle fragmented content. On success it returns 1. If an error occurred, -1
|
||||
* is returned. If nothing has been encoded, it returns 0 (this is only possible
|
||||
* for unfragmented payload). */
|
||||
static int
|
||||
spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
|
||||
struct list *messages, int dir)
|
||||
struct list *messages, int dir, int type)
|
||||
{
|
||||
struct spoe_config *conf = FLT_CONF(ctx->filter);
|
||||
struct spoe_agent *agent = conf->agent;
|
||||
@ -2190,22 +2190,43 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
|
||||
p = ctx->buffer->p;
|
||||
end = p + agent->frame_size - FRAME_HDR_SIZE;
|
||||
|
||||
/* Resume encoding of a SPOE message */
|
||||
if (ctx->frag_ctx.curmsg != NULL) {
|
||||
msg = ctx->frag_ctx.curmsg;
|
||||
goto encode_message;
|
||||
}
|
||||
if (type == SPOE_MSGS_BY_EVENT) { /* Loop on messages by event */
|
||||
/* Resume encoding of a SPOE message */
|
||||
if (ctx->frag_ctx.curmsg != NULL) {
|
||||
msg = ctx->frag_ctx.curmsg;
|
||||
goto encode_evt_message;
|
||||
}
|
||||
|
||||
/* Loop on messages */
|
||||
list_for_each_entry(msg, messages, by_evt) {
|
||||
ctx->frag_ctx.curmsg = msg;
|
||||
ctx->frag_ctx.curarg = NULL;
|
||||
ctx->frag_ctx.curoff = UINT_MAX;
|
||||
list_for_each_entry(msg, messages, by_evt) {
|
||||
ctx->frag_ctx.curmsg = msg;
|
||||
ctx->frag_ctx.curarg = NULL;
|
||||
ctx->frag_ctx.curoff = UINT_MAX;
|
||||
|
||||
encode_message:
|
||||
if (spoe_encode_message(s, ctx, msg, dir, &p, end) == -1)
|
||||
goto too_big;
|
||||
encode_evt_message:
|
||||
if (spoe_encode_message(s, ctx, msg, dir, &p, end) == -1)
|
||||
goto too_big;
|
||||
}
|
||||
}
|
||||
else if (type == SPOE_MSGS_BY_GROUP) { /* Loop on messages by group */
|
||||
/* Resume encoding of a SPOE message */
|
||||
if (ctx->frag_ctx.curmsg != NULL) {
|
||||
msg = ctx->frag_ctx.curmsg;
|
||||
goto encode_grp_message;
|
||||
}
|
||||
|
||||
list_for_each_entry(msg, messages, by_grp) {
|
||||
ctx->frag_ctx.curmsg = msg;
|
||||
ctx->frag_ctx.curarg = NULL;
|
||||
ctx->frag_ctx.curoff = UINT_MAX;
|
||||
|
||||
encode_grp_message:
|
||||
if (spoe_encode_message(s, ctx, msg, dir, &p, end) == -1)
|
||||
goto too_big;
|
||||
}
|
||||
}
|
||||
else
|
||||
goto skip;
|
||||
|
||||
|
||||
/* nothing has been encoded for an unfragmented payload */
|
||||
if (!(ctx->flags & SPOE_CTX_FL_FRAGMENTED) && p == ctx->buffer->p)
|
||||
@ -2544,7 +2565,7 @@ spoe_process_event(struct stream *s, struct spoe_context *ctx,
|
||||
if (ctx->state == SPOE_CTX_ST_ENCODING_MSGS) {
|
||||
if (!spoe_acquire_buffer(&ctx->buffer, &ctx->buffer_wait))
|
||||
goto out;
|
||||
ret = spoe_encode_messages(s, ctx, &(ctx->events[ev]), dir);
|
||||
ret = spoe_encode_messages(s, ctx, &(ctx->events[ev]), dir, SPOE_MSGS_BY_EVENT);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
if (!ret)
|
||||
|
Loading…
Reference in New Issue
Block a user