blob: 86fa811300a7724a57701c563718e35e20500322 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreauc7e42382012-08-24 19:22:53 +02002 * Channel management functions.
Willy Tarreaubaaee002006-06-26 02:48:02 +02003 *
Willy Tarreauc7e42382012-08-24 19:22:53 +02004 * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Krzysztof Piotr Oledzkiba8d7d32009-10-10 21:06:03 +020013#include <ctype.h>
Willy Tarreauc0dde7a2007-01-01 21:38:07 +010014#include <stdarg.h>
15#include <stdio.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020016#include <string.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020017
18#include <common/config.h>
Willy Tarreau7341d942007-05-13 19:56:02 +020019#include <common/memory.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020020#include <common/buffer.h>
21#include <proto/channel.h>
Willy Tarreau27a674e2009-08-17 07:23:33 +020022#include <types/global.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020023
Willy Tarreauc7e42382012-08-24 19:22:53 +020024
25/* Note: this code has not yet been completely cleaned up and still refers to
26 * the word "buffer" when "channel" is meant instead.
27 */
Willy Tarreau7341d942007-05-13 19:56:02 +020028struct pool_head *pool2_buffer;
29
30
31/* perform minimal intializations, report 0 in case of error, 1 if OK. */
32int init_buffer()
33{
Willy Tarreau7421efb2012-07-02 15:11:27 +020034 pool2_buffer = create_pool("buffer", sizeof(struct channel) + global.tune.bufsize, MEM_F_SHARED);
Willy Tarreau7341d942007-05-13 19:56:02 +020035 return pool2_buffer != NULL;
36}
37
Willy Tarreau0bc34932011-03-28 16:25:58 +020038/* Schedule up to <bytes> more bytes to be forwarded by the buffer without notifying
39 * the task. Any pending data in the buffer is scheduled to be sent as well,
40 * in the limit of the number of bytes to forward. This must be the only method
41 * to use to schedule bytes to be sent. If the requested number is too large, it
42 * is automatically adjusted. The number of bytes taken into account is returned.
Willy Tarreau2e046c62012-03-01 16:08:30 +010043 * Directly touching ->to_forward will cause lockups when ->o goes down to
Willy Tarreau0bc34932011-03-28 16:25:58 +020044 * zero if nobody is ready to push the remaining data.
45 */
Willy Tarreau7421efb2012-07-02 15:11:27 +020046unsigned long long buffer_forward(struct channel *buf, unsigned long long bytes)
Willy Tarreau0bc34932011-03-28 16:25:58 +020047{
Willy Tarreau0bc34932011-03-28 16:25:58 +020048 unsigned int new_forward;
Willy Tarreau02d6cfc2012-03-01 18:19:58 +010049 unsigned int forwarded;
Willy Tarreau328582c2012-05-05 23:32:27 +020050 unsigned int bytes32;
Willy Tarreau0bc34932011-03-28 16:25:58 +020051
Willy Tarreau328582c2012-05-05 23:32:27 +020052 bytes32 = bytes;
53
54 /* hint: avoid comparisons on long long for the fast case, since if the
55 * length does not fit in an unsigned it, it will never be forwarded at
56 * once anyway.
57 */
58 if (bytes <= ~0U) {
Willy Tarreau572bf902012-07-02 17:01:20 +020059 if (bytes32 <= buf->buf.i) {
Willy Tarreau328582c2012-05-05 23:32:27 +020060 /* OK this amount of bytes might be forwarded at once */
61 if (!bytes32)
62 return 0;
Willy Tarreaua75bcef2012-08-24 22:56:11 +020063 b_adv(&buf->buf, bytes32);
Willy Tarreau328582c2012-05-05 23:32:27 +020064 return bytes;
65 }
Willy Tarreau0bc34932011-03-28 16:25:58 +020066 }
67
Willy Tarreau572bf902012-07-02 17:01:20 +020068 forwarded = buf->buf.i;
Willy Tarreaua75bcef2012-08-24 22:56:11 +020069 b_adv(&buf->buf, buf->buf.i);
Willy Tarreau0bc34932011-03-28 16:25:58 +020070
Willy Tarreau0bc34932011-03-28 16:25:58 +020071 /* Note: the case below is the only case where we may return
72 * a byte count that does not fit into a 32-bit number.
73 */
74 if (likely(buf->to_forward == BUF_INFINITE_FORWARD))
75 return bytes;
76
Willy Tarreau02d6cfc2012-03-01 18:19:58 +010077 if (likely(bytes == BUF_INFINITE_FORWARD)) {
78 buf->to_forward = bytes;
79 return bytes;
80 }
81
82 new_forward = buf->to_forward + bytes - forwarded;
83 bytes = forwarded; /* at least those bytes were scheduled */
Willy Tarreau0bc34932011-03-28 16:25:58 +020084
85 if (new_forward <= buf->to_forward) {
86 /* integer overflow detected, let's assume no more than 2G at once */
87 new_forward = MID_RANGE(new_forward);
88 }
89
90 if (new_forward > buf->to_forward) {
91 bytes += new_forward - buf->to_forward;
92 buf->to_forward = new_forward;
93 }
94 return bytes;
95}
Willy Tarreaubaaee002006-06-26 02:48:02 +020096
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +020097/* writes <len> bytes from message <msg> to buffer <buf>. Returns -1 in case of
Willy Tarreau078e2942009-08-18 07:19:39 +020098 * success, -2 if the message is larger than the buffer size, or the number of
99 * bytes available otherwise. The send limit is automatically adjusted with the
100 * amount of data written. FIXME-20060521: handle unaligned data.
Willy Tarreau363a5bb2012-03-02 20:14:45 +0100101 * Note: this function appends data to the buffer's output and possibly overwrites
102 * any pending input data which are assumed not to exist.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200103 */
Willy Tarreau7421efb2012-07-02 15:11:27 +0200104int bo_inject(struct channel *buf, const char *msg, int len)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105{
106 int max;
107
Willy Tarreauaeac3192009-08-31 08:09:57 +0200108 if (len == 0)
109 return -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200110
Willy Tarreau572bf902012-07-02 17:01:20 +0200111 if (len > buf->buf.size) {
Willy Tarreau078e2942009-08-18 07:19:39 +0200112 /* we can't write this chunk and will never be able to, because
113 * it is larger than the buffer. This must be reported as an
114 * error. Then we return -2 so that writers that don't care can
115 * ignore it and go on, and others can check for this value.
116 */
117 return -2;
118 }
119
Willy Tarreau572bf902012-07-02 17:01:20 +0200120 max = buffer_realign(&buf->buf);
Willy Tarreauaeac3192009-08-31 08:09:57 +0200121
Willy Tarreaubaaee002006-06-26 02:48:02 +0200122 if (len > max)
123 return max;
124
Willy Tarreau572bf902012-07-02 17:01:20 +0200125 memcpy(buf->buf.p, msg, len);
126 buf->buf.o += len;
127 buf->buf.p = b_ptr(&buf->buf, len);
Willy Tarreau35d66b02007-01-02 00:28:21 +0100128 buf->total += len;
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +0200129
Willy Tarreau8e21bb92012-08-24 22:40:29 +0200130 buf->flags &= ~BF_FULL;
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200131 if (bi_full(buf))
Willy Tarreaue393fe22008-08-16 22:18:07 +0200132 buf->flags |= BF_FULL;
133
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +0200134 return -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200135}
136
Willy Tarreau74b08c92010-09-08 17:04:31 +0200137/* Tries to copy character <c> into buffer <buf> after length controls. The
Willy Tarreau2e046c62012-03-01 16:08:30 +0100138 * ->o and to_forward pointers are updated. If the buffer's input is
Willy Tarreau74b08c92010-09-08 17:04:31 +0200139 * closed, -2 is returned. If there is not enough room left in the buffer, -1
140 * is returned. Otherwise the number of bytes copied is returned (1). Buffer
141 * flags FULL, EMPTY and READ_PARTIAL are updated if some data can be
142 * transferred.
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100143 */
Willy Tarreau7421efb2012-07-02 15:11:27 +0200144int bi_putchr(struct channel *buf, char c)
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100145{
Willy Tarreau74b08c92010-09-08 17:04:31 +0200146 if (unlikely(buffer_input_closed(buf)))
147 return -2;
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100148
Willy Tarreau74b08c92010-09-08 17:04:31 +0200149 if (buf->flags & BF_FULL)
Krzysztof Piotr Oledzki8e4b21d2008-04-20 21:34:47 +0200150 return -1;
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100151
Willy Tarreau572bf902012-07-02 17:01:20 +0200152 *bi_end(&buf->buf) = c;
Willy Tarreau74b08c92010-09-08 17:04:31 +0200153
Willy Tarreau572bf902012-07-02 17:01:20 +0200154 buf->buf.i++;
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200155 if (bi_full(buf))
Willy Tarreau74b08c92010-09-08 17:04:31 +0200156 buf->flags |= BF_FULL;
157 buf->flags |= BF_READ_PARTIAL;
158
Willy Tarreau74b08c92010-09-08 17:04:31 +0200159 if (buf->to_forward >= 1) {
160 if (buf->to_forward != BUF_INFINITE_FORWARD)
161 buf->to_forward--;
Willy Tarreaua75bcef2012-08-24 22:56:11 +0200162 b_adv(&buf->buf, 1);
Willy Tarreau74b08c92010-09-08 17:04:31 +0200163 }
164
165 buf->total++;
166 return 1;
167}
168
169/* Tries to copy block <blk> at once into buffer <buf> after length controls.
Willy Tarreau2e046c62012-03-01 16:08:30 +0100170 * The ->o and to_forward pointers are updated. If the buffer's input is
Willy Tarreau74b08c92010-09-08 17:04:31 +0200171 * closed, -2 is returned. If the block is too large for this buffer, -3 is
172 * returned. If there is not enough room left in the buffer, -1 is returned.
173 * Otherwise the number of bytes copied is returned (0 being a valid number).
174 * Buffer flags FULL, EMPTY and READ_PARTIAL are updated if some data can be
175 * transferred.
176 */
Willy Tarreau7421efb2012-07-02 15:11:27 +0200177int bi_putblk(struct channel *buf, const char *blk, int len)
Willy Tarreau74b08c92010-09-08 17:04:31 +0200178{
179 int max;
180
181 if (unlikely(buffer_input_closed(buf)))
182 return -2;
183
Willy Tarreau591fedc2010-08-10 15:28:21 +0200184 max = buffer_max_len(buf);
Willy Tarreau572bf902012-07-02 17:01:20 +0200185 if (unlikely(len > max - buffer_len(&buf->buf))) {
Willy Tarreau591fedc2010-08-10 15:28:21 +0200186 /* we can't write this chunk right now because the buffer is
187 * almost full or because the block is too large. Return the
188 * available space or -2 if impossible.
Willy Tarreau078e2942009-08-18 07:19:39 +0200189 */
Willy Tarreau591fedc2010-08-10 15:28:21 +0200190 if (len > max)
Willy Tarreau74b08c92010-09-08 17:04:31 +0200191 return -3;
Willy Tarreau078e2942009-08-18 07:19:39 +0200192
Willy Tarreau74b08c92010-09-08 17:04:31 +0200193 return -1;
Willy Tarreau591fedc2010-08-10 15:28:21 +0200194 }
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100195
Willy Tarreau74b08c92010-09-08 17:04:31 +0200196 if (unlikely(len == 0))
197 return 0;
198
Willy Tarreau591fedc2010-08-10 15:28:21 +0200199 /* OK so the data fits in the buffer in one or two blocks */
Willy Tarreau572bf902012-07-02 17:01:20 +0200200 max = buffer_contig_space_with_res(&buf->buf, buf->buf.size - max);
201 memcpy(bi_end(&buf->buf), blk, MIN(len, max));
Willy Tarreauaeac3192009-08-31 08:09:57 +0200202 if (len > max)
Willy Tarreau572bf902012-07-02 17:01:20 +0200203 memcpy(buf->buf.data, blk + max, len - max);
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100204
Willy Tarreau572bf902012-07-02 17:01:20 +0200205 buf->buf.i += len;
Willy Tarreauaeac3192009-08-31 08:09:57 +0200206 buf->total += len;
Willy Tarreau31971e52009-09-20 12:07:52 +0200207 if (buf->to_forward) {
208 unsigned long fwd = len;
209 if (buf->to_forward != BUF_INFINITE_FORWARD) {
210 if (fwd > buf->to_forward)
211 fwd = buf->to_forward;
212 buf->to_forward -= fwd;
213 }
Willy Tarreaua75bcef2012-08-24 22:56:11 +0200214 b_adv(&buf->buf, fwd);
Willy Tarreauaeac3192009-08-31 08:09:57 +0200215 }
216
Willy Tarreauba0b63d2009-09-20 08:09:44 +0200217 buf->flags &= ~BF_FULL;
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200218 if (bi_full(buf))
Willy Tarreaue393fe22008-08-16 22:18:07 +0200219 buf->flags |= BF_FULL;
220
Willy Tarreaufb0e9202009-09-23 23:47:55 +0200221 /* notify that some data was read from the SI into the buffer */
222 buf->flags |= BF_READ_PARTIAL;
Willy Tarreau74b08c92010-09-08 17:04:31 +0200223 return len;
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100224}
225
Willy Tarreau74b08c92010-09-08 17:04:31 +0200226/* Gets one text line out of a buffer from a stream interface.
Willy Tarreau4fe7a2e2009-09-01 06:41:32 +0200227 * Return values :
228 * >0 : number of bytes read. Includes the \n if present before len or end.
Willy Tarreau74b08c92010-09-08 17:04:31 +0200229 * =0 : no '\n' before end found. <str> is left undefined.
230 * <0 : no more bytes readable because output is shut.
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200231 * The buffer status is not changed. The caller must call bo_skip() to
Willy Tarreau4fe7a2e2009-09-01 06:41:32 +0200232 * update it. The '\n' is waited for as long as neither the buffer nor the
233 * output are full. If either of them is full, the string may be returned
234 * as is, without the '\n'.
235 */
Willy Tarreau7421efb2012-07-02 15:11:27 +0200236int bo_getline(struct channel *buf, char *str, int len)
Willy Tarreau4fe7a2e2009-09-01 06:41:32 +0200237{
238 int ret, max;
239 char *p;
240
241 ret = 0;
242 max = len;
Willy Tarreau74b08c92010-09-08 17:04:31 +0200243
244 /* closed or empty + imminent close = -1; empty = 0 */
Willy Tarreau8e21bb92012-08-24 22:40:29 +0200245 if (unlikely((buf->flags & BF_SHUTW) || channel_is_empty(buf))) {
Willy Tarreau4fe7a2e2009-09-01 06:41:32 +0200246 if (buf->flags & (BF_SHUTW|BF_SHUTW_NOW))
247 ret = -1;
248 goto out;
249 }
250
Willy Tarreau572bf902012-07-02 17:01:20 +0200251 p = bo_ptr(&buf->buf);
Willy Tarreau4fe7a2e2009-09-01 06:41:32 +0200252
Willy Tarreau572bf902012-07-02 17:01:20 +0200253 if (max > buf->buf.o) {
254 max = buf->buf.o;
Willy Tarreau2e1dd3d2009-09-23 22:56:07 +0200255 str[max-1] = 0;
Willy Tarreau4fe7a2e2009-09-01 06:41:32 +0200256 }
257 while (max) {
258 *str++ = *p;
259 ret++;
260 max--;
261
262 if (*p == '\n')
263 break;
Willy Tarreau572bf902012-07-02 17:01:20 +0200264 p = buffer_wrap_add(&buf->buf, p + 1);
Willy Tarreau4fe7a2e2009-09-01 06:41:32 +0200265 }
Willy Tarreau572bf902012-07-02 17:01:20 +0200266 if (ret > 0 && ret < len && ret < buf->buf.o &&
Willy Tarreau2e1dd3d2009-09-23 22:56:07 +0200267 *(str-1) != '\n' &&
268 !(buf->flags & (BF_SHUTW|BF_SHUTW_NOW)))
Willy Tarreau4fe7a2e2009-09-01 06:41:32 +0200269 ret = 0;
270 out:
271 if (max)
272 *str = 0;
273 return ret;
274}
275
Willy Tarreau74b08c92010-09-08 17:04:31 +0200276/* Gets one full block of data at once from a buffer, optionally from a
277 * specific offset. Return values :
278 * >0 : number of bytes read, equal to requested size.
279 * =0 : not enough data available. <blk> is left undefined.
280 * <0 : no more bytes readable because output is shut.
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200281 * The buffer status is not changed. The caller must call bo_skip() to
Willy Tarreau74b08c92010-09-08 17:04:31 +0200282 * update it.
283 */
Willy Tarreau7421efb2012-07-02 15:11:27 +0200284int bo_getblk(struct channel *buf, char *blk, int len, int offset)
Willy Tarreau74b08c92010-09-08 17:04:31 +0200285{
286 int firstblock;
287
288 if (buf->flags & BF_SHUTW)
289 return -1;
290
Willy Tarreau572bf902012-07-02 17:01:20 +0200291 if (len + offset > buf->buf.o) {
Willy Tarreau74b08c92010-09-08 17:04:31 +0200292 if (buf->flags & (BF_SHUTW|BF_SHUTW_NOW))
293 return -1;
294 return 0;
295 }
296
Willy Tarreau572bf902012-07-02 17:01:20 +0200297 firstblock = buf->buf.data + buf->buf.size - bo_ptr(&buf->buf);
Willy Tarreau74b08c92010-09-08 17:04:31 +0200298 if (firstblock > offset) {
299 if (firstblock >= len + offset) {
Willy Tarreau572bf902012-07-02 17:01:20 +0200300 memcpy(blk, bo_ptr(&buf->buf) + offset, len);
Willy Tarreau74b08c92010-09-08 17:04:31 +0200301 return len;
302 }
303
Willy Tarreau572bf902012-07-02 17:01:20 +0200304 memcpy(blk, bo_ptr(&buf->buf) + offset, firstblock - offset);
305 memcpy(blk + firstblock - offset, buf->buf.data, len - firstblock + offset);
Willy Tarreau74b08c92010-09-08 17:04:31 +0200306 return len;
307 }
308
Willy Tarreau572bf902012-07-02 17:01:20 +0200309 memcpy(blk, buf->buf.data + offset - firstblock, len);
Willy Tarreau74b08c92010-09-08 17:04:31 +0200310 return len;
311}
312
Willy Tarreau19ae56b2011-11-28 10:36:13 +0100313/* This function writes the string <str> at position <pos> which must be in
314 * buffer <b>, and moves <end> just after the end of <str>. <b>'s parameters
Willy Tarreaua458b672012-03-05 11:17:50 +0100315 * <l> and <r> are updated to be valid after the shift. The shift value
Willy Tarreau19ae56b2011-11-28 10:36:13 +0100316 * (positive or negative) is returned. If there's no space left, the move is
Willy Tarreau8e21bb92012-08-24 22:40:29 +0200317 * not done. The function does not adjust ->o because it does not make sense to
318 * use it on data scheduled to be sent. For the same reason, it does not make
319 * sense to call this function on unparsed data, so <orig> is not updated. The
320 * string length is taken from parameter <len>. If <len> is null, the <str>
321 * pointer is allowed to be null.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200322 */
Willy Tarreau7421efb2012-07-02 15:11:27 +0200323int buffer_replace2(struct channel *b, char *pos, char *end, const char *str, int len)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200324{
325 int delta;
326
327 delta = len - (end - pos);
328
Willy Tarreau572bf902012-07-02 17:01:20 +0200329 if (bi_end(&b->buf) + delta >= b->buf.data + b->buf.size)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200330 return 0; /* no space left */
331
Willy Tarreau572bf902012-07-02 17:01:20 +0200332 if (buffer_not_empty(&b->buf) &&
333 bi_end(&b->buf) + delta > bo_ptr(&b->buf) &&
334 bo_ptr(&b->buf) >= bi_end(&b->buf))
Willy Tarreaubbfa7932010-01-25 01:49:57 +0100335 return 0; /* no space left before wrapping data */
336
Willy Tarreaubaaee002006-06-26 02:48:02 +0200337 /* first, protect the end of the buffer */
Willy Tarreau572bf902012-07-02 17:01:20 +0200338 memmove(end + delta, end, bi_end(&b->buf) - end);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200339
340 /* now, copy str over pos */
341 if (len)
342 memcpy(pos, str, len);
343
Willy Tarreau572bf902012-07-02 17:01:20 +0200344 b->buf.i += delta;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200345
Willy Tarreauba0b63d2009-09-20 08:09:44 +0200346 b->flags &= ~BF_FULL;
Willy Tarreau572bf902012-07-02 17:01:20 +0200347 if (buffer_len(&b->buf) == 0)
348 b->buf.p = b->buf.data;
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200349 if (bi_full(b))
Willy Tarreaue393fe22008-08-16 22:18:07 +0200350 b->flags |= BF_FULL;
351
Willy Tarreaubaaee002006-06-26 02:48:02 +0200352 return delta;
353}
354
Willy Tarreaubaaee002006-06-26 02:48:02 +0200355/*
Willy Tarreau4af6f3a2007-03-18 22:36:26 +0100356 * Inserts <str> followed by "\r\n" at position <pos> in buffer <b>. The <len>
357 * argument informs about the length of string <str> so that we don't have to
358 * measure it. It does not include the "\r\n". If <str> is NULL, then the buffer
359 * is only opened for len+2 bytes but nothing is copied in. It may be useful in
Willy Tarreaua458b672012-03-05 11:17:50 +0100360 * some circumstances. The send limit is *not* adjusted. Same comments as above
361 * for the valid use cases.
Willy Tarreau4af6f3a2007-03-18 22:36:26 +0100362 *
363 * The number of bytes added is returned on success. 0 is returned on failure.
364 */
Willy Tarreau7421efb2012-07-02 15:11:27 +0200365int buffer_insert_line2(struct channel *b, char *pos, const char *str, int len)
Willy Tarreau4af6f3a2007-03-18 22:36:26 +0100366{
367 int delta;
368
369 delta = len + 2;
370
Willy Tarreau572bf902012-07-02 17:01:20 +0200371 if (bi_end(&b->buf) + delta >= b->buf.data + b->buf.size)
Willy Tarreau4af6f3a2007-03-18 22:36:26 +0100372 return 0; /* no space left */
373
374 /* first, protect the end of the buffer */
Willy Tarreau572bf902012-07-02 17:01:20 +0200375 memmove(pos + delta, pos, bi_end(&b->buf) - pos);
Willy Tarreau4af6f3a2007-03-18 22:36:26 +0100376
377 /* now, copy str over pos */
378 if (len && str) {
379 memcpy(pos, str, len);
380 pos[len] = '\r';
381 pos[len + 1] = '\n';
382 }
383
Willy Tarreau572bf902012-07-02 17:01:20 +0200384 b->buf.i += delta;
Willy Tarreau4af6f3a2007-03-18 22:36:26 +0100385
Willy Tarreauba0b63d2009-09-20 08:09:44 +0200386 b->flags &= ~BF_FULL;
Willy Tarreau9dab5fc2012-05-07 11:56:55 +0200387 if (bi_full(b))
Willy Tarreaue393fe22008-08-16 22:18:07 +0200388 b->flags |= BF_FULL;
389
Willy Tarreau4af6f3a2007-03-18 22:36:26 +0100390 return delta;
391}
392
Krzysztof Piotr Oledzkiba8d7d32009-10-10 21:06:03 +0200393/*
Willy Tarreaubaaee002006-06-26 02:48:02 +0200394 * Local variables:
395 * c-indent-level: 8
396 * c-basic-offset: 8
397 * End:
398 */