REORG: buffer: move buffer_flush, b_adv and b_rew to buffer.h
These one now operate over real buffers, not channels anymore.
diff --git a/include/common/buffer.h b/include/common/buffer.h
index a51744b..b1b7c46 100644
--- a/include/common/buffer.h
+++ b/include/common/buffer.h
@@ -61,6 +61,29 @@
__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 */
static inline char *bi_ptr(const struct buffer *b)
{
@@ -289,6 +312,16 @@
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 */
diff --git a/include/proto/channel.h b/include/proto/channel.h
index 83881ba..4aa6a57 100644
--- a/include/proto/channel.h
+++ b/include/proto/channel.h
@@ -158,29 +158,6 @@
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,
* excluding reserved space, which is preserved.
*/
@@ -222,17 +199,6 @@
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
* that any spliced data is not affected since we may not have any access to
* it.
diff --git a/src/backend.c b/src/backend.c
index 998e02c..ea0d894 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -419,12 +419,12 @@
args[0].data.str.len = px->hh_len;
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);
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)
return NULL;
@@ -905,13 +905,13 @@
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 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,
&s->txn.hdr_idx, srv->bind_hdr_occ, NULL, &vptr, &vlen)) {
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr =
htonl(inetaddr_host_lim(vptr, vptr + vlen));
}
- b_adv(s->req, rewind);
+ b_adv(&s->req->buf, rewind);
}
break;
default:
@@ -939,13 +939,13 @@
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 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,
&s->txn.hdr_idx, s->be->bind_hdr_occ, NULL, &vptr, &vlen)) {
((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr =
htonl(inetaddr_host_lim(vptr, vptr + vlen));
}
- b_adv(s->req, rewind);
+ b_adv(&s->req->buf, rewind);
}
break;
default:
diff --git a/src/channel.c b/src/channel.c
index 825ed7b..86fa811 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -60,13 +60,13 @@
/* OK this amount of bytes might be forwarded at once */
if (!bytes32)
return 0;
- b_adv(buf, bytes32);
+ b_adv(&buf->buf, bytes32);
return bytes;
}
}
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
* a byte count that does not fit into a 32-bit number.
@@ -159,7 +159,7 @@
if (buf->to_forward >= 1) {
if (buf->to_forward != BUF_INFINITE_FORWARD)
buf->to_forward--;
- b_adv(buf, 1);
+ b_adv(&buf->buf, 1);
}
buf->total++;
@@ -211,7 +211,7 @@
fwd = buf->to_forward;
buf->to_forward -= fwd;
}
- b_adv(buf, fwd);
+ b_adv(&buf->buf, fwd);
}
buf->flags &= ~BF_FULL;
diff --git a/src/proto_http.c b/src/proto_http.c
index f38e378..a3b2e9b 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -787,12 +787,12 @@
* to temporarily rewind the buffer.
*/
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);
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)
return;
@@ -3711,7 +3711,7 @@
old_o = req->buf.o;
if (old_o) {
/* 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;
@@ -3734,7 +3734,7 @@
* data to be forwarded in order to take into account the size
* variations.
*/
- b_adv(req, old_o + req->buf.i - old_i);
+ b_adv(&req->buf, old_o + req->buf.i - old_i);
}
return 0;
diff --git a/src/session.c b/src/session.c
index 1aec3bf..28dbd19 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1856,7 +1856,7 @@
buffer_auto_read(s->req);
buffer_auto_connect(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)
* to the consumer (which might possibly not be connected yet).
@@ -1991,7 +1991,7 @@
*/
buffer_auto_read(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)
* to the consumer.
diff --git a/src/stream_interface.c b/src/stream_interface.c
index 2066b06..14e2cd5 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -1071,7 +1071,7 @@
fwd = b->to_forward;
b->to_forward -= fwd;
}
- b_adv(b, fwd);
+ b_adv(&b->buf, fwd);
}
if (conn->flags & CO_FL_WAIT_L4_CONN)