MINOR: filters: Remove unused or useless stuff and do small optimizations

This commit is contained in:
Christopher Faulet 2015-12-07 13:39:08 +01:00 committed by Willy Tarreau
parent da02e17d42
commit 3e7bc67722
3 changed files with 33 additions and 35 deletions

View File

@ -34,6 +34,10 @@
#define CHN_IDX(chn) (((chn)->flags & CF_ISRESP) == CF_ISRESP)
#define FLT_NXT(flt, chn) ((flt)->next[CHN_IDX(chn)])
#define FLT_FWD(flt, chn) ((flt)->fwd[CHN_IDX(chn)])
#define flt_req_nxt(flt) ((flt)->next[0])
#define flt_rsp_nxt(flt) ((flt)->next[1])
#define flt_req_fwd(flt) ((flt)->fwd[0])
#define flt_rsp_fwd(flt) ((flt)->fwd[1])
#define HAS_FILTERS(strm) ((strm)->strm_flt.flags & STRM_FLT_FL_HAS_FILTERS)
@ -181,7 +185,8 @@ flt_change_next_size(struct filter *filter, struct channel *chn, int len)
list_for_each_entry(f, &strm_flt(s)->filters, list) {
if (f == filter)
break;
FLT_NXT(f, chn) += len;
if (IS_DATA_FILTER(filter, chn))
FLT_NXT(f, chn) += len;
}
}
@ -205,9 +210,11 @@ flt_change_forward_size(struct filter *filter, struct channel *chn, int len)
list_for_each_entry(f, &strm_flt(s)->filters, list) {
if (f == filter)
before = 0;
if (before)
FLT_FWD(f, chn) += len;
FLT_NXT(f, chn) += len;
if (IS_DATA_FILTER(filter, chn)) {
if (before)
FLT_FWD(f, chn) += len;
FLT_NXT(f, chn) += len;
}
}
}

View File

@ -55,17 +55,6 @@ struct flt_kw_list {
struct flt_kw kw[VAR_ARRAY];
};
/*
* Filter flags set for a specific filter on channel
*
* - FILTER_FL_FORWARD_DATA : When this flag is set, the rest of the data is
* directly forwarded. For chunk-encoded HTTP
* messages, this flag is reseted between each
* chunks.
*/
#define FILTER_FL_FORWARD_DATA 0x00000001
/*
* Callbacks available on a filter:
*

View File

@ -154,35 +154,36 @@ static int
comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
{
struct comp_state *st = filter->ctx;
struct buffer *buf = msg->chn->buf;
unsigned int *nxt = &flt_rsp_nxt(filter);
unsigned int len;
int ret;
if (!(msg->chn->flags & CF_ISRESP) || !st->comp_algo)
return 1;
len = MIN(msg->chunk_len + msg->next, msg->chn->buf->i) - FLT_NXT(filter, msg->chn);
len = MIN(msg->chunk_len + msg->next, buf->i) - *nxt;
if (!len)
return len;
if (!st->initialized) {
b_adv(msg->chn->buf, FLT_FWD(filter, msg->chn) + st->sov);
ret = http_compression_buffer_init(msg->chn->buf, tmpbuf);
b_rew(msg->chn->buf, FLT_FWD(filter, msg->chn) + st->sov);
unsigned int fwd = flt_rsp_fwd(filter) + st->sov;
b_adv(buf, fwd);
ret = http_compression_buffer_init(buf, tmpbuf);
b_rew(buf, fwd);
if (ret < 0) {
msg->chn->flags |= CF_WAKE_WRITE;
return 0;
}
}
b_adv(msg->chn->buf, FLT_NXT(filter, msg->chn));
ret = http_compression_buffer_add_data(st, msg->chn->buf, tmpbuf, len);
b_rew(msg->chn->buf, FLT_NXT(filter, msg->chn));
b_adv(buf, *nxt);
ret = http_compression_buffer_add_data(st, buf, tmpbuf, len);
b_rew(buf, *nxt);
if (ret < 0)
return ret;
st->initialized = 1;
msg->next += ret;
msg->chunk_len -= ret;
FLT_NXT(filter, msg->chn) = msg->next;
*nxt = msg->next;
return 0;
}
@ -541,15 +542,13 @@ http_compression_buffer_add_data(struct comp_state *st, struct buffer *in,
int block1, block2;
if (!sz)
return 0;
goto end;
/* select the smallest size between the announced chunk size, the input
* data, and the available output buffer size. The compressors are
* assumed to be able to process all the bytes we pass to them at
* once. */
data_process_len = sz;
data_process_len = MIN(out->size - buffer_len(out), data_process_len);
data_process_len = MIN(out->size - buffer_len(out), sz);
block1 = data_process_len;
if (block1 > bi_contig_data(in))
@ -558,11 +557,14 @@ http_compression_buffer_add_data(struct comp_state *st, struct buffer *in,
/* compressors return < 0 upon error or the amount of bytes read */
consumed_data = st->comp_algo->add_data(st->comp_ctx, bi_ptr(in), block1, out);
if (consumed_data >= 0 && block2 > 0) {
consumed_data = st->comp_algo->add_data(st->comp_ctx, in->data, block2, out);
if (consumed_data >= 0)
consumed_data += block1;
}
if (consumed_data != block1 || !block2)
goto end;
consumed_data = st->comp_algo->add_data(st->comp_ctx, in->data, block2, out);
if (consumed_data < 0)
goto end;
consumed_data += block1;
end:
return consumed_data;
}