]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: buffer: move buffer_flush, b_adv and b_rew to buffer.h
authorWilly Tarreau <wtarreau@exceliance.fr>
Fri, 24 Aug 2012 20:56:11 +0000 (22:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 3 Sep 2012 18:47:32 +0000 (20:47 +0200)
These one now operate over real buffers, not channels anymore.

include/common/buffer.h
include/proto/channel.h
src/backend.c
src/channel.c
src/proto_http.c
src/session.c
src/stream_interface.c

index a51744bb076c375cdcc71e46811686fa648d384a..b1b7c4607dcee935bd5d2c020fdb9eb31345f3b8 100644 (file)
@@ -61,6 +61,29 @@ void buffer_bounce_realign(struct buffer *buf);
                __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 @@ static inline int buffer_realign(struct buffer *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 */
 
index 83881ba8b2262c06818633277e11c3594cc5284d..4aa6a572219378adb51433d7363fde2e27067a9d 100644 (file)
@@ -158,29 +158,6 @@ static inline int bi_avail(const struct channel *b)
        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 @@ static inline void buffer_check_timeouts(struct channel *b)
                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.
index 998e02c1fa967a05c6914f50f42b878c9e5b93c6..ea0d8949aaca71e7156ee3531dc92775a8bf67e0 100644 (file)
@@ -419,12 +419,12 @@ struct server *get_server_rch(struct session *s)
        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 @@ 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_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 @@ 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_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:
index 825ed7bcb8faabfea77e4a1cb0cb076301dcd3a2..86fa811300a7724a57701c563718e35e20500322 100644 (file)
@@ -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 */
                        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 @@ int bi_putchr(struct channel *buf, char c)
        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 @@ int bi_putblk(struct channel *buf, const char *blk, int len)
                                fwd = buf->to_forward;
                        buf->to_forward -= fwd;
                }
-               b_adv(buf, fwd);
+               b_adv(&buf->buf, fwd);
        }
 
        buf->flags &= ~BF_FULL;
index f38e37877880eda0a63e106adcbe40f562b57c9e..a3b2e9ba36f3efb8f5be114f24bc6b20c9aa5b93 100644 (file)
@@ -787,12 +787,12 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
         * 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 @@ int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* sr
        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 @@ 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
                 * variations.
                 */
-               b_adv(req, old_o + req->buf.i - old_i);
+               b_adv(&req->buf, old_o + req->buf.i - old_i);
        }
 
        return 0;
index 1aec3bfc0d12b238016a2d9faf5a639b318baeb0..28dbd19392cf1cad15688c40158655a5b23a11ea 100644 (file)
@@ -1856,7 +1856,7 @@ struct task *process_session(struct task *t)
                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 @@ struct task *process_session(struct task *t)
                 */
                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.
index 2066b06bac4adf77b73ebb4a8c2510d198b9e03f..14e2cd5ce474bcbfcee7f2d1254193ca84f38c8f 100644 (file)
@@ -1071,7 +1071,7 @@ void si_conn_recv_cb(struct connection *conn)
                                        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)