buf->p = buf->data;
}
+/* Allocates a buffer and replaces *buf with this buffer. No control is made
+ * to check if *buf already pointed to another buffer. The allocated buffer
+ * is returned, or NULL in case no memory is available.
+ */
+static inline struct buffer *b_alloc(struct buffer **buf)
+{
+ *buf = pool_alloc_dirty(pool2_buffer);
+ if (likely(*buf)) {
+ (*buf)->size = pool2_buffer->size - sizeof(struct buffer);
+ b_reset(*buf);
+ }
+ return *buf;
+}
+
#endif /* _COMMON_BUFFER_H */
/*
/* We start by copying the current buffer's pending outgoing data into
* a new temporary buffer that we initialize with a new empty chunk.
*/
-
- out->size = global.tune.bufsize;
b_reset(out);
if (in->o > 0) {
if ((s->req = pool_alloc2(pool2_channel)) == NULL)
goto out_fail_req; /* no memory */
- if ((s->req->buf = pool_alloc2(pool2_buffer)) == NULL)
+ if (unlikely(b_alloc(&s->req->buf) == NULL))
goto out_fail_req_buf; /* no memory */
- s->req->buf->size = global.tune.bufsize;
- b_reset(s->req->buf);
channel_init(s->req);
s->req->prod = &s->si[0];
s->req->cons = &s->si[1];
if ((s->rep = pool_alloc2(pool2_channel)) == NULL)
goto out_fail_rep; /* no memory */
- if ((s->rep->buf = pool_alloc2(pool2_buffer)) == NULL)
+ if (unlikely(b_alloc(&s->rep->buf) == NULL))
goto out_fail_rep_buf; /* no memory */
- s->rep->buf->size = global.tune.bufsize;
- b_reset(s->rep->buf);
channel_init(s->rep);
s->rep->prod = &s->si[1];
s->rep->cons = &s->si[0];
*/
if (unlikely(tmpbuf == NULL)) {
/* this is the first time we need the compression buffer */
- tmpbuf = pool_alloc2(pool2_buffer);
- if (tmpbuf == NULL)
+ if (b_alloc(&tmpbuf) == NULL)
goto aborted_xfer; /* no memory */
}
if (unlikely((s->req = pool_alloc2(pool2_channel)) == NULL))
goto out_free_task; /* no memory */
- if (unlikely((s->req->buf = pool_alloc2(pool2_buffer)) == NULL))
+ if (unlikely(b_alloc(&s->req->buf) == NULL))
goto out_free_req; /* no memory */
if (unlikely((s->rep = pool_alloc2(pool2_channel)) == NULL))
goto out_free_req_buf; /* no memory */
- if (unlikely((s->rep->buf = pool_alloc2(pool2_buffer)) == NULL))
+ if (unlikely(b_alloc(&s->rep->buf) == NULL))
goto out_free_rep; /* no memory */
- /* initialize the request buffer */
- s->req->buf->size = global.tune.bufsize;
- b_reset(s->req->buf);
channel_init(s->req);
s->req->prod = &s->si[0];
s->req->cons = &s->si[1];
s->req->wex = TICK_ETERNITY;
s->req->analyse_exp = TICK_ETERNITY;
- /* initialize response buffer */
- s->rep->buf->size = global.tune.bufsize;
- b_reset(s->rep->buf);
channel_init(s->rep);
s->rep->prod = &s->si[1];
s->rep->cons = &s->si[0];