Lines Matching full:chain
139 (ptr)->internal_.chain = NULL; \
143 static void evbuffer_chain_align(struct evbuffer_chain *chain);
144 static int evbuffer_chain_should_realign(struct evbuffer_chain *chain,
154 static inline void evbuffer_chain_incref(struct evbuffer_chain *chain);
159 struct evbuffer_chain *chain; in evbuffer_chain_new() local
178 if ((chain = mm_malloc(to_alloc)) == NULL) in evbuffer_chain_new()
181 memset(chain, 0, EVBUFFER_CHAIN_SIZE); in evbuffer_chain_new()
183 chain->buffer_len = to_alloc - EVBUFFER_CHAIN_SIZE; in evbuffer_chain_new()
188 chain->buffer = EVBUFFER_CHAIN_EXTRA(unsigned char, chain); in evbuffer_chain_new()
190 chain->refcnt = 1; in evbuffer_chain_new()
192 return (chain); in evbuffer_chain_new()
196 evbuffer_chain_free(struct evbuffer_chain *chain) in evbuffer_chain_free() argument
198 EVUTIL_ASSERT(chain->refcnt > 0); in evbuffer_chain_free()
199 if (--chain->refcnt > 0) { in evbuffer_chain_free()
200 /* chain is still referenced by other chains */ in evbuffer_chain_free()
204 if (CHAIN_PINNED(chain)) { in evbuffer_chain_free()
206 chain->refcnt++; in evbuffer_chain_free()
207 chain->flags |= EVBUFFER_DANGLING; in evbuffer_chain_free()
211 /* safe to release chain, it's either a referencing in evbuffer_chain_free()
212 * chain or all references to it have been freed */ in evbuffer_chain_free()
213 if (chain->flags & EVBUFFER_REFERENCE) { in evbuffer_chain_free()
217 chain); in evbuffer_chain_free()
219 (*info->cleanupfn)(chain->buffer, in evbuffer_chain_free()
220 chain->buffer_len, in evbuffer_chain_free()
223 if (chain->flags & EVBUFFER_FILESEGMENT) { in evbuffer_chain_free()
227 chain); in evbuffer_chain_free()
231 UnmapViewOfFile(chain->buffer); in evbuffer_chain_free()
236 if (chain->flags & EVBUFFER_MULTICAST) { in evbuffer_chain_free()
240 chain); in evbuffer_chain_free()
241 /* referencing chain is being freed, decrease in evbuffer_chain_free()
242 * refcounts of source chain and associated in evbuffer_chain_free()
252 mm_free(chain); in evbuffer_chain_free()
256 evbuffer_free_all_chains(struct evbuffer_chain *chain) in evbuffer_free_all_chains() argument
259 for (; chain; chain = next) { in evbuffer_free_all_chains()
260 next = chain->next; in evbuffer_free_all_chains()
261 evbuffer_chain_free(chain); in evbuffer_free_all_chains()
267 evbuffer_chains_all_empty(struct evbuffer_chain *chain) in evbuffer_chains_all_empty() argument
269 for (; chain; chain = chain->next) { in evbuffer_chains_all_empty()
270 if (chain->off) in evbuffer_chains_all_empty()
278 static inline int evbuffer_chains_all_empty(struct evbuffer_chain *chain) { in evbuffer_chains_all_empty() argument
284 * to replacing them all with a new chain. Return a pointer to the place
285 * where the new chain will go.
294 /* Find the first victim chain. It might be *last_with_datap */ in evbuffer_free_trailing_empty_chains()
305 /* Add a single chain 'chain' to the end of 'buf', freeing trailing empty
310 struct evbuffer_chain *chain) in evbuffer_chain_insert() argument
317 buf->first = buf->last = chain; in evbuffer_chain_insert()
321 *chp = chain; in evbuffer_chain_insert()
322 if (chain->off) in evbuffer_chain_insert()
324 buf->last = chain; in evbuffer_chain_insert()
326 buf->total_len += chain->off; in evbuffer_chain_insert()
332 struct evbuffer_chain *chain; in evbuffer_chain_insert_new() local
333 if ((chain = evbuffer_chain_new(datlen)) == NULL) in evbuffer_chain_insert_new()
335 evbuffer_chain_insert(buf, chain); in evbuffer_chain_insert_new()
336 return chain; in evbuffer_chain_insert_new()
340 evbuffer_chain_pin_(struct evbuffer_chain *chain, unsigned flag) in evbuffer_chain_pin_() argument
342 EVUTIL_ASSERT((chain->flags & flag) == 0); in evbuffer_chain_pin_()
343 chain->flags |= flag; in evbuffer_chain_pin_()
347 evbuffer_chain_unpin_(struct evbuffer_chain *chain, unsigned flag) in evbuffer_chain_unpin_() argument
349 EVUTIL_ASSERT((chain->flags & flag) != 0); in evbuffer_chain_unpin_()
350 chain->flags &= ~flag; in evbuffer_chain_unpin_()
351 if (chain->flags & EVBUFFER_DANGLING) in evbuffer_chain_unpin_()
352 evbuffer_chain_free(chain); in evbuffer_chain_unpin_()
356 evbuffer_chain_incref(struct evbuffer_chain *chain) in evbuffer_chain_incref() argument
358 ++chain->refcnt; in evbuffer_chain_incref()
563 struct evbuffer_chain *chain, *next; in evbuffer_decref_and_unlock_() local
573 for (chain = buffer->first; chain != NULL; chain = next) { in evbuffer_decref_and_unlock_()
574 next = chain->next; in evbuffer_decref_and_unlock_()
575 evbuffer_chain_free(chain); in evbuffer_decref_and_unlock_()
623 struct evbuffer_chain *chain; in evbuffer_get_contiguous_space() local
627 chain = buf->first; in evbuffer_get_contiguous_space()
628 result = (chain != NULL ? chain->off : 0); in evbuffer_get_contiguous_space()
674 struct evbuffer_chain *chain, **chainp; in evbuffer_reserve_space() local
683 if ((chain = evbuffer_expand_singlechain(buf, size)) == NULL) in evbuffer_reserve_space()
686 vec[0].iov_base = (void *)CHAIN_SPACE_PTR(chain); in evbuffer_reserve_space()
687 vec[0].iov_len = (size_t)CHAIN_SPACE_LEN(chain); in evbuffer_reserve_space()
727 struct evbuffer_chain *chain, **firstchainp, **chainp; in evbuffer_commit_space() local
741 /* The user only got or used one chain; it might not in evbuffer_commit_space()
752 /* Advance 'firstchain' to the first chain with space in it. */ in evbuffer_commit_space()
760 chain = *firstchainp; in evbuffer_commit_space()
764 if (!chain) in evbuffer_commit_space()
766 if (vec[i].iov_base != (void *)CHAIN_SPACE_PTR(chain) || in evbuffer_commit_space()
767 (size_t)vec[i].iov_len > CHAIN_SPACE_LEN(chain)) in evbuffer_commit_space()
769 chain = chain->next; in evbuffer_commit_space()
810 * read-pinned chains. The first pinned chain is saved in first, and the
817 struct evbuffer_chain *chain, **pinned; in PRESERVE_PINNED() local
830 chain = *first = *pinned; in PRESERVE_PINNED()
833 /* If there's data in the first pinned chain, we need to allocate in PRESERVE_PINNED()
834 * a new chain and copy the data over. */ in PRESERVE_PINNED()
835 if (chain->off) { in PRESERVE_PINNED()
839 tmp = evbuffer_chain_new(chain->off); in PRESERVE_PINNED()
842 memcpy(tmp->buffer, chain->buffer + chain->misalign, in PRESERVE_PINNED()
843 chain->off); in PRESERVE_PINNED()
844 tmp->off = chain->off; in PRESERVE_PINNED()
847 chain->misalign += chain->off; in PRESERVE_PINNED()
848 chain->off = 0; in PRESERVE_PINNED()
911 struct evbuffer_chain *chain = src->first; in APPEND_CHAIN_MULTICAST() local
917 for (; chain; chain = chain->next) { in APPEND_CHAIN_MULTICAST()
918 if (!chain->off || chain->flags & EVBUFFER_DANGLING) { in APPEND_CHAIN_MULTICAST()
929 /* reference evbuffer containing source chain so it in APPEND_CHAIN_MULTICAST()
930 * doesn't get released while the chain is still in APPEND_CHAIN_MULTICAST()
934 /* reference source chain which now becomes immutable */ in APPEND_CHAIN_MULTICAST()
935 evbuffer_chain_incref(chain); in APPEND_CHAIN_MULTICAST()
936 extra->parent = chain; in APPEND_CHAIN_MULTICAST()
937 chain->flags |= EVBUFFER_IMMUTABLE; in APPEND_CHAIN_MULTICAST()
938 tmp->buffer_len = chain->buffer_len; in APPEND_CHAIN_MULTICAST()
939 tmp->misalign = chain->misalign; in APPEND_CHAIN_MULTICAST()
940 tmp->off = chain->off; in APPEND_CHAIN_MULTICAST()
942 tmp->buffer = chain->buffer; in APPEND_CHAIN_MULTICAST()
990 /* There might be an empty chain at the start of outbuf; free in evbuffer_add_buffer()
1015 struct evbuffer_chain *chain; in evbuffer_add_buffer_reference() local
1021 chain = inbuf->first; in evbuffer_add_buffer_reference()
1031 for (; chain; chain = chain->next) { in evbuffer_add_buffer_reference()
1032 if ((chain->flags & (EVBUFFER_FILESEGMENT|EVBUFFER_SENDFILE|EVBUFFER_MULTICAST)) != 0) { in evbuffer_add_buffer_reference()
1033 /* chain type can not be referenced */ in evbuffer_add_buffer_reference()
1040 /* There might be an empty chain at the start of outbuf; free in evbuffer_add_buffer_reference()
1080 /* There might be an empty chain at the start of outbuf; free in evbuffer_prepend_buffer()
1103 struct evbuffer_chain *chain, *next; in evbuffer_drain() local
1120 for (chain = buf->first; chain != NULL; chain = next) { in evbuffer_drain()
1121 next = chain->next; in evbuffer_drain()
1122 evbuffer_chain_free(chain); in evbuffer_drain()
1132 for (chain = buf->first; in evbuffer_drain()
1133 remaining >= chain->off; in evbuffer_drain()
1134 chain = next) { in evbuffer_drain()
1135 next = chain->next; in evbuffer_drain()
1136 remaining -= chain->off; in evbuffer_drain()
1138 if (chain == *buf->last_with_datap) { in evbuffer_drain()
1141 if (&chain->next == buf->last_with_datap) in evbuffer_drain()
1144 if (CHAIN_PINNED_R(chain)) { in evbuffer_drain()
1146 chain->misalign += chain->off; in evbuffer_drain()
1147 chain->off = 0; in evbuffer_drain()
1150 evbuffer_chain_free(chain); in evbuffer_drain()
1153 buf->first = chain; in evbuffer_drain()
1154 EVUTIL_ASSERT(remaining <= chain->off); in evbuffer_drain()
1155 chain->misalign += remaining; in evbuffer_drain()
1156 chain->off -= remaining; in evbuffer_drain()
1194 struct evbuffer_chain *chain; in evbuffer_copyout_from() local
1207 chain = pos->internal_.chain; in evbuffer_copyout_from()
1212 chain = buf->first; in evbuffer_copyout_from()
1229 while (datlen && datlen >= chain->off - pos_in_chain) { in evbuffer_copyout_from()
1230 size_t copylen = chain->off - pos_in_chain; in evbuffer_copyout_from()
1232 chain->buffer + chain->misalign + pos_in_chain, in evbuffer_copyout_from()
1237 chain = chain->next; in evbuffer_copyout_from()
1239 EVUTIL_ASSERT(chain || datlen==0); in evbuffer_copyout_from()
1243 EVUTIL_ASSERT(chain); in evbuffer_copyout_from()
1244 EVUTIL_ASSERT(datlen+pos_in_chain <= chain->off); in evbuffer_copyout_from()
1246 memcpy(data, chain->buffer + chain->misalign + pos_in_chain, in evbuffer_copyout_from()
1266 struct evbuffer_chain *chain, *previous; in evbuffer_remove_buffer() local
1272 chain = previous = src->first; in evbuffer_remove_buffer()
1293 while (chain->off <= datlen) { in evbuffer_remove_buffer()
1297 EVUTIL_ASSERT(chain != *src->last_with_datap); in evbuffer_remove_buffer()
1298 nread += chain->off; in evbuffer_remove_buffer()
1299 datlen -= chain->off; in evbuffer_remove_buffer()
1300 previous = chain; in evbuffer_remove_buffer()
1301 if (src->last_with_datap == &chain->next) in evbuffer_remove_buffer()
1303 chain = chain->next; in evbuffer_remove_buffer()
1306 if (chain != src->first) { in evbuffer_remove_buffer()
1307 /* we can remove the chain */ in evbuffer_remove_buffer()
1318 src->first = chain; in evbuffer_remove_buffer()
1326 * we want to read, so we manually drain the chain */ in evbuffer_remove_buffer()
1327 evbuffer_add(dst, chain->buffer + chain->misalign, datlen); in evbuffer_remove_buffer()
1328 chain->misalign += datlen; in evbuffer_remove_buffer()
1329 chain->off -= datlen; in evbuffer_remove_buffer()
1352 struct evbuffer_chain *chain, *next, *tmp, *last_with_data; in evbuffer_pullup() local
1360 chain = buf->first; in evbuffer_pullup()
1372 if (chain->off >= (size_t)size) { in evbuffer_pullup()
1373 result = chain->buffer + chain->misalign; in evbuffer_pullup()
1378 remaining = size - chain->off; in evbuffer_pullup()
1380 for (tmp=chain->next; tmp; tmp=tmp->next) { in evbuffer_pullup()
1388 if (CHAIN_PINNED(chain)) { in evbuffer_pullup()
1389 size_t old_off = chain->off; in evbuffer_pullup()
1390 if (CHAIN_SPACE_LEN(chain) < size - chain->off) { in evbuffer_pullup()
1394 buffer = CHAIN_SPACE_PTR(chain); in evbuffer_pullup()
1395 tmp = chain; in evbuffer_pullup()
1398 chain = chain->next; in evbuffer_pullup()
1399 } else if (chain->buffer_len - chain->misalign >= (size_t)size) { in evbuffer_pullup()
1400 /* already have enough space in the first chain */ in evbuffer_pullup()
1401 size_t old_off = chain->off; in evbuffer_pullup()
1402 buffer = chain->buffer + chain->misalign + chain->off; in evbuffer_pullup()
1403 tmp = chain; in evbuffer_pullup()
1406 chain = chain->next; in evbuffer_pullup()
1421 for (; chain != NULL && (size_t)size >= chain->off; chain = next) { in evbuffer_pullup()
1422 next = chain->next; in evbuffer_pullup()
1424 if (chain->buffer) { in evbuffer_pullup()
1425 memcpy(buffer, chain->buffer + chain->misalign, chain->off); in evbuffer_pullup()
1426 size -= chain->off; in evbuffer_pullup()
1427 buffer += chain->off; in evbuffer_pullup()
1429 if (chain == last_with_data) in evbuffer_pullup()
1431 if (&chain->next == buf->last_with_datap) in evbuffer_pullup()
1434 evbuffer_chain_free(chain); in evbuffer_pullup()
1437 if (chain != NULL) { in evbuffer_pullup()
1438 memcpy(buffer, chain->buffer + chain->misalign, size); in evbuffer_pullup()
1439 chain->misalign += size; in evbuffer_pullup()
1440 chain->off -= size; in evbuffer_pullup()
1445 tmp->next = chain; in evbuffer_pullup()
1476 struct evbuffer_chain *chain = it->internal_.chain; in evbuffer_strchr() local
1478 while (chain != NULL) { in evbuffer_strchr()
1479 char *buffer = (char *)chain->buffer + chain->misalign; in evbuffer_strchr()
1480 char *cp = memchr(buffer+i, chr, chain->off-i); in evbuffer_strchr()
1482 it->internal_.chain = chain; in evbuffer_strchr()
1487 it->pos += chain->off - i; in evbuffer_strchr()
1489 chain = chain->next; in evbuffer_strchr()
1525 struct evbuffer_chain *chain = it->internal_.chain; in evbuffer_find_eol_char() local
1527 while (chain != NULL) { in evbuffer_find_eol_char()
1528 char *buffer = (char *)chain->buffer + chain->misalign; in evbuffer_find_eol_char()
1529 char *cp = find_eol_char(buffer+i, chain->off-i); in evbuffer_find_eol_char()
1531 it->internal_.chain = chain; in evbuffer_find_eol_char()
1536 it->pos += chain->off - i; in evbuffer_find_eol_char()
1538 chain = chain->next; in evbuffer_find_eol_char()
1549 struct evbuffer_chain *chain = ptr->internal_.chain; in evbuffer_strspn() local
1552 if (!chain) in evbuffer_strspn()
1556 char *buffer = (char *)chain->buffer + chain->misalign; in evbuffer_strspn()
1557 for (; i < chain->off; ++i) { in evbuffer_strspn()
1563 ptr->internal_.chain = chain; in evbuffer_strspn()
1572 if (! chain->next) { in evbuffer_strspn()
1573 ptr->internal_.chain = chain; in evbuffer_strspn()
1579 chain = chain->next; in evbuffer_strspn()
1587 struct evbuffer_chain *chain = it->internal_.chain; in evbuffer_getchr() local
1590 if (chain == NULL) in evbuffer_getchr()
1593 return (unsigned char)chain->buffer[chain->misalign + off]; in evbuffer_getchr()
1606 if (start && start->internal_.chain == NULL) { in evbuffer_search_eol()
1619 it.internal_.chain = buffer->first; in evbuffer_search_eol()
1732 struct evbuffer_chain *chain, *tmp; in evbuffer_add() local
1748 chain = buf->last; in evbuffer_add()
1750 chain = *buf->last_with_datap; in evbuffer_add()
1755 if (chain == NULL) { in evbuffer_add()
1756 chain = evbuffer_chain_new(datlen); in evbuffer_add()
1757 if (!chain) in evbuffer_add()
1759 evbuffer_chain_insert(buf, chain); in evbuffer_add()
1762 if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) { in evbuffer_add()
1764 EVUTIL_ASSERT(chain->misalign >= 0 && in evbuffer_add()
1765 (ev_uint64_t)chain->misalign <= EVBUFFER_CHAIN_MAX); in evbuffer_add()
1766 remain = chain->buffer_len - (size_t)chain->misalign - chain->off; in evbuffer_add()
1769 * current last chain */ in evbuffer_add()
1770 memcpy(chain->buffer + chain->misalign + chain->off, in evbuffer_add()
1772 chain->off += datlen; in evbuffer_add()
1776 } else if (!CHAIN_PINNED(chain) && in evbuffer_add()
1777 evbuffer_chain_should_realign(chain, datlen)) { in evbuffer_add()
1779 evbuffer_chain_align(chain); in evbuffer_add()
1781 memcpy(chain->buffer + chain->off, data, datlen); in evbuffer_add()
1782 chain->off += datlen; in evbuffer_add()
1788 /* we cannot write any data to the last chain */ in evbuffer_add()
1792 /* we need to add another chain */ in evbuffer_add()
1793 to_alloc = chain->buffer_len; in evbuffer_add()
1803 memcpy(chain->buffer + chain->misalign + chain->off, in evbuffer_add()
1805 chain->off += remain; in evbuffer_add()
1829 struct evbuffer_chain *chain, *tmp; in evbuffer_prepend() local
1845 chain = buf->first; in evbuffer_prepend()
1847 if (chain == NULL) { in evbuffer_prepend()
1848 chain = evbuffer_chain_new(datlen); in evbuffer_prepend()
1849 if (!chain) in evbuffer_prepend()
1851 evbuffer_chain_insert(buf, chain); in evbuffer_prepend()
1855 if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) { in evbuffer_prepend()
1857 EVUTIL_ASSERT(chain->misalign >= 0 && in evbuffer_prepend()
1858 (ev_uint64_t)chain->misalign <= EVBUFFER_CHAIN_MAX); in evbuffer_prepend()
1860 /* If this chain is empty, we can treat it as in evbuffer_prepend()
1862 if (chain->off == 0) in evbuffer_prepend()
1863 chain->misalign = chain->buffer_len; in evbuffer_prepend()
1865 if ((size_t)chain->misalign >= datlen) { in evbuffer_prepend()
1867 memcpy(chain->buffer + chain->misalign - datlen, in evbuffer_prepend()
1869 chain->off += datlen; in evbuffer_prepend()
1870 chain->misalign -= datlen; in evbuffer_prepend()
1874 } else if (chain->misalign) { in evbuffer_prepend()
1876 memcpy(chain->buffer, in evbuffer_prepend()
1877 (char*)data + datlen - chain->misalign, in evbuffer_prepend()
1878 (size_t)chain->misalign); in evbuffer_prepend()
1879 chain->off += (size_t)chain->misalign; in evbuffer_prepend()
1880 buf->total_len += (size_t)chain->misalign; in evbuffer_prepend()
1881 buf->n_add_for_cb += (size_t)chain->misalign; in evbuffer_prepend()
1882 datlen -= (size_t)chain->misalign; in evbuffer_prepend()
1883 chain->misalign = 0; in evbuffer_prepend()
1887 /* we need to add another chain */ in evbuffer_prepend()
1891 if (buf->last_with_datap == &buf->first && chain->off) in evbuffer_prepend()
1894 tmp->next = chain; in evbuffer_prepend()
1912 /** Helper: realigns the memory in chain->buffer so that misalign is 0. */
1914 evbuffer_chain_align(struct evbuffer_chain *chain) in evbuffer_chain_align() argument
1916 EVUTIL_ASSERT(!(chain->flags & EVBUFFER_IMMUTABLE)); in evbuffer_chain_align()
1917 EVUTIL_ASSERT(!(chain->flags & EVBUFFER_MEM_PINNED_ANY)); in evbuffer_chain_align()
1918 memmove(chain->buffer, chain->buffer + chain->misalign, chain->off); in evbuffer_chain_align()
1919 chain->misalign = 0; in evbuffer_chain_align()
1925 /** Helper: return true iff we should realign chain to fit datalen bytes of
1928 evbuffer_chain_should_realign(struct evbuffer_chain *chain, in evbuffer_chain_should_realign() argument
1931 return chain->buffer_len - chain->off >= datlen && in evbuffer_chain_should_realign()
1932 (chain->off < chain->buffer_len / 2) && in evbuffer_chain_should_realign()
1933 (chain->off <= MAX_TO_REALIGN_IN_EXPAND); in evbuffer_chain_should_realign()
1941 struct evbuffer_chain *chain, **chainp; in evbuffer_expand_singlechain() local
1953 /* 'chain' now points to the first chain with writable space (if any) in evbuffer_expand_singlechain()
1955 chain = *chainp; in evbuffer_expand_singlechain()
1957 if (chain == NULL || in evbuffer_expand_singlechain()
1958 (chain->flags & (EVBUFFER_IMMUTABLE|EVBUFFER_MEM_PINNED_ANY))) { in evbuffer_expand_singlechain()
1959 /* We can't use the last_with_data chain at all. Just add a in evbuffer_expand_singlechain()
1965 if (CHAIN_SPACE_LEN(chain) >= datlen) { in evbuffer_expand_singlechain()
1966 result = chain; in evbuffer_expand_singlechain()
1970 /* If the chain is completely empty, just replace it by adding a new in evbuffer_expand_singlechain()
1971 * empty chain. */ in evbuffer_expand_singlechain()
1972 if (chain->off == 0) { in evbuffer_expand_singlechain()
1982 if (evbuffer_chain_should_realign(chain, datlen)) { in evbuffer_expand_singlechain()
1983 evbuffer_chain_align(chain); in evbuffer_expand_singlechain()
1984 result = chain; in evbuffer_expand_singlechain()
1990 * CHAIN_SPACE_LEN(chain) bytes in the former last chunk. If we in evbuffer_expand_singlechain()
1991 * resize, we have to copy chain->off bytes. in evbuffer_expand_singlechain()
1995 if (CHAIN_SPACE_LEN(chain) < chain->buffer_len / 8 || in evbuffer_expand_singlechain()
1996 chain->off > MAX_TO_COPY_IN_EXPAND || in evbuffer_expand_singlechain()
1997 datlen >= (EVBUFFER_CHAIN_MAX - chain->off)) { in evbuffer_expand_singlechain()
1998 /* It's not worth resizing this chain. Can the next one be in evbuffer_expand_singlechain()
2000 if (chain->next && CHAIN_SPACE_LEN(chain->next) >= datlen) { in evbuffer_expand_singlechain()
2001 /* Yes, we can just use the next chain (which should in evbuffer_expand_singlechain()
2003 result = chain->next; in evbuffer_expand_singlechain()
2006 /* No; append a new chain (which will free all in evbuffer_expand_singlechain()
2011 /* Okay, we're going to try to resize this chain: Not doing so in evbuffer_expand_singlechain()
2016 size_t length = chain->off + datlen; in evbuffer_expand_singlechain()
2022 tmp->off = chain->off; in evbuffer_expand_singlechain()
2023 memcpy(tmp->buffer, chain->buffer + chain->misalign, in evbuffer_expand_singlechain()
2024 chain->off); in evbuffer_expand_singlechain()
2026 EVUTIL_ASSERT(*chainp == chain); in evbuffer_expand_singlechain()
2029 if (buf->last == chain) in evbuffer_expand_singlechain()
2032 tmp->next = chain->next; in evbuffer_expand_singlechain()
2033 evbuffer_chain_free(chain); in evbuffer_expand_singlechain()
2053 struct evbuffer_chain *chain = buf->last, *tmp, *next; in evbuffer_expand_fast_() local
2060 if (chain == NULL || (chain->flags & EVBUFFER_IMMUTABLE)) { in evbuffer_expand_fast_()
2063 chain = evbuffer_chain_new(datlen); in evbuffer_expand_fast_()
2064 if (chain == NULL) in evbuffer_expand_fast_()
2067 evbuffer_chain_insert(buf, chain); in evbuffer_expand_fast_()
2076 for (chain = *buf->last_with_datap; chain; chain = chain->next) { in evbuffer_expand_fast_()
2077 if (chain->off) { in evbuffer_expand_fast_()
2078 size_t space = (size_t) CHAIN_SPACE_LEN(chain); in evbuffer_expand_fast_()
2079 EVUTIL_ASSERT(chain == *buf->last_with_datap); in evbuffer_expand_fast_()
2085 /* No data in chain; realign it. */ in evbuffer_expand_fast_()
2086 chain->misalign = 0; in evbuffer_expand_fast_()
2087 avail += chain->buffer_len; in evbuffer_expand_fast_()
2099 * them. Either add a new chain with enough space, or replace all in evbuffer_expand_fast_()
2104 EVUTIL_ASSERT(chain == NULL); in evbuffer_expand_fast_()
2113 * chain. But if the buffer had no chains, we would have in evbuffer_expand_fast_()
2114 * just allocated a new chain earlier) */ in evbuffer_expand_fast_()
2119 chain = *buf->last_with_datap; in evbuffer_expand_fast_()
2120 if (!chain->off) { in evbuffer_expand_fast_()
2121 EVUTIL_ASSERT(chain == buf->first); in evbuffer_expand_fast_()
2127 avail = (size_t) CHAIN_SPACE_LEN(chain); in evbuffer_expand_fast_()
2128 chain = chain->next; in evbuffer_expand_fast_()
2132 for (; chain; chain = next) { in evbuffer_expand_fast_()
2133 next = chain->next; in evbuffer_expand_fast_()
2134 EVUTIL_ASSERT(chain->off == 0); in evbuffer_expand_fast_()
2135 evbuffer_chain_free(chain); in evbuffer_expand_fast_()
2163 struct evbuffer_chain *chain; in evbuffer_expand() local
2166 chain = evbuffer_expand_singlechain(buf, datlen); in evbuffer_expand()
2168 return chain ? 0 : -1; in evbuffer_expand()
2218 @param chainp A pointer to a variable to hold the first chain we're
2229 struct evbuffer_chain *chain; in evbuffer_read_setup_vecs_() local
2239 /* Let firstchain be the first chain with any space on it */ in evbuffer_read_setup_vecs_()
2246 chain = *firstchainp; in evbuffer_read_setup_vecs_()
2247 EVUTIL_ASSERT(chain); in evbuffer_read_setup_vecs_()
2249 size_t avail = (size_t) CHAIN_SPACE_LEN(chain); in evbuffer_read_setup_vecs_()
2252 vecs[i].iov_base = (void *)CHAIN_SPACE_PTR(chain); in evbuffer_read_setup_vecs_()
2255 chain = chain->next; in evbuffer_read_setup_vecs_()
2293 struct evbuffer_chain *chain; in evbuffer_read() local
2355 if ((chain = evbuffer_expand_singlechain(buf, howmuch)) == NULL) { in evbuffer_read()
2361 p = chain->buffer + chain->misalign + chain->off; in evbuffer_read()
2400 chain->off += n; in evbuffer_read()
2420 struct evbuffer_chain *chain = buffer->first; in evbuffer_write_iovec() local
2430 while (chain != NULL && i < NUM_WRITE_IOVEC && howmuch) { in evbuffer_write_iovec()
2433 if (chain->flags & EVBUFFER_SENDFILE) in evbuffer_write_iovec()
2436 iov[i].IOV_PTR_FIELD = (void *) (chain->buffer + chain->misalign); in evbuffer_write_iovec()
2437 if ((size_t)howmuch >= chain->off) { in evbuffer_write_iovec()
2439 iov[i++].IOV_LEN_FIELD = (IOV_LEN_TYPE)chain->off; in evbuffer_write_iovec()
2440 howmuch -= chain->off; in evbuffer_write_iovec()
2446 chain = chain->next; in evbuffer_write_iovec()
2471 struct evbuffer_chain *chain = buffer->first; in evbuffer_write_sendfile() local
2474 chain); in evbuffer_write_sendfile()
2478 ev_off_t len = chain->off; in evbuffer_write_sendfile()
2481 off_t offset = chain->misalign; in evbuffer_write_sendfile()
2487 res = sendfile(source_fd, dest_fd, chain->misalign, &len, NULL, 0); in evbuffer_write_sendfile()
2493 res = sendfile(source_fd, dest_fd, chain->misalign, chain->off, NULL, &len, 0); in evbuffer_write_sendfile()
2500 res = sendfile(dest_fd, source_fd, &offset, chain->off); in evbuffer_write_sendfile()
2509 res = sendfile(dest_fd, source_fd, &offset, chain->off); in evbuffer_write_sendfile()
2540 struct evbuffer_chain *chain = buffer->first; in evbuffer_write_atmost() local
2541 if (chain != NULL && (chain->flags & EVBUFFER_SENDFILE)) in evbuffer_write_atmost()
2610 if (pos->internal_.chain && howfar <= pos->internal_.pos_in_chain) { in evbuffer_ptr_subtract()
2627 struct evbuffer_chain *chain = NULL; in evbuffer_ptr_set() local
2634 chain = buf->first; in evbuffer_ptr_set()
2645 chain = pos->internal_.chain; in evbuffer_ptr_set()
2652 while (chain && position + left >= chain->off) { in evbuffer_ptr_set()
2653 left -= chain->off - position; in evbuffer_ptr_set()
2654 chain = chain->next; in evbuffer_ptr_set()
2657 if (chain) { in evbuffer_ptr_set()
2658 pos->internal_.chain = chain; in evbuffer_ptr_set()
2661 /* The first byte in the (nonexistent) chain after the last chain */ in evbuffer_ptr_set()
2662 pos->internal_.chain = NULL; in evbuffer_ptr_set()
2682 struct evbuffer_chain *chain; in evbuffer_ptr_memcmp() local
2693 chain = pos->internal_.chain; in evbuffer_ptr_memcmp()
2695 while (len && chain) { in evbuffer_ptr_memcmp()
2697 if (len + position > chain->off) in evbuffer_ptr_memcmp()
2698 n_comparable = chain->off - position; in evbuffer_ptr_memcmp()
2701 r = memcmp(chain->buffer + chain->misalign + position, mem, in evbuffer_ptr_memcmp()
2708 chain = chain->next; in evbuffer_ptr_memcmp()
2724 struct evbuffer_chain *chain, *last_chain = NULL; in evbuffer_search_range() local
2732 chain = pos.internal_.chain; in evbuffer_search_range()
2735 chain = pos.internal_.chain = buffer->first; in evbuffer_search_range()
2740 last_chain = end->internal_.chain; in evbuffer_search_range()
2747 while (chain) { in evbuffer_search_range()
2749 chain->buffer + chain->misalign + in evbuffer_search_range()
2752 chain->off - pos.internal_.pos_in_chain); in evbuffer_search_range()
2764 if (pos.internal_.pos_in_chain == chain->off) { in evbuffer_search_range()
2765 chain = pos.internal_.chain = chain->next; in evbuffer_search_range()
2769 if (chain == last_chain) in evbuffer_search_range()
2771 pos.pos += chain->off - pos.internal_.pos_in_chain; in evbuffer_search_range()
2772 chain = pos.internal_.chain = chain->next; in evbuffer_search_range()
2789 struct evbuffer_chain *chain; in evbuffer_peek() local
2794 if (start_at && start_at->internal_.chain == NULL) in evbuffer_peek()
2800 chain = start_at->internal_.chain; in evbuffer_peek()
2801 len_so_far = chain->off in evbuffer_peek()
2805 vec[0].iov_base = (void *)(chain->buffer + chain->misalign in evbuffer_peek()
2809 chain = chain->next; in evbuffer_peek()
2811 chain = buffer->first; in evbuffer_peek()
2823 while (chain) { in evbuffer_peek()
2827 vec[idx].iov_base = (void *)(chain->buffer + chain->misalign); in evbuffer_peek()
2828 vec[idx].iov_len = chain->off; in evbuffer_peek()
2833 len_so_far += chain->off; in evbuffer_peek()
2834 chain = chain->next; in evbuffer_peek()
2850 struct evbuffer_chain *chain; in evbuffer_add_vprintf() local
2860 if ((chain = evbuffer_expand_singlechain(buf, 64)) == NULL) in evbuffer_add_vprintf()
2865 size_t used = chain->misalign + chain->off; in evbuffer_add_vprintf()
2866 buffer = (char *)chain->buffer + chain->misalign + chain->off; in evbuffer_add_vprintf()
2867 EVUTIL_ASSERT(chain->buffer_len >= used); in evbuffer_add_vprintf()
2868 space = chain->buffer_len - used; in evbuffer_add_vprintf()
2870 buffer = (char*) CHAIN_SPACE_PTR(chain); in evbuffer_add_vprintf()
2871 space = (size_t) CHAIN_SPACE_LEN(chain); in evbuffer_add_vprintf()
2888 chain->off += sz; in evbuffer_add_vprintf()
2897 if ((chain = evbuffer_expand_singlechain(buf, sz + 1)) == NULL) in evbuffer_add_vprintf()
2925 struct evbuffer_chain *chain; in evbuffer_add_reference() local
2929 chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_reference)); in evbuffer_add_reference()
2930 if (!chain) in evbuffer_add_reference()
2932 chain->flags |= EVBUFFER_REFERENCE | EVBUFFER_IMMUTABLE; in evbuffer_add_reference()
2933 chain->buffer = (unsigned char *)data; in evbuffer_add_reference()
2934 chain->buffer_len = datlen; in evbuffer_add_reference()
2935 chain->off = datlen; in evbuffer_add_reference()
2937 info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_reference, chain); in evbuffer_add_reference()
2945 mm_free(chain); in evbuffer_add_reference()
2948 evbuffer_chain_insert(outbuf, chain); in evbuffer_add_reference()
3197 struct evbuffer_chain *chain; in evbuffer_add_file_segment() local
3229 chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_file_segment)); in evbuffer_add_file_segment()
3230 if (!chain) in evbuffer_add_file_segment()
3232 extra = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_file_segment, chain); in evbuffer_add_file_segment()
3234 chain->flags |= EVBUFFER_IMMUTABLE|EVBUFFER_FILESEGMENT; in evbuffer_add_file_segment()
3236 chain->flags |= EVBUFFER_SENDFILE; in evbuffer_add_file_segment()
3237 chain->misalign = seg->file_offset + offset; in evbuffer_add_file_segment()
3238 chain->off = length; in evbuffer_add_file_segment()
3239 chain->buffer_len = chain->misalign + length; in evbuffer_add_file_segment()
3259 mm_free(chain); in evbuffer_add_file_segment()
3262 chain->buffer = (unsigned char*) data; in evbuffer_add_file_segment()
3263 chain->buffer_len = length+offset_remaining; in evbuffer_add_file_segment()
3264 chain->misalign = offset_remaining; in evbuffer_add_file_segment()
3265 chain->off = length; in evbuffer_add_file_segment()
3267 chain->buffer = (unsigned char*)(seg->contents + offset); in evbuffer_add_file_segment()
3268 chain->buffer_len = length; in evbuffer_add_file_segment()
3269 chain->off = length; in evbuffer_add_file_segment()
3272 chain->buffer = (unsigned char*)(seg->contents + offset); in evbuffer_add_file_segment()
3273 chain->buffer_len = length; in evbuffer_add_file_segment()
3274 chain->off = length; in evbuffer_add_file_segment()
3282 evbuffer_chain_insert(buf, chain); in evbuffer_add_file_segment()