Till now we'd consider a buffer full even if it had size==0 due to pointing
to buf.size. Now we change this : if buf_wanted is present, it means that we
have already tried to allocate a buffer but failed. Thus the buffer must be
considered full so that we stop trying to poll for reads on it. Otherwise if
it's empty, it's buf_empty and we report !full since we may allocate it on
the fly.
*/
static inline int buffer_full(const struct buffer *b, unsigned int reserve)
{
+ if (b == &buf_empty)
+ return 0;
+
return (b->i + reserve >= b->size);
}
/* Return 1 if the buffer has less than 1/4 of its capacity free, otherwise 0 */
static inline int buffer_almost_full(const struct buffer *buf)
{
- if (buffer_total_space(buf) < buf->size / 4)
+ if (buf == &buf_empty)
+ return 0;
+
+ if (!buf->size || buffer_total_space(buf) < buf->size / 4)
return 1;
return 0;
}
{
int rem = chn->buf->size;
+ if (chn->buf == &buf_empty)
+ return 0;
+
rem -= chn->buf->o;
rem -= chn->buf->i;
if (!rem)