Пример #1
0
END_TEST

/*******************************************************************************
 * chunk_length
 */

START_TEST(test_chunk_length)
{
	chunk_t a, b, c;
	size_t len;

	a = chunk_empty;
	b = chunk_empty;
	c = chunk_empty;
	len = chunk_length("ccc", a, b, c);
	ck_assert_int_eq(len, 0);

	a = chunk_from_str("foo");
	b = chunk_from_str("bar");
	len = chunk_length("ccc", a, b, c);
	ck_assert_int_eq(len, 6);

	len = chunk_length("zcc", a, b, c);
	ck_assert_int_eq(len, 0);

	len = chunk_length("czc", a, b, c);
	ck_assert_int_eq(len, 3);

	a = chunk_from_str("foo");
	b = chunk_from_str("bar");
	c = chunk_from_str("baz");
	len = chunk_length("ccc", a, b, c);
	ck_assert_int_eq(len, 9);
}
Пример #2
0
/**
 * skip bytes in the chunkqueue
 *
 * @param cq chunkqueue
 * @param skip bytes to skip
 * @return bytes skipped
 */
off_t chunkqueue_skip(chunkqueue *cq, off_t skip) {
    off_t total = 0;
    off_t we_have = 0, we_want = 0;
    chunk *c;

    if (!cq) return 0;

    /* consume chunks */
    for (c = cq->first; c && skip > 0; c = c->next) {
        we_have = chunk_length(c);

        /* skip empty chunks */
        if (!we_have) continue;

        we_want = we_have < skip ? we_have : skip;

        c->offset += we_want;
        total += we_want;
        skip -= we_want;
    }

    return total;
}