mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
REORG: buffer: move buffer_flush, b_adv and b_rew to buffer.h
These one now operate over real buffers, not channels anymore.
This commit is contained in:
parent
8e21bb9e52
commit
a75bcef867
@ -61,6 +61,29 @@ void buffer_bounce_realign(struct buffer *buf);
|
|||||||
__ret; \
|
__ret; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/* 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 */
|
/* Returns the start of the input data in a buffer */
|
||||||
static inline char *bi_ptr(const struct buffer *b)
|
static inline char *bi_ptr(const struct buffer *b)
|
||||||
{
|
{
|
||||||
@ -289,6 +312,16 @@ static inline int buffer_realign(struct buffer *buf)
|
|||||||
return buffer_contig_space(buf);
|
return buffer_contig_space(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Schedule all remaining buffer data to be sent. ->o is not touched if it
|
||||||
|
* already covers those data. That permits doing a flush even after a forward,
|
||||||
|
* although not recommended.
|
||||||
|
*/
|
||||||
|
static inline void buffer_flush(struct buffer *buf)
|
||||||
|
{
|
||||||
|
buf->p = buffer_wrap_add(buf, buf->p + buf->i);
|
||||||
|
buf->o += buf->i;
|
||||||
|
buf->i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _COMMON_BUFFER_H */
|
#endif /* _COMMON_BUFFER_H */
|
||||||
|
|
||||||
|
@ -158,29 +158,6 @@ static inline int bi_avail(const struct channel *b)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 channel *b, unsigned int adv)
|
|
||||||
{
|
|
||||||
b->buf.i -= adv;
|
|
||||||
b->buf.o += adv;
|
|
||||||
b->buf.p = b_ptr(&b->buf, 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 channel *b, unsigned int adv)
|
|
||||||
{
|
|
||||||
b->buf.i += adv;
|
|
||||||
b->buf.o -= adv;
|
|
||||||
b->buf.p = b_ptr(&b->buf, (int)-adv);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the amount of bytes that can be written into the buffer at once,
|
/* Return the amount of bytes that can be written into the buffer at once,
|
||||||
* excluding reserved space, which is preserved.
|
* excluding reserved space, which is preserved.
|
||||||
*/
|
*/
|
||||||
@ -222,17 +199,6 @@ static inline void buffer_check_timeouts(struct channel *b)
|
|||||||
b->flags |= BF_ANA_TIMEOUT;
|
b->flags |= BF_ANA_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Schedule all remaining buffer data to be sent. ->o is not touched if it
|
|
||||||
* already covers those data. That permits doing a flush even after a forward,
|
|
||||||
* although not recommended.
|
|
||||||
*/
|
|
||||||
static inline void buffer_flush(struct channel *buf)
|
|
||||||
{
|
|
||||||
buf->buf.p = buffer_wrap_add(&buf->buf, buf->buf.p + buf->buf.i);
|
|
||||||
buf->buf.o += buf->buf.i;
|
|
||||||
buf->buf.i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Erase any content from buffer <buf> and adjusts flags accordingly. Note
|
/* Erase any content from buffer <buf> and adjusts flags accordingly. Note
|
||||||
* that any spliced data is not affected since we may not have any access to
|
* that any spliced data is not affected since we may not have any access to
|
||||||
* it.
|
* it.
|
||||||
|
@ -419,12 +419,12 @@ struct server *get_server_rch(struct session *s)
|
|||||||
args[0].data.str.len = px->hh_len;
|
args[0].data.str.len = px->hh_len;
|
||||||
args[1].type = ARGT_STOP;
|
args[1].type = ARGT_STOP;
|
||||||
|
|
||||||
b_rew(s->req, rewind = s->req->buf.o);
|
b_rew(&s->req->buf, rewind = s->req->buf.o);
|
||||||
|
|
||||||
ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp);
|
ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp);
|
||||||
len = smp.data.str.len;
|
len = smp.data.str.len;
|
||||||
|
|
||||||
b_adv(s->req, rewind);
|
b_adv(&s->req->buf, rewind);
|
||||||
|
|
||||||
if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || len == 0)
|
if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || len == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -905,13 +905,13 @@ static void assign_tproxy_address(struct session *s)
|
|||||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0;
|
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0;
|
||||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = 0;
|
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = 0;
|
||||||
|
|
||||||
b_rew(s->req, rewind = s->req->buf.o);
|
b_rew(&s->req->buf, rewind = s->req->buf.o);
|
||||||
if (http_get_hdr(&s->txn.req, srv->bind_hdr_name, srv->bind_hdr_len,
|
if (http_get_hdr(&s->txn.req, srv->bind_hdr_name, srv->bind_hdr_len,
|
||||||
&s->txn.hdr_idx, srv->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
&s->txn.hdr_idx, srv->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr =
|
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr =
|
||||||
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
||||||
}
|
}
|
||||||
b_adv(s->req, rewind);
|
b_adv(&s->req->buf, rewind);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -939,13 +939,13 @@ static void assign_tproxy_address(struct session *s)
|
|||||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0;
|
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0;
|
||||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = 0;
|
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = 0;
|
||||||
|
|
||||||
b_rew(s->req, rewind = s->req->buf.o);
|
b_rew(&s->req->buf, rewind = s->req->buf.o);
|
||||||
if (http_get_hdr(&s->txn.req, s->be->bind_hdr_name, s->be->bind_hdr_len,
|
if (http_get_hdr(&s->txn.req, s->be->bind_hdr_name, s->be->bind_hdr_len,
|
||||||
&s->txn.hdr_idx, s->be->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
&s->txn.hdr_idx, s->be->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||||
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr =
|
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr =
|
||||||
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
||||||
}
|
}
|
||||||
b_adv(s->req, rewind);
|
b_adv(&s->req->buf, rewind);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -60,13 +60,13 @@ unsigned long long buffer_forward(struct channel *buf, unsigned long long bytes)
|
|||||||
/* OK this amount of bytes might be forwarded at once */
|
/* OK this amount of bytes might be forwarded at once */
|
||||||
if (!bytes32)
|
if (!bytes32)
|
||||||
return 0;
|
return 0;
|
||||||
b_adv(buf, bytes32);
|
b_adv(&buf->buf, bytes32);
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forwarded = buf->buf.i;
|
forwarded = buf->buf.i;
|
||||||
b_adv(buf, buf->buf.i);
|
b_adv(&buf->buf, buf->buf.i);
|
||||||
|
|
||||||
/* Note: the case below is the only case where we may return
|
/* Note: the case below is the only case where we may return
|
||||||
* a byte count that does not fit into a 32-bit number.
|
* a byte count that does not fit into a 32-bit number.
|
||||||
@ -159,7 +159,7 @@ int bi_putchr(struct channel *buf, char c)
|
|||||||
if (buf->to_forward >= 1) {
|
if (buf->to_forward >= 1) {
|
||||||
if (buf->to_forward != BUF_INFINITE_FORWARD)
|
if (buf->to_forward != BUF_INFINITE_FORWARD)
|
||||||
buf->to_forward--;
|
buf->to_forward--;
|
||||||
b_adv(buf, 1);
|
b_adv(&buf->buf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->total++;
|
buf->total++;
|
||||||
@ -211,7 +211,7 @@ int bi_putblk(struct channel *buf, const char *blk, int len)
|
|||||||
fwd = buf->to_forward;
|
fwd = buf->to_forward;
|
||||||
buf->to_forward -= fwd;
|
buf->to_forward -= fwd;
|
||||||
}
|
}
|
||||||
b_adv(buf, fwd);
|
b_adv(&buf->buf, fwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->flags &= ~BF_FULL;
|
buf->flags &= ~BF_FULL;
|
||||||
|
@ -787,12 +787,12 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
|
|||||||
* to temporarily rewind the buffer.
|
* to temporarily rewind the buffer.
|
||||||
*/
|
*/
|
||||||
txn = &s->txn;
|
txn = &s->txn;
|
||||||
b_rew(s->req, rewind = s->req->buf.o);
|
b_rew(&s->req->buf, rewind = s->req->buf.o);
|
||||||
|
|
||||||
path = http_get_path(txn);
|
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));
|
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, rewind);
|
b_adv(&s->req->buf, rewind);
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
return;
|
return;
|
||||||
@ -3711,7 +3711,7 @@ int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* sr
|
|||||||
old_o = req->buf.o;
|
old_o = req->buf.o;
|
||||||
if (old_o) {
|
if (old_o) {
|
||||||
/* The request was already skipped, let's restore it */
|
/* The request was already skipped, let's restore it */
|
||||||
b_rew(req, old_o);
|
b_rew(&req->buf, old_o);
|
||||||
}
|
}
|
||||||
|
|
||||||
old_i = req->buf.i;
|
old_i = req->buf.i;
|
||||||
@ -3734,7 +3734,7 @@ int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* sr
|
|||||||
* data to be forwarded in order to take into account the size
|
* data to be forwarded in order to take into account the size
|
||||||
* variations.
|
* variations.
|
||||||
*/
|
*/
|
||||||
b_adv(req, old_o + req->buf.i - old_i);
|
b_adv(&req->buf, old_o + req->buf.i - old_i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1856,7 +1856,7 @@ struct task *process_session(struct task *t)
|
|||||||
buffer_auto_read(s->req);
|
buffer_auto_read(s->req);
|
||||||
buffer_auto_connect(s->req);
|
buffer_auto_connect(s->req);
|
||||||
buffer_auto_close(s->req);
|
buffer_auto_close(s->req);
|
||||||
buffer_flush(s->req);
|
buffer_flush(&s->req->buf);
|
||||||
|
|
||||||
/* We'll let data flow between the producer (if still connected)
|
/* We'll let data flow between the producer (if still connected)
|
||||||
* to the consumer (which might possibly not be connected yet).
|
* to the consumer (which might possibly not be connected yet).
|
||||||
@ -1991,7 +1991,7 @@ struct task *process_session(struct task *t)
|
|||||||
*/
|
*/
|
||||||
buffer_auto_read(s->rep);
|
buffer_auto_read(s->rep);
|
||||||
buffer_auto_close(s->rep);
|
buffer_auto_close(s->rep);
|
||||||
buffer_flush(s->rep);
|
buffer_flush(&s->rep->buf);
|
||||||
|
|
||||||
/* We'll let data flow between the producer (if still connected)
|
/* We'll let data flow between the producer (if still connected)
|
||||||
* to the consumer.
|
* to the consumer.
|
||||||
|
@ -1071,7 +1071,7 @@ void si_conn_recv_cb(struct connection *conn)
|
|||||||
fwd = b->to_forward;
|
fwd = b->to_forward;
|
||||||
b->to_forward -= fwd;
|
b->to_forward -= fwd;
|
||||||
}
|
}
|
||||||
b_adv(b, fwd);
|
b_adv(&b->buf, fwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn->flags & CO_FL_WAIT_L4_CONN)
|
if (conn->flags & CO_FL_WAIT_L4_CONN)
|
||||||
|
Loading…
Reference in New Issue
Block a user