Lines Matching refs:chain
139 static void evbuffer_chain_align(struct evbuffer_chain *chain);
140 static int evbuffer_chain_should_realign(struct evbuffer_chain *chain,
158 struct evbuffer_chain *chain; in evbuffer_chain_new() local
177 if ((chain = mm_malloc(to_alloc)) == NULL) in evbuffer_chain_new()
180 memset(chain, 0, EVBUFFER_CHAIN_SIZE); in evbuffer_chain_new()
182 chain->buffer_len = to_alloc - EVBUFFER_CHAIN_SIZE; in evbuffer_chain_new()
187 chain->buffer = EVBUFFER_CHAIN_EXTRA(u_char, chain); in evbuffer_chain_new()
189 return (chain); in evbuffer_chain_new()
193 evbuffer_chain_free(struct evbuffer_chain *chain) in evbuffer_chain_free() argument
195 if (CHAIN_PINNED(chain)) { in evbuffer_chain_free()
196 chain->flags |= EVBUFFER_DANGLING; in evbuffer_chain_free()
199 if (chain->flags & (EVBUFFER_MMAP|EVBUFFER_SENDFILE| in evbuffer_chain_free()
201 if (chain->flags & EVBUFFER_REFERENCE) { in evbuffer_chain_free()
205 chain); in evbuffer_chain_free()
207 (*info->cleanupfn)(chain->buffer, in evbuffer_chain_free()
208 chain->buffer_len, in evbuffer_chain_free()
212 if (chain->flags & EVBUFFER_MMAP) { in evbuffer_chain_free()
215 chain); in evbuffer_chain_free()
216 if (munmap(chain->buffer, chain->buffer_len) == -1) in evbuffer_chain_free()
224 if (chain->flags & EVBUFFER_SENDFILE) { in evbuffer_chain_free()
227 chain); in evbuffer_chain_free()
235 mm_free(chain); in evbuffer_chain_free()
239 evbuffer_free_all_chains(struct evbuffer_chain *chain) in evbuffer_free_all_chains() argument
242 for (; chain; chain = next) { in evbuffer_free_all_chains()
243 next = chain->next; in evbuffer_free_all_chains()
244 evbuffer_chain_free(chain); in evbuffer_free_all_chains()
250 evbuffer_chains_all_empty(struct evbuffer_chain *chain) in evbuffer_chains_all_empty() argument
252 for (; chain; chain = chain->next) { in evbuffer_chains_all_empty()
253 if (chain->off) in evbuffer_chains_all_empty()
261 static inline int evbuffer_chains_all_empty(struct evbuffer_chain *chain) { in evbuffer_chains_all_empty() argument
293 struct evbuffer_chain *chain) in evbuffer_chain_insert() argument
300 buf->first = buf->last = chain; in evbuffer_chain_insert()
308 buf->last->next = chain; in evbuffer_chain_insert()
309 if (chain->off) in evbuffer_chain_insert()
315 *ch = chain; in evbuffer_chain_insert()
317 buf->last = chain; in evbuffer_chain_insert()
319 buf->total_len += chain->off; in evbuffer_chain_insert()
325 struct evbuffer_chain *chain; in evbuffer_chain_insert_new() local
326 if ((chain = evbuffer_chain_new(datlen)) == NULL) in evbuffer_chain_insert_new()
328 evbuffer_chain_insert(buf, chain); in evbuffer_chain_insert_new()
329 return chain; in evbuffer_chain_insert_new()
333 _evbuffer_chain_pin(struct evbuffer_chain *chain, unsigned flag) in _evbuffer_chain_pin() argument
335 EVUTIL_ASSERT((chain->flags & flag) == 0); in _evbuffer_chain_pin()
336 chain->flags |= flag; in _evbuffer_chain_pin()
340 _evbuffer_chain_unpin(struct evbuffer_chain *chain, unsigned flag) in _evbuffer_chain_unpin() argument
342 EVUTIL_ASSERT((chain->flags & flag) != 0); in _evbuffer_chain_unpin()
343 chain->flags &= ~flag; in _evbuffer_chain_unpin()
344 if (chain->flags & EVBUFFER_DANGLING) in _evbuffer_chain_unpin()
345 evbuffer_chain_free(chain); in _evbuffer_chain_unpin()
550 struct evbuffer_chain *chain, *next; in _evbuffer_decref_and_unlock() local
560 for (chain = buffer->first; chain != NULL; chain = next) { in _evbuffer_decref_and_unlock()
561 next = chain->next; in _evbuffer_decref_and_unlock()
562 evbuffer_chain_free(chain); in _evbuffer_decref_and_unlock()
610 struct evbuffer_chain *chain; in evbuffer_get_contiguous_space() local
614 chain = buf->first; in evbuffer_get_contiguous_space()
615 result = (chain != NULL ? chain->off : 0); in evbuffer_get_contiguous_space()
625 struct evbuffer_chain *chain, **chainp; in evbuffer_reserve_space() local
634 if ((chain = evbuffer_expand_singlechain(buf, size)) == NULL) in evbuffer_reserve_space()
637 vec[0].iov_base = CHAIN_SPACE_PTR(chain); in evbuffer_reserve_space()
638 vec[0].iov_len = (size_t) CHAIN_SPACE_LEN(chain); in evbuffer_reserve_space()
674 struct evbuffer_chain *chain, **firstchainp, **chainp; in evbuffer_commit_space() local
707 chain = *firstchainp; in evbuffer_commit_space()
711 if (!chain) in evbuffer_commit_space()
713 if (vec[i].iov_base != (void*)CHAIN_SPACE_PTR(chain) || in evbuffer_commit_space()
714 (size_t)vec[i].iov_len > CHAIN_SPACE_LEN(chain)) in evbuffer_commit_space()
716 chain = chain->next; in evbuffer_commit_space()
764 struct evbuffer_chain *chain, **pinned; in PRESERVE_PINNED() local
777 chain = *first = *pinned; in PRESERVE_PINNED()
782 if (chain->off) { in PRESERVE_PINNED()
786 tmp = evbuffer_chain_new(chain->off); in PRESERVE_PINNED()
789 memcpy(tmp->buffer, chain->buffer + chain->misalign, in PRESERVE_PINNED()
790 chain->off); in PRESERVE_PINNED()
791 tmp->off = chain->off; in PRESERVE_PINNED()
794 chain->misalign += chain->off; in PRESERVE_PINNED()
795 chain->off = 0; in PRESERVE_PINNED()
962 struct evbuffer_chain *chain, *next; in evbuffer_drain() local
979 for (chain = buf->first; chain != NULL; chain = next) { in evbuffer_drain()
980 next = chain->next; in evbuffer_drain()
981 evbuffer_chain_free(chain); in evbuffer_drain()
991 for (chain = buf->first; in evbuffer_drain()
992 remaining >= chain->off; in evbuffer_drain()
993 chain = next) { in evbuffer_drain()
994 next = chain->next; in evbuffer_drain()
995 remaining -= chain->off; in evbuffer_drain()
997 if (chain == *buf->last_with_datap) { in evbuffer_drain()
1000 if (&chain->next == buf->last_with_datap) in evbuffer_drain()
1003 if (CHAIN_PINNED_R(chain)) { in evbuffer_drain()
1005 chain->misalign += chain->off; in evbuffer_drain()
1006 chain->off = 0; in evbuffer_drain()
1009 evbuffer_chain_free(chain); in evbuffer_drain()
1012 buf->first = chain; in evbuffer_drain()
1013 if (chain) { in evbuffer_drain()
1014 EVUTIL_ASSERT(remaining <= chain->off); in evbuffer_drain()
1015 chain->misalign += remaining; in evbuffer_drain()
1016 chain->off -= remaining; in evbuffer_drain()
1048 struct evbuffer_chain *chain; in evbuffer_copyout() local
1055 chain = buf->first; in evbuffer_copyout()
1070 while (datlen && datlen >= chain->off) { in evbuffer_copyout()
1071 memcpy(data, chain->buffer + chain->misalign, chain->off); in evbuffer_copyout()
1072 data += chain->off; in evbuffer_copyout()
1073 datlen -= chain->off; in evbuffer_copyout()
1075 chain = chain->next; in evbuffer_copyout()
1076 EVUTIL_ASSERT(chain || datlen==0); in evbuffer_copyout()
1080 EVUTIL_ASSERT(chain); in evbuffer_copyout()
1081 EVUTIL_ASSERT(datlen <= chain->off); in evbuffer_copyout()
1082 memcpy(data, chain->buffer + chain->misalign, datlen); in evbuffer_copyout()
1101 struct evbuffer_chain *chain, *previous; in evbuffer_remove_buffer() local
1107 chain = previous = src->first; in evbuffer_remove_buffer()
1128 while (chain->off <= datlen) { in evbuffer_remove_buffer()
1132 EVUTIL_ASSERT(chain != *src->last_with_datap); in evbuffer_remove_buffer()
1133 nread += chain->off; in evbuffer_remove_buffer()
1134 datlen -= chain->off; in evbuffer_remove_buffer()
1135 previous = chain; in evbuffer_remove_buffer()
1136 if (src->last_with_datap == &chain->next) in evbuffer_remove_buffer()
1138 chain = chain->next; in evbuffer_remove_buffer()
1153 src->first = chain; in evbuffer_remove_buffer()
1162 evbuffer_add(dst, chain->buffer + chain->misalign, datlen); in evbuffer_remove_buffer()
1163 chain->misalign += datlen; in evbuffer_remove_buffer()
1164 chain->off -= datlen; in evbuffer_remove_buffer()
1187 struct evbuffer_chain *chain, *next, *tmp, *last_with_data; in evbuffer_pullup() local
1195 chain = buf->first; in evbuffer_pullup()
1207 if (chain->off >= (size_t)size) { in evbuffer_pullup()
1208 result = chain->buffer + chain->misalign; in evbuffer_pullup()
1213 remaining = size - chain->off; in evbuffer_pullup()
1215 for (tmp=chain->next; tmp; tmp=tmp->next) { in evbuffer_pullup()
1223 if (CHAIN_PINNED(chain)) { in evbuffer_pullup()
1224 size_t old_off = chain->off; in evbuffer_pullup()
1225 if (CHAIN_SPACE_LEN(chain) < size - chain->off) { in evbuffer_pullup()
1229 buffer = CHAIN_SPACE_PTR(chain); in evbuffer_pullup()
1230 tmp = chain; in evbuffer_pullup()
1233 chain = chain->next; in evbuffer_pullup()
1234 } else if (chain->buffer_len - chain->misalign >= (size_t)size) { in evbuffer_pullup()
1236 size_t old_off = chain->off; in evbuffer_pullup()
1237 buffer = chain->buffer + chain->misalign + chain->off; in evbuffer_pullup()
1238 tmp = chain; in evbuffer_pullup()
1241 chain = chain->next; in evbuffer_pullup()
1256 for (; chain != NULL && (size_t)size >= chain->off; chain = next) { in evbuffer_pullup()
1257 next = chain->next; in evbuffer_pullup()
1259 memcpy(buffer, chain->buffer + chain->misalign, chain->off); in evbuffer_pullup()
1260 size -= chain->off; in evbuffer_pullup()
1261 buffer += chain->off; in evbuffer_pullup()
1262 if (chain == last_with_data) in evbuffer_pullup()
1264 if (&chain->next == buf->last_with_datap) in evbuffer_pullup()
1267 evbuffer_chain_free(chain); in evbuffer_pullup()
1270 if (chain != NULL) { in evbuffer_pullup()
1271 memcpy(buffer, chain->buffer + chain->misalign, size); in evbuffer_pullup()
1272 chain->misalign += size; in evbuffer_pullup()
1273 chain->off -= size; in evbuffer_pullup()
1278 tmp->next = chain; in evbuffer_pullup()
1309 struct evbuffer_chain *chain = it->_internal.chain; in evbuffer_strchr() local
1311 while (chain != NULL) { in evbuffer_strchr()
1312 char *buffer = (char *)chain->buffer + chain->misalign; in evbuffer_strchr()
1313 char *cp = memchr(buffer+i, chr, chain->off-i); in evbuffer_strchr()
1315 it->_internal.chain = chain; in evbuffer_strchr()
1320 it->pos += chain->off - i; in evbuffer_strchr()
1322 chain = chain->next; in evbuffer_strchr()
1358 struct evbuffer_chain *chain = it->_internal.chain; in evbuffer_find_eol_char() local
1360 while (chain != NULL) { in evbuffer_find_eol_char()
1361 char *buffer = (char *)chain->buffer + chain->misalign; in evbuffer_find_eol_char()
1362 char *cp = find_eol_char(buffer+i, chain->off-i); in evbuffer_find_eol_char()
1364 it->_internal.chain = chain; in evbuffer_find_eol_char()
1369 it->pos += chain->off - i; in evbuffer_find_eol_char()
1371 chain = chain->next; in evbuffer_find_eol_char()
1382 struct evbuffer_chain *chain = ptr->_internal.chain; in evbuffer_strspn() local
1385 if (!chain) in evbuffer_strspn()
1389 char *buffer = (char *)chain->buffer + chain->misalign; in evbuffer_strspn()
1390 for (; i < chain->off; ++i) { in evbuffer_strspn()
1396 ptr->_internal.chain = chain; in evbuffer_strspn()
1405 if (! chain->next) { in evbuffer_strspn()
1406 ptr->_internal.chain = chain; in evbuffer_strspn()
1412 chain = chain->next; in evbuffer_strspn()
1420 struct evbuffer_chain *chain = it->_internal.chain; in evbuffer_getchr() local
1423 return chain->buffer[chain->misalign + off]; in evbuffer_getchr()
1441 it._internal.chain = buffer->first; in evbuffer_search_eol()
1547 struct evbuffer_chain *chain, *tmp; in evbuffer_add() local
1562 chain = buf->last; in evbuffer_add()
1566 if (chain == NULL) { in evbuffer_add()
1567 chain = evbuffer_chain_new(datlen); in evbuffer_add()
1568 if (!chain) in evbuffer_add()
1570 evbuffer_chain_insert(buf, chain); in evbuffer_add()
1573 if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) { in evbuffer_add()
1575 EVUTIL_ASSERT(chain->misalign >= 0 && in evbuffer_add()
1576 (ev_uint64_t)chain->misalign <= EVBUFFER_CHAIN_MAX); in evbuffer_add()
1577 remain = chain->buffer_len - (size_t)chain->misalign - chain->off; in evbuffer_add()
1581 memcpy(chain->buffer + chain->misalign + chain->off, in evbuffer_add()
1583 chain->off += datlen; in evbuffer_add()
1587 } else if (!CHAIN_PINNED(chain) && in evbuffer_add()
1588 evbuffer_chain_should_realign(chain, datlen)) { in evbuffer_add()
1590 evbuffer_chain_align(chain); in evbuffer_add()
1592 memcpy(chain->buffer + chain->off, data, datlen); in evbuffer_add()
1593 chain->off += datlen; in evbuffer_add()
1604 to_alloc = chain->buffer_len; in evbuffer_add()
1614 memcpy(chain->buffer + chain->misalign + chain->off, in evbuffer_add()
1616 chain->off += remain; in evbuffer_add()
1640 struct evbuffer_chain *chain, *tmp; in evbuffer_prepend() local
1652 chain = buf->first; in evbuffer_prepend()
1654 if (chain == NULL) { in evbuffer_prepend()
1655 chain = evbuffer_chain_new(datlen); in evbuffer_prepend()
1656 if (!chain) in evbuffer_prepend()
1658 evbuffer_chain_insert(buf, chain); in evbuffer_prepend()
1662 if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) { in evbuffer_prepend()
1664 EVUTIL_ASSERT(chain->misalign >= 0 && in evbuffer_prepend()
1665 (ev_uint64_t)chain->misalign <= EVBUFFER_CHAIN_MAX); in evbuffer_prepend()
1669 if (chain->off == 0) in evbuffer_prepend()
1670 chain->misalign = chain->buffer_len; in evbuffer_prepend()
1672 if ((size_t)chain->misalign >= datlen) { in evbuffer_prepend()
1674 memcpy(chain->buffer + chain->misalign - datlen, in evbuffer_prepend()
1676 chain->off += datlen; in evbuffer_prepend()
1677 chain->misalign -= datlen; in evbuffer_prepend()
1681 } else if (chain->misalign) { in evbuffer_prepend()
1683 memcpy(chain->buffer, in evbuffer_prepend()
1684 (char*)data + datlen - chain->misalign, in evbuffer_prepend()
1685 (size_t)chain->misalign); in evbuffer_prepend()
1686 chain->off += (size_t)chain->misalign; in evbuffer_prepend()
1687 buf->total_len += (size_t)chain->misalign; in evbuffer_prepend()
1688 buf->n_add_for_cb += (size_t)chain->misalign; in evbuffer_prepend()
1689 datlen -= (size_t)chain->misalign; in evbuffer_prepend()
1690 chain->misalign = 0; in evbuffer_prepend()
1701 tmp->next = chain; in evbuffer_prepend()
1709 buf->n_add_for_cb += (size_t)chain->misalign; in evbuffer_prepend()
1721 evbuffer_chain_align(struct evbuffer_chain *chain) in evbuffer_chain_align() argument
1723 EVUTIL_ASSERT(!(chain->flags & EVBUFFER_IMMUTABLE)); in evbuffer_chain_align()
1724 EVUTIL_ASSERT(!(chain->flags & EVBUFFER_MEM_PINNED_ANY)); in evbuffer_chain_align()
1725 memmove(chain->buffer, chain->buffer + chain->misalign, chain->off); in evbuffer_chain_align()
1726 chain->misalign = 0; in evbuffer_chain_align()
1735 evbuffer_chain_should_realign(struct evbuffer_chain *chain, in evbuffer_chain_should_realign() argument
1738 return chain->buffer_len - chain->off >= datlen && in evbuffer_chain_should_realign()
1739 (chain->off < chain->buffer_len / 2) && in evbuffer_chain_should_realign()
1740 (chain->off <= MAX_TO_REALIGN_IN_EXPAND); in evbuffer_chain_should_realign()
1748 struct evbuffer_chain *chain, **chainp; in evbuffer_expand_singlechain() local
1762 chain = *chainp; in evbuffer_expand_singlechain()
1764 if (chain == NULL || in evbuffer_expand_singlechain()
1765 (chain->flags & (EVBUFFER_IMMUTABLE|EVBUFFER_MEM_PINNED_ANY))) { in evbuffer_expand_singlechain()
1772 if (CHAIN_SPACE_LEN(chain) >= datlen) { in evbuffer_expand_singlechain()
1773 result = chain; in evbuffer_expand_singlechain()
1779 if (chain->off == 0) { in evbuffer_expand_singlechain()
1789 if (evbuffer_chain_should_realign(chain, datlen)) { in evbuffer_expand_singlechain()
1790 evbuffer_chain_align(chain); in evbuffer_expand_singlechain()
1791 result = chain; in evbuffer_expand_singlechain()
1802 if (CHAIN_SPACE_LEN(chain) < chain->buffer_len / 8 || in evbuffer_expand_singlechain()
1803 chain->off > MAX_TO_COPY_IN_EXPAND || in evbuffer_expand_singlechain()
1805 EVBUFFER_CHAIN_MAX - datlen >= chain->off)) { in evbuffer_expand_singlechain()
1808 if (chain->next && CHAIN_SPACE_LEN(chain->next) >= datlen) { in evbuffer_expand_singlechain()
1811 result = chain->next; in evbuffer_expand_singlechain()
1824 size_t length = chain->off + datlen; in evbuffer_expand_singlechain()
1830 tmp->off = chain->off; in evbuffer_expand_singlechain()
1831 memcpy(tmp->buffer, chain->buffer + chain->misalign, in evbuffer_expand_singlechain()
1832 chain->off); in evbuffer_expand_singlechain()
1834 EVUTIL_ASSERT(*chainp == chain); in evbuffer_expand_singlechain()
1837 if (buf->last == chain) in evbuffer_expand_singlechain()
1840 tmp->next = chain->next; in evbuffer_expand_singlechain()
1841 evbuffer_chain_free(chain); in evbuffer_expand_singlechain()
1861 struct evbuffer_chain *chain = buf->last, *tmp, *next; in _evbuffer_expand_fast() local
1868 if (chain == NULL || (chain->flags & EVBUFFER_IMMUTABLE)) { in _evbuffer_expand_fast()
1871 chain = evbuffer_chain_new(datlen); in _evbuffer_expand_fast()
1872 if (chain == NULL) in _evbuffer_expand_fast()
1875 evbuffer_chain_insert(buf, chain); in _evbuffer_expand_fast()
1884 for (chain = *buf->last_with_datap; chain; chain = chain->next) { in _evbuffer_expand_fast()
1885 if (chain->off) { in _evbuffer_expand_fast()
1886 size_t space = (size_t) CHAIN_SPACE_LEN(chain); in _evbuffer_expand_fast()
1887 EVUTIL_ASSERT(chain == *buf->last_with_datap); in _evbuffer_expand_fast()
1894 chain->misalign = 0; in _evbuffer_expand_fast()
1895 avail += chain->buffer_len; in _evbuffer_expand_fast()
1912 EVUTIL_ASSERT(chain == NULL); in _evbuffer_expand_fast()
1927 chain = *buf->last_with_datap; in _evbuffer_expand_fast()
1928 if (!chain->off) { in _evbuffer_expand_fast()
1929 EVUTIL_ASSERT(chain == buf->first); in _evbuffer_expand_fast()
1935 avail = (size_t) CHAIN_SPACE_LEN(chain); in _evbuffer_expand_fast()
1936 chain = chain->next; in _evbuffer_expand_fast()
1940 for (; chain; chain = next) { in _evbuffer_expand_fast()
1941 next = chain->next; in _evbuffer_expand_fast()
1942 EVUTIL_ASSERT(chain->off == 0); in _evbuffer_expand_fast()
1943 evbuffer_chain_free(chain); in _evbuffer_expand_fast()
1971 struct evbuffer_chain *chain; in evbuffer_expand() local
1974 chain = evbuffer_expand_singlechain(buf, datlen); in evbuffer_expand()
1976 return chain ? 0 : -1; in evbuffer_expand()
2037 struct evbuffer_chain *chain; in _evbuffer_read_setup_vecs() local
2053 chain = *firstchainp; in _evbuffer_read_setup_vecs()
2055 size_t avail = (size_t) CHAIN_SPACE_LEN(chain); in _evbuffer_read_setup_vecs()
2058 vecs[i].iov_base = CHAIN_SPACE_PTR(chain); in _evbuffer_read_setup_vecs()
2061 chain = chain->next; in _evbuffer_read_setup_vecs()
2099 struct evbuffer_chain *chain; in evbuffer_read() local
2161 if ((chain = evbuffer_expand_singlechain(buf, howmuch)) == NULL) { in evbuffer_read()
2167 p = chain->buffer + chain->misalign + chain->off; in evbuffer_read()
2206 chain->off += n; in evbuffer_read()
2276 struct evbuffer_chain *chain = buffer->first; in evbuffer_write_iovec() local
2286 while (chain != NULL && i < NUM_WRITE_IOVEC && howmuch) { in evbuffer_write_iovec()
2289 if (chain->flags & EVBUFFER_SENDFILE) in evbuffer_write_iovec()
2292 iov[i].IOV_PTR_FIELD = (void *) (chain->buffer + chain->misalign); in evbuffer_write_iovec()
2293 if ((size_t)howmuch >= chain->off) { in evbuffer_write_iovec()
2295 iov[i++].IOV_LEN_FIELD = (IOV_LEN_TYPE)chain->off; in evbuffer_write_iovec()
2296 howmuch -= chain->off; in evbuffer_write_iovec()
2302 chain = chain->next; in evbuffer_write_iovec()
2326 struct evbuffer_chain *chain = buffer->first; in evbuffer_write_sendfile() local
2328 EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_fd, chain); in evbuffer_write_sendfile()
2331 off_t len = chain->off; in evbuffer_write_sendfile()
2334 off_t offset = chain->misalign; in evbuffer_write_sendfile()
2340 res = sendfile(info->fd, fd, chain->misalign, &len, NULL, 0); in evbuffer_write_sendfile()
2346 res = sendfile(info->fd, fd, chain->misalign, chain->off, NULL, &len, 0); in evbuffer_write_sendfile()
2353 res = sendfile(fd, info->fd, &offset, chain->off); in evbuffer_write_sendfile()
2362 res = sendfile(fd, info->fd, &offset, chain->off); in evbuffer_write_sendfile()
2393 struct evbuffer_chain *chain = buffer->first; in evbuffer_write_atmost() local
2394 if (chain != NULL && (chain->flags & EVBUFFER_SENDFILE)) in evbuffer_write_atmost()
2455 struct evbuffer_chain *chain = NULL; in evbuffer_ptr_set() local
2461 chain = buf->first; in evbuffer_ptr_set()
2472 chain = pos->_internal.chain; in evbuffer_ptr_set()
2479 while (chain && position + left >= chain->off) { in evbuffer_ptr_set()
2480 left -= chain->off - position; in evbuffer_ptr_set()
2481 chain = chain->next; in evbuffer_ptr_set()
2484 if (chain) { in evbuffer_ptr_set()
2485 pos->_internal.chain = chain; in evbuffer_ptr_set()
2488 pos->_internal.chain = NULL; in evbuffer_ptr_set()
2494 return chain != NULL ? 0 : -1; in evbuffer_ptr_set()
2505 struct evbuffer_chain *chain; in evbuffer_ptr_memcmp() local
2516 chain = pos->_internal.chain; in evbuffer_ptr_memcmp()
2518 while (len && chain) { in evbuffer_ptr_memcmp()
2520 if (len + position > chain->off) in evbuffer_ptr_memcmp()
2521 n_comparable = chain->off - position; in evbuffer_ptr_memcmp()
2524 r = memcmp(chain->buffer + chain->misalign + position, mem, in evbuffer_ptr_memcmp()
2531 chain = chain->next; in evbuffer_ptr_memcmp()
2547 struct evbuffer_chain *chain, *last_chain = NULL; in evbuffer_search_range() local
2555 chain = pos._internal.chain; in evbuffer_search_range()
2558 chain = pos._internal.chain = buffer->first; in evbuffer_search_range()
2563 last_chain = end->_internal.chain; in evbuffer_search_range()
2570 while (chain) { in evbuffer_search_range()
2572 chain->buffer + chain->misalign + in evbuffer_search_range()
2575 chain->off - pos._internal.pos_in_chain); in evbuffer_search_range()
2587 if (pos._internal.pos_in_chain == chain->off) { in evbuffer_search_range()
2588 chain = pos._internal.chain = chain->next; in evbuffer_search_range()
2592 if (chain == last_chain) in evbuffer_search_range()
2594 pos.pos += chain->off - pos._internal.pos_in_chain; in evbuffer_search_range()
2595 chain = pos._internal.chain = chain->next; in evbuffer_search_range()
2602 pos._internal.chain = NULL; in evbuffer_search_range()
2613 struct evbuffer_chain *chain; in evbuffer_peek() local
2620 chain = start_at->_internal.chain; in evbuffer_peek()
2621 len_so_far = chain->off in evbuffer_peek()
2625 vec[0].iov_base = chain->buffer + chain->misalign in evbuffer_peek()
2629 chain = chain->next; in evbuffer_peek()
2631 chain = buffer->first; in evbuffer_peek()
2643 while (chain) { in evbuffer_peek()
2647 vec[idx].iov_base = chain->buffer + chain->misalign; in evbuffer_peek()
2648 vec[idx].iov_len = chain->off; in evbuffer_peek()
2653 len_so_far += chain->off; in evbuffer_peek()
2654 chain = chain->next; in evbuffer_peek()
2670 struct evbuffer_chain *chain; in evbuffer_add_vprintf() local
2680 if ((chain = evbuffer_expand_singlechain(buf, 64)) == NULL) in evbuffer_add_vprintf()
2685 size_t used = chain->misalign + chain->off; in evbuffer_add_vprintf()
2686 buffer = (char *)chain->buffer + chain->misalign + chain->off; in evbuffer_add_vprintf()
2687 EVUTIL_ASSERT(chain->buffer_len >= used); in evbuffer_add_vprintf()
2688 space = chain->buffer_len - used; in evbuffer_add_vprintf()
2690 buffer = (char*) CHAIN_SPACE_PTR(chain); in evbuffer_add_vprintf()
2691 space = (size_t) CHAIN_SPACE_LEN(chain); in evbuffer_add_vprintf()
2708 chain->off += sz; in evbuffer_add_vprintf()
2717 if ((chain = evbuffer_expand_singlechain(buf, sz + 1)) == NULL) in evbuffer_add_vprintf()
2745 struct evbuffer_chain *chain; in evbuffer_add_reference() local
2749 chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_reference)); in evbuffer_add_reference()
2750 if (!chain) in evbuffer_add_reference()
2752 chain->flags |= EVBUFFER_REFERENCE | EVBUFFER_IMMUTABLE; in evbuffer_add_reference()
2753 chain->buffer = (u_char *)data; in evbuffer_add_reference()
2754 chain->buffer_len = datlen; in evbuffer_add_reference()
2755 chain->off = datlen; in evbuffer_add_reference()
2757 info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_reference, chain); in evbuffer_add_reference()
2765 mm_free(chain); in evbuffer_add_reference()
2768 evbuffer_chain_insert(outbuf, chain); in evbuffer_add_reference()
2792 struct evbuffer_chain *chain; in evbuffer_add_file() local
2813 chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_fd)); in evbuffer_add_file()
2814 if (chain == NULL) { in evbuffer_add_file()
2819 chain->flags |= EVBUFFER_SENDFILE | EVBUFFER_IMMUTABLE; in evbuffer_add_file()
2820 chain->buffer = NULL; /* no reading possible */ in evbuffer_add_file()
2821 chain->buffer_len = length + offset; in evbuffer_add_file()
2822 chain->off = length; in evbuffer_add_file()
2823 chain->misalign = offset; in evbuffer_add_file()
2825 info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_fd, chain); in evbuffer_add_file()
2830 mm_free(chain); in evbuffer_add_file()
2834 evbuffer_chain_insert(outbuf, chain); in evbuffer_add_file()
2860 chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_fd)); in evbuffer_add_file()
2861 if (chain == NULL) { in evbuffer_add_file()
2867 chain->flags |= EVBUFFER_MMAP | EVBUFFER_IMMUTABLE; in evbuffer_add_file()
2868 chain->buffer = mapped; in evbuffer_add_file()
2869 chain->buffer_len = length + offset; in evbuffer_add_file()
2870 chain->off = length + offset; in evbuffer_add_file()
2872 info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_fd, chain); in evbuffer_add_file()
2878 evbuffer_chain_free(chain); in evbuffer_add_file()
2883 evbuffer_chain_insert(outbuf, chain); in evbuffer_add_file()