58
67
return buf->l == BUFSIZE;
61
/* flushes any content from buffer <buf> */
70
/* Check buffer timeouts, and set the corresponding flags. The
71
* likely/unlikely have been optimized for fastest normal path.
72
* The read/write timeouts are not set if there was activity on the buffer.
73
* That way, we don't have to update the timeout on every I/O. Note that the
74
* analyser timeout is always checked.
76
static inline void buffer_check_timeouts(struct buffer *b)
78
if (likely(!(b->flags & (BF_SHUTR|BF_READ_TIMEOUT|BF_READ_ACTIVITY|BF_READ_NOEXP))) &&
79
unlikely(tick_is_expired(b->rex, now_ms)))
80
b->flags |= BF_READ_TIMEOUT;
82
if (likely(!(b->flags & (BF_SHUTW|BF_WRITE_TIMEOUT|BF_WRITE_ACTIVITY))) &&
83
unlikely(tick_is_expired(b->wex, now_ms)))
84
b->flags |= BF_WRITE_TIMEOUT;
86
if (likely(!(b->flags & BF_ANA_TIMEOUT)) &&
87
unlikely(tick_is_expired(b->analyse_exp, now_ms)))
88
b->flags |= BF_ANA_TIMEOUT;
91
/* Schedule <bytes> more bytes to be forwarded by the buffer without notifying
92
* the task. Any pending data in the buffer is scheduled to be sent as well,
93
* in the limit of the number of bytes to forward. This must be the only method
94
* to use to schedule bytes to be sent. Directly touching ->to_forward will
95
* cause lockups when send_max goes down to zero if nobody is ready to push the
98
static inline void buffer_forward(struct buffer *buf, unsigned int bytes)
100
unsigned int data_left;
102
buf->to_forward += bytes;
103
data_left = buf->l - buf->send_max;
104
if (data_left > buf->to_forward)
105
data_left = buf->to_forward;
107
buf->to_forward -= data_left;
108
buf->send_max += data_left;
111
/* Schedule all remaining buffer data to be sent. send_max is not touched if it
112
* already covers those data. That permits doing a flush even after a forward,
113
* although not recommended.
62
115
static inline void buffer_flush(struct buffer *buf)
117
if (buf->send_max < buf->l)
118
buf->send_max = buf->l;
121
/* Erase any content from buffer <buf> and adjusts flags accordingly. Note
122
* that any spliced data is not affected since we may not have any access to
125
static inline void buffer_erase(struct buffer *buf)
64
129
buf->r = buf->lr = buf->w = buf->data;
131
buf->flags |= BF_EMPTY | BF_FULL;
133
buf->flags &= ~BF_FULL;
68
/* marks the buffer as "shutdown pending" for reads and cancels the timeout */
136
/* marks the buffer as "shutdown" for reads and cancels the timeout */
69
137
static inline void buffer_shutr(struct buffer *buf)
71
tv_eternity(&buf->rex);
72
buf->flags |= BF_SHUTR_PENDING;
139
buf->rex = TICK_ETERNITY;
140
buf->flags |= BF_SHUTR;
75
/* marks the buffer as "shutdown pending" for writes and cancels the timeout */
143
/* marks the buffer as "shutdown" for writes and cancels the timeout */
76
144
static inline void buffer_shutw(struct buffer *buf)
78
tv_eternity(&buf->wex);
79
buf->flags |= BF_SHUTW_PENDING;
146
buf->wex = TICK_ETERNITY;
147
buf->flags |= BF_SHUTW;
150
/* marks the buffer as "shutdown" ASAP for reads */
151
static inline void buffer_shutr_now(struct buffer *buf)
153
buf->flags |= BF_SHUTR_NOW;
156
/* marks the buffer as "shutdown" ASAP for writes */
157
static inline void buffer_shutw_now(struct buffer *buf)
159
buf->flags |= BF_SHUTW_NOW;
162
/* marks the buffer as "shutdown" ASAP in both directions */
163
static inline void buffer_abort(struct buffer *buf)
165
buf->flags |= BF_SHUTR_NOW | BF_SHUTW_NOW;
168
/* Installs <func> as a hijacker on the buffer <b> for session <s>. The hijack
169
* flag is set, and the function called once. The function is responsible for
170
* clearing the hijack bit. It is possible that the function clears the flag
171
* during this first call.
173
static inline void buffer_install_hijacker(struct session *s,
175
void (*func)(struct session *, struct buffer *))
178
b->flags |= BF_HIJACK;
182
/* Releases the buffer from hijacking mode. Often used by the hijack function */
183
static inline void buffer_stop_hijack(struct buffer *buf)
185
buf->flags &= ~BF_HIJACK;
188
/* allows the consumer to send the buffer contents */
189
static inline void buffer_write_ena(struct buffer *buf)
191
buf->flags |= BF_WRITE_ENA;
194
/* prevents the consumer from sending the buffer contents */
195
static inline void buffer_write_dis(struct buffer *buf)
197
buf->flags &= ~BF_WRITE_ENA;
200
/* check if the buffer needs to be shut down for read, and perform the shutdown
201
* at the stream_interface level if needed. This must not be used with a buffer
202
* for which a connection is currently in queue or turn-around.
204
static inline void buffer_check_shutr(struct buffer *b)
206
if (b->flags & BF_SHUTR)
209
if (!(b->flags & (BF_SHUTR_NOW|BF_SHUTW)))
212
/* Last read, forced read-shutdown, or other end closed. We have to
213
* close our read side and inform the stream_interface.
215
b->prod->shutr(b->prod);
218
/* check if the buffer needs to be shut down for write, and perform the shutdown
219
* at the stream_interface level if needed. This must not be used with a buffer
220
* for which a connection is currently in queue or turn-around.
222
static inline void buffer_check_shutw(struct buffer *b)
224
if (b->flags & BF_SHUTW)
227
if ((b->flags & BF_SHUTW_NOW) ||
228
(b->flags & (BF_EMPTY|BF_HIJACK|BF_WRITE_ENA|BF_SHUTR)) ==
229
(BF_EMPTY|BF_WRITE_ENA|BF_SHUTR)) {
230
/* Application requested write-shutdown, or other end closed
231
* with empty buffer. We have to close our write side and
232
* inform the stream_interface.
234
b->cons->shutw(b->cons);
83
238
/* returns the maximum number of bytes writable at once in this buffer */
84
239
static inline int buffer_max(const struct buffer *buf)