size_t ret = 0;
size_t meta_sz = (flags & HTX_XFER_NO_METADATA) ? 0 : sizeof(*blk);
uint32_t max, last_dstblk_sz;
+ uint32_t nb_hdrs = 0;
int dst_full = 0;
/* Note: no test on the end of the message here. Blocks are added one by
last_dstblk_sz = v.len;
count -= meta_sz + v.len;
ret += meta_sz + v.len;
+ nb_hdrs = 0;
if (v.len != sz) {
dst_full = 1;
goto stop;
last_dstblk_sz = sz;
count -= meta_sz + sz;
ret += meta_sz + sz;
+
+ /* Count the start-line, header and trailer blocks
+ * copied at the end of <dst> by this call. Only these
+ * ones may be removed if the copy is interrupted.
+ */
+ if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR)
+ nb_hdrs++;
+ else
+ nb_hdrs = 0;
break;
}
if (dstblk)
type = htx_get_blk_type(dstblk);
- /* the last copied block is a start-line, a header or a trailer */
- if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR) {
+ /* the last copied block is a start-line, a header or a
+ * trailer. Blocks already present in <dst> before this call
+ * must not be considered.
+ */
+ if (nb_hdrs && (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR)) {
/* <src> cannot have partial headers or trailers part */
BUG_ON(blk == NULL);
- /* Remove partial headers/trailers from <dst> and rollback on <src> to not remove them later */
- while (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR) {
+ /* Remove partial headers/trailers copied by this call
+ * from <dst> and rollback on <src> to not remove them
+ * later
+ */
+ while (nb_hdrs && (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL || type == HTX_BLK_HDR || type == HTX_BLK_TLR)) {
ret -= meta_sz + htx_get_blksz(dstblk);
htx_remove_blk(dst, dstblk);
+ nb_hdrs--;
dstblk = htx_get_tail_blk(dst);
blk = htx_get_prev_blk(src, blk);
if (!dstblk)