~ubuntu-branches/ubuntu/utopic/haproxy/utopic-proposed

« back to all changes in this revision

Viewing changes to src/buffers.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Cornet
  • Date: 2009-06-26 00:11:01 UTC
  • mfrom: (1.1.6 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090626001101-qo261ke2mjh3d8cn
* New Upstream Version (Closes: #534583).
* Add contrib directory in docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
 
32
32
/* writes <len> bytes from message <msg> to buffer <buf>. Returns -1 in case of
33
 
 * success, or the number of bytes available otherwise.
 
33
 * success, or the number of bytes available otherwise. The send limit is
 
34
 * automatically adjusted with the amount of data written.
34
35
 * FIXME-20060521: handle unaligned data.
35
36
 */
36
37
int buffer_write(struct buffer *buf, const char *msg, int len)
44
45
 
45
46
        memcpy(buf->r, msg, len);
46
47
        buf->l += len;
 
48
        buf->send_max += len;
47
49
        buf->r += len;
48
50
        buf->total += len;
49
51
        if (buf->r == buf->data + BUFSIZE)
50
52
                buf->r = buf->data;
51
53
 
 
54
        buf->flags &= ~(BF_EMPTY|BF_FULL);
 
55
        if (buf->l == 0)
 
56
                buf->flags |= BF_EMPTY;
 
57
        if (buf->l >= buf->max_len)
 
58
                buf->flags |= BF_FULL;
 
59
 
52
60
        return -1;
53
61
}
54
62
 
55
63
/* writes the chunk <chunk> to buffer <buf>. Returns -1 in case of
56
64
 * success, or the number of bytes available otherwise. If the chunk
57
 
 * has been written, its size is automatically reset to zero.
 
65
 * has been written, its size is automatically reset to zero. The send limit is
 
66
 * automatically adjusted with the amount of data written.
58
67
 */
59
68
int buffer_write_chunk(struct buffer *buf, struct chunk *chunk)
60
69
{
70
79
 
71
80
        memcpy(buf->r, chunk->str, chunk->len);
72
81
        buf->l += chunk->len;
 
82
        buf->send_max += chunk->len;
73
83
        buf->r += chunk->len;
74
84
        buf->total += chunk->len;
75
85
        if (buf->r == buf->data + BUFSIZE)
76
86
                buf->r = buf->data;
 
87
 
 
88
        buf->flags &= ~(BF_EMPTY|BF_FULL);
 
89
        if (buf->l == 0)
 
90
                buf->flags |= BF_EMPTY;
 
91
        if (buf->l >= buf->max_len)
 
92
                buf->flags |= BF_FULL;
 
93
 
77
94
        chunk->len = 0;
78
 
 
79
95
        return -1;
80
96
}
81
97
 
110
126
        if (b->lr > pos) b->lr += delta;
111
127
        b->l += delta;
112
128
 
 
129
        b->flags &= ~(BF_EMPTY|BF_FULL);
 
130
        if (b->l == 0)
 
131
                b->flags |= BF_EMPTY;
 
132
        if (b->l >= b->max_len)
 
133
                b->flags |= BF_FULL;
 
134
 
113
135
        return delta;
114
136
}
115
137
 
116
138
/*
117
139
 * same except that the string length is given, which allows str to be NULL if
118
 
 * len is 0.
 
140
 * len is 0. The send limit is *not* adjusted.
119
141
 */
120
142
int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int len)
121
143
{
145
167
        if (b->lr > pos) b->lr += delta;
146
168
        b->l += delta;
147
169
 
 
170
        b->flags &= ~(BF_EMPTY|BF_FULL);
 
171
        if (b->l == 0)
 
172
                b->flags |= BF_EMPTY;
 
173
        if (b->l >= b->max_len)
 
174
                b->flags |= BF_FULL;
 
175
 
148
176
        return delta;
149
177
}
150
178
 
154
182
 * argument informs about the length of string <str> so that we don't have to
155
183
 * measure it. It does not include the "\r\n". If <str> is NULL, then the buffer
156
184
 * is only opened for len+2 bytes but nothing is copied in. It may be useful in
157
 
 * some circumstances.
 
185
 * some circumstances. The send limit is *not* adjusted.
158
186
 *
159
187
 * The number of bytes added is returned on success. 0 is returned on failure.
160
188
 */
183
211
        if (b->lr > pos) b->lr += delta;
184
212
        b->l += delta;
185
213
 
 
214
        b->flags &= ~(BF_EMPTY|BF_FULL);
 
215
        if (b->l == 0)
 
216
                b->flags |= BF_EMPTY;
 
217
        if (b->l >= b->max_len)
 
218
                b->flags |= BF_FULL;
 
219
 
186
220
        return delta;
187
221
}
188
222