MINOR: channel/buffer: replace b_{adv,rew} with c_{adv,rew}

These ones manipulate the output data count which will be specific to
the channel soon, so prepare the call points to use the channel only.
The b_* functions are now unused and were removed.
This commit is contained in:
Willy Tarreau 2018-06-06 07:13:22 +02:00
parent c0a51c51b1
commit bcbd39370f
12 changed files with 49 additions and 71 deletions

View File

@ -1207,14 +1207,14 @@ data itself, i.e. the buffer offsets. For a HTTP message, you also must update
if (avail > 10 and /* ...Some condition... */) {
/* Move the buffer forward to have buf->p pointing on unparsed
* data */
b_adv(msg->chn->buf, flt_rsp_nxt(filter));
c_adv(msg->chn, flt_rsp_nxt(filter));
/* Skip first 10 bytes. To simplify this example, we consider a
* non-wrapping buffer */
memmove(buf->p + 10, buf->p, avail - 10);
/* Restore buf->p value */
b_rew(msg->chn->buf, flt_rsp_nxt(filter));
c_rew(msg->chn, flt_rsp_nxt(filter));
/* Now update other filters */
flt_change_next_size(filter, msg->chn, -10);
@ -1240,14 +1240,14 @@ data itself, i.e. the buffer offsets. For a HTTP message, you also must update
if (len > 10 and /* ...Some condition... */) {
/* Move the buffer forward to have buf->p pointing on non-forwarded
* data */
b_adv(msg->chn->buf, flt_rsp_fwd(filter));
c_adv(msg->chn, flt_rsp_fwd(filter));
/* Skip first 10 bytes. To simplify this example, we consider a
* non-wrapping buffer */
memmove(buf->p + 10, buf->p, len - 10);
/* Restore buf->p value */
b_rew(msg->chn->buf, flt_rsp_fwd(filter));
c_rew(msg->chn, flt_rsp_fwd(filter));
/* Now update other filters */
flt_change_forward_size(filter, msg->chn, -10);

View File

@ -105,29 +105,6 @@ static inline void bo_del(struct buffer *b, unsigned int del)
b->o -= del;
}
/* Advances the buffer by <adv> bytes, which means that the buffer
* pointer advances, and that as many bytes from in are transferred
* to out. The caller is responsible for ensuring that adv is always
* smaller than or equal to b->i.
*/
static inline void b_adv(struct buffer *b, unsigned int adv)
{
b->i -= adv;
b->o += adv;
b->p = b_ptr(b, adv);
}
/* Rewinds the buffer by <adv> bytes, which means that the buffer pointer goes
* backwards, and that as many bytes from out are moved to in. The caller is
* responsible for ensuring that adv is always smaller than or equal to b->o.
*/
static inline void b_rew(struct buffer *b, unsigned int adv)
{
b->i += adv;
b->o -= adv;
b->p = b_ptr(b, (int)-adv);
}
/* Returns the start of the input data in a buffer */
static inline char *bi_ptr(const struct buffer *b)
{

View File

@ -341,7 +341,7 @@ static inline unsigned long long channel_forward(struct channel *chn, unsigned l
if (bytes32 <= chn->buf->i) {
/* OK this amount of bytes might be forwarded at once */
b_adv(chn->buf, bytes32);
c_adv(chn, bytes32);
return bytes;
}
}
@ -351,7 +351,7 @@ static inline unsigned long long channel_forward(struct channel *chn, unsigned l
/* Forwards any input data and marks the channel for permanent forwarding */
static inline void channel_forward_forever(struct channel *chn)
{
b_adv(chn->buf, chn->buf->i);
c_adv(chn, chn->buf->i);
chn->to_forward = CHN_INFINITE_FORWARD;
}

View File

@ -485,12 +485,12 @@ static struct server *get_server_rch(struct stream *s)
memset(&smp, 0, sizeof(smp));
b_rew(s->req.buf, rewind = s->req.buf->o);
c_rew(&s->req, rewind = s->req.buf->o);
ret = fetch_rdp_cookie_name(s, &smp, px->hh_name, px->hh_len);
len = smp.data.u.str.len;
b_adv(s->req.buf, rewind);
c_adv(&s->req, rewind);
if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || len == 0)
return NULL;
@ -1020,13 +1020,13 @@ static void assign_tproxy_address(struct stream *s)
((struct sockaddr_in *)&srv_conn->addr.from)->sin_port = 0;
((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr = 0;
b_rew(s->req.buf, rewind = http_hdr_rewind(&s->txn->req));
c_rew(&s->req, rewind = http_hdr_rewind(&s->txn->req));
if (http_get_hdr(&s->txn->req, src->bind_hdr_name, src->bind_hdr_len,
&s->txn->hdr_idx, src->bind_hdr_occ, NULL, &vptr, &vlen)) {
((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr =
htonl(inetaddr_host_lim(vptr, vptr + vlen));
}
b_adv(s->req.buf, rewind);
c_adv(&s->req, rewind);
}
break;
default:
@ -1261,12 +1261,12 @@ int connect_server(struct stream *s)
* output data.
*/
rewind = s->txn ? http_hdr_rewind(&s->txn->req) : s->req.buf->o;
b_rew(s->req.buf, rewind);
c_rew(&s->req, rewind);
smp = sample_fetch_as_type(s->be, s->sess, s, SMP_OPT_DIR_REQ | SMP_OPT_FINAL, srv->ssl_ctx.sni, SMP_T_STR);
/* restore the pointers */
b_adv(s->req.buf, rewind);
c_adv(&s->req, rewind);
if (smp_make_safe(smp)) {
ssl_sock_set_servername(srv_conn, smp->data.u.str.str);

View File

@ -221,13 +221,13 @@ cache_store_http_forward_data(struct stream *s, struct filter *filter,
pool_free(pool_head_cache_st, st);
} else {
/* Skip remaining headers to fill the cache */
b_adv(msg->chn->buf, st->hdrs_len);
c_adv(msg->chn, st->hdrs_len);
ret = shctx_row_data_append(shctx,
st->first_block,
(unsigned char *)bi_ptr(msg->chn->buf),
MIN(bi_contig_data(msg->chn->buf), len - st->hdrs_len));
/* Rewind the buffer to forward all data */
b_rew(msg->chn->buf, st->hdrs_len);
c_rew(msg->chn, st->hdrs_len);
st->hdrs_len = 0;
if (ret)
goto disable_cache;

View File

@ -38,7 +38,7 @@ unsigned long long __channel_forward(struct channel *chn, unsigned long long byt
* regular code paths.
*/
if (unlikely(chn->to_forward == CHN_INFINITE_FORWARD)) {
b_adv(chn->buf, chn->buf->i);
c_adv(chn, chn->buf->i);
return bytes;
}
@ -49,7 +49,7 @@ unsigned long long __channel_forward(struct channel *chn, unsigned long long byt
/* transfer as much as we can of buf->i */
forwarded = MIN(chn->buf->i, budget);
b_adv(chn->buf, forwarded);
c_adv(chn, forwarded);
budget -= forwarded;
if (!budget)
@ -125,7 +125,7 @@ int ci_putchr(struct channel *chn, char c)
if (chn->to_forward >= 1) {
if (chn->to_forward != CHN_INFINITE_FORWARD)
chn->to_forward--;
b_adv(chn->buf, 1);
c_adv(chn, 1);
}
chn->total++;
@ -180,7 +180,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len)
fwd = chn->to_forward;
chn->to_forward -= fwd;
}
b_adv(chn->buf, fwd);
c_adv(chn, fwd);
}
/* notify that some data was read from the SI into the buffer */
@ -223,7 +223,7 @@ struct buffer *ci_swpbuf(struct channel *chn, struct buffer *buf)
fwd = chn->to_forward;
chn->to_forward -= fwd;
}
b_adv(chn->buf, fwd);
c_adv(chn, fwd);
}
/* notify that some data was read from the SI into the buffer */

View File

@ -1089,7 +1089,7 @@ flt_xfer_data(struct stream *s, struct channel *chn, unsigned int an_bit)
goto end;
/* Consume data that all filters consider as forwarded. */
b_adv(chn->buf, ret);
c_adv(chn, ret);
/* Stop waiting data if the input in closed and no data is pending or if
* the output is closed. */

View File

@ -177,7 +177,8 @@ 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;
struct channel *chn = msg->chn;
struct buffer *buf = chn->buf;
unsigned int *nxt = &flt_rsp_nxt(filter);
unsigned int len;
int ret;
@ -190,9 +191,9 @@ comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
unsigned int fwd = flt_rsp_fwd(filter) + st->hdrs_len;
b_reset(tmpbuf);
b_adv(buf, fwd);
c_adv(chn, fwd);
ret = http_compression_buffer_init(buf, zbuf);
b_rew(buf, fwd);
c_rew(chn, fwd);
if (ret < 0) {
msg->chn->flags |= CF_WAKE_WRITE;
return 0;
@ -204,20 +205,20 @@ comp_http_data(struct stream *s, struct filter *filter, struct http_msg *msg)
len = MIN(tmpbuf->size - buffer_len(tmpbuf), len);
b_adv(buf, *nxt);
c_adv(chn, *nxt);
block = bi_contig_data(buf);
memcpy(bi_end(tmpbuf), bi_ptr(buf), block);
if (len > block)
memcpy(bi_end(tmpbuf)+block, buf->data, len-block);
b_rew(buf, *nxt);
c_rew(chn, *nxt);
tmpbuf->i += len;
ret = len;
}
else {
b_adv(buf, *nxt);
c_adv(chn, *nxt);
ret = http_compression_buffer_add_data(st, buf, zbuf, len);
b_rew(buf, *nxt);
c_rew(chn, *nxt);
if (ret < 0)
return ret;
}
@ -237,13 +238,13 @@ comp_http_chunk_trailers(struct stream *s, struct filter *filter,
if (!st->initialized) {
if (!st->finished) {
struct buffer *buf = msg->chn->buf;
struct channel *chn = msg->chn;
unsigned int fwd = flt_rsp_fwd(filter) + st->hdrs_len;
b_reset(tmpbuf);
b_adv(buf, fwd);
http_compression_buffer_init(buf, zbuf);
b_rew(buf, fwd);
c_adv(chn, fwd);
http_compression_buffer_init(chn->buf, zbuf);
c_rew(chn, fwd);
st->initialized = 1;
}
}
@ -305,9 +306,9 @@ comp_http_forward_data(struct stream *s, struct filter *filter,
}
st->consumed = len - st->hdrs_len - st->tlrs_len;
b_adv(msg->chn->buf, flt_rsp_fwd(filter) + st->hdrs_len);
c_adv(msg->chn, flt_rsp_fwd(filter) + st->hdrs_len);
ret = http_compression_buffer_end(st, s, msg->chn, &zbuf, msg->msg_state >= HTTP_MSG_TRAILERS);
b_rew(msg->chn->buf, flt_rsp_fwd(filter) + st->hdrs_len);
c_rew(msg->chn, flt_rsp_fwd(filter) + st->hdrs_len);
if (ret < 0)
return ret;
@ -762,7 +763,7 @@ http_compression_buffer_end(struct comp_state *st, struct stream *s,
}
/* copy the remaining data in the tmp buffer. */
b_adv(ib, st->consumed);
c_adv(chn, st->consumed);
if (ib->i > 0) {
left = bi_contig_data(ib);
memcpy(ob->p + ob->i, bi_ptr(ib), left);

View File

@ -465,9 +465,9 @@ trace_http_forward_data(struct stream *s, struct filter *filter,
FLT_NXT(filter, msg->chn), FLT_FWD(filter, msg->chn), ret);
if (conf->hexdump) {
b_adv(msg->chn->buf, FLT_FWD(filter, msg->chn));
c_adv(msg->chn, FLT_FWD(filter, msg->chn));
trace_hexdump(msg->chn->buf, ret);
b_rew(msg->chn->buf, FLT_FWD(filter, msg->chn));
c_rew(msg->chn, FLT_FWD(filter, msg->chn));
}
if ((ret != len) ||
@ -515,9 +515,9 @@ trace_tcp_forward_data(struct stream *s, struct filter *filter, struct channel *
FLT_FWD(filter, chn), ret);
if (conf->hexdump) {
b_adv(chn->buf, FLT_FWD(filter, chn));
c_adv(chn, FLT_FWD(filter, chn));
trace_hexdump(chn->buf, ret);
b_rew(chn->buf, FLT_FWD(filter, chn));
c_rew(chn, FLT_FWD(filter, chn));
}
if (ret != len)

View File

@ -3049,7 +3049,7 @@ __LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext
/* buffer replace considers that the input part is filled.
* so, I must forward these new data in the output part.
*/
b_adv(chn->buf, max);
c_adv(chn, max);
l += max;
lua_pop(L, 1);

View File

@ -1108,12 +1108,12 @@ void http_perform_server_redirect(struct stream *s, struct stream_interface *si)
* to temporarily rewind the buffer.
*/
txn = s->txn;
b_rew(s->req.buf, rewind = http_hdr_rewind(&txn->req));
c_rew(&s->req, rewind = http_hdr_rewind(&txn->req));
path = http_get_path(txn);
len = buffer_count(s->req.buf, path, b_ptr(s->req.buf, txn->req.sl.rq.u + txn->req.sl.rq.u_l));
b_adv(s->req.buf, rewind);
c_adv(&s->req, rewind);
if (!path)
return;
@ -4251,7 +4251,7 @@ int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* sr
old_o = http_hdr_rewind(&txn->req);
if (old_o) {
/* The request was already skipped, let's restore it */
b_rew(chn->buf, old_o);
c_rew(chn, old_o);
txn->req.next += old_o;
txn->req.sov += old_o;
}
@ -4278,7 +4278,7 @@ int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* sr
* so we don't have to adjust ->sol.
*/
old_o += chn->buf->i - old_i;
b_adv(chn->buf, old_o);
c_adv(chn, old_o);
txn->req.next -= old_o;
txn->req.sov -= old_o;
}
@ -6289,7 +6289,7 @@ http_msg_forward_body(struct stream *s, struct http_msg *msg)
ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
/* default_ret */ msg->next,
/* on_error */ goto error);
b_adv(chn->buf, ret);
c_adv(chn, ret);
msg->next -= ret;
if (unlikely(!(chn->flags & CF_WROTE_DATA) || msg->sov > 0))
msg->sov -= ret;
@ -6309,7 +6309,7 @@ http_msg_forward_body(struct stream *s, struct http_msg *msg)
ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
/* default_ret */ msg->next,
/* on_error */ goto error);
b_adv(chn->buf, ret);
c_adv(chn, ret);
msg->next -= ret;
if (!(chn->flags & CF_WROTE_DATA) || msg->sov > 0)
msg->sov -= ret;
@ -6420,7 +6420,7 @@ http_msg_forward_chunked_body(struct stream *s, struct http_msg *msg)
ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
/* default_ret */ msg->next,
/* on_error */ goto error);
b_adv(chn->buf, ret);
c_adv(chn, ret);
msg->next -= ret;
if (unlikely(!(chn->flags & CF_WROTE_DATA) || msg->sov > 0))
msg->sov -= ret;
@ -6439,7 +6439,7 @@ http_msg_forward_chunked_body(struct stream *s, struct http_msg *msg)
ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
/* default_ret */ msg->next,
/* on_error */ goto error);
b_adv(chn->buf, ret);
c_adv(chn, ret);
msg->next -= ret;
if (!(chn->flags & CF_WROTE_DATA) || msg->sov > 0)
msg->sov -= ret;

View File

@ -1203,7 +1203,7 @@ static void si_cs_recv_cb(struct conn_stream *cs)
fwd = ic->to_forward;
ic->to_forward -= fwd;
}
b_adv(ic->buf, fwd);
c_adv(ic, fwd);
}
ic->flags |= CF_READ_PARTIAL;