This will be important so that we can parse a buffer without touching it.
Now we indicate where from the buffer's head we plan to start to copy, and
for how many bytes. This will be used by send functions to loop at the end
of the buffer without having to update the buffer's output byte count.
return len;
}
+/* b_getblk_nc() : gets one or two blocks of data at once from a buffer,
+ * starting from offset <ofs> after the beginning of its output, and limited to
+ * no more than <max> bytes. The caller is responsible for ensuring that
+ * neither <ofs> nor <ofs>+<max> exceed the total number of bytes available in
+ * the buffer. Return values :
+ * >0 : number of blocks filled (1 or 2). blk1 is always filled before blk2.
+ * =0 : not enough data available. <blk*> are left undefined.
+ * The buffer is left unaffected. Unused buffers are left in an undefined state.
+ */
+static inline size_t b_getblk_nc(struct buffer *buf, char **blk1, int *len1, char **blk2, int *len2, size_t ofs, size_t max)
+{
+ size_t l1;
+
+ if (!max)
+ return 0;
+
+ *blk1 = b_peek(buf, ofs);
+ l1 = b_wrap(buf) - *blk1;
+ if (l1 < max) {
+ *len1 = l1;
+ *len2 = max - l1;
+ *blk2 = buf->data;
+ return 2;
+ }
+ *len1 = max;
+ return 1;
+}
+
/*********************************************/
/* Functions used to modify the buffer state */
return bo_putblk(b, chk->str, chk->len);
}
-/* Gets one or two blocks of data at once from a buffer's output.
- * Return values :
- * >0 : number of blocks filled (1 or 2). blk1 is always filled before blk2.
- * =0 : not enough data available. <blk*> are left undefined.
- * The buffer is left unaffected. Unused buffers are left in an undefined state.
- */
-static inline int bo_getblk_nc(struct buffer *buf, char **blk1, int *len1, char **blk2, int *len2)
-{
- if (unlikely(buf->o == 0))
- return 0;
-
- if (unlikely(buf->p != buf->data && buf->p - buf->o < buf->data)) {
- *blk1 = buf->p - buf->o + buf->size;
- *len1 = buf->data + buf->size - *blk1;
- *blk2 = buf->data;
- *len2 = buf->p - buf->data;
- return 2;
- }
-
- *blk1 = b_head(buf);
- *len1 = buf->o;
- return 1;
-}
-
/* Tries to write char <c> into input data at buffer <b>. Supports wrapping.
* Data are truncated if buffer is full.
*/
return 0;
}
- return bo_getblk_nc(chn->buf, blk1, len1, blk2, len2);
+ return b_getblk_nc(chn->buf, blk1, len1, blk2, len2, 0, chn->buf->o);
}
/* Gets one text line out of a channel's output buffer from a stream interface.
/* copy whatever we can */
blk1 = blk2 = NULL; // silence a maybe-uninitialized warning
- ret = bo_getblk_nc(buf, &blk1, &len1, &blk2, &len2);
+ ret = b_getblk_nc(buf, &blk1, &len1, &blk2, &len2, 0, buf->o);
if (ret == 1)
len2 = 0;