Lines Matching refs:c
111 chunk * const restrict c = ck_calloc(1, sizeof(*c)); in chunk_init() local
114 c->type = MEM_CHUNK; in chunk_init()
115 c->next = NULL; in chunk_init()
116 c->offset = 0; in chunk_init()
117 c->file.length = 0; in chunk_init()
118 c->file.is_temp = 0; in chunk_init()
119 c->file.view = NULL; in chunk_init()
121 c->file.fd = -1; in chunk_init()
123 c->mem = buffer_init(); in chunk_init()
124 return c; in chunk_init()
130 chunk * const restrict c = chunk_init(); in chunk_init_sz() local
131 buffer_string_prepare_copy(c->mem, sz-1); in chunk_init_sz()
132 return c; in chunk_init_sz()
193 static void chunk_reset_file_chunk(chunk *c) { in chunk_reset_file_chunk() argument
194 if (c->file.is_temp) { in chunk_reset_file_chunk()
195 c->file.is_temp = 0; in chunk_reset_file_chunk()
196 if (!buffer_is_blank(c->mem)) in chunk_reset_file_chunk()
197 unlink(c->mem->ptr); in chunk_reset_file_chunk()
199 if (c->file.refchg) { in chunk_reset_file_chunk()
200 c->file.refchg(c->file.ref, -1); in chunk_reset_file_chunk()
201 c->file.refchg = 0; /* NULL fn ptr */ in chunk_reset_file_chunk()
202 c->file.ref = NULL; in chunk_reset_file_chunk()
204 else if (c->file.fd != -1) { in chunk_reset_file_chunk()
205 close(c->file.fd); in chunk_reset_file_chunk()
208 if (c->file.view) in chunk_reset_file_chunk()
209 c->file.view = chunk_file_view_release(c->file.view); in chunk_reset_file_chunk()
211 c->file.fd = -1; in chunk_reset_file_chunk()
212 c->file.length = 0; in chunk_reset_file_chunk()
213 c->type = MEM_CHUNK; in chunk_reset_file_chunk()
216 static void chunk_reset(chunk *c) { in chunk_reset() argument
217 if (c->type == FILE_CHUNK) chunk_reset_file_chunk(c); in chunk_reset()
219 buffer_clear(c->mem); in chunk_reset()
220 c->offset = 0; in chunk_reset()
223 static void chunk_free(chunk *c) { in chunk_free() argument
224 if (c->type == FILE_CHUNK) chunk_reset_file_chunk(c); in chunk_free()
225 buffer_free(c->mem); in chunk_free()
226 free(c); in chunk_free()
233 chunk *c = chunks_oversized; in chunk_pop_oversized() local
234 chunks_oversized = c->next; in chunk_pop_oversized()
235 return c; in chunk_pop_oversized()
240 static void chunk_push_oversized(chunk * const c, const size_t sz) { in chunk_push_oversized() argument
246 c->next = *co; in chunk_push_oversized()
247 *co = c; in chunk_push_oversized()
253 chunks_oversized->mem = c->mem; in chunk_push_oversized()
254 c->mem = tb; in chunk_push_oversized()
256 chunk_free(c); in chunk_push_oversized()
263 chunk *c; in chunk_buffer_acquire_sz() local
267 c = chunks; in chunk_buffer_acquire_sz()
268 chunks = c->next; in chunk_buffer_acquire_sz()
271 c = chunk_init_sz(chunk_buf_sz); in chunk_buffer_acquire_sz()
274 c = chunk_pop_oversized(sz); in chunk_buffer_acquire_sz()
275 if (NULL == c) { in chunk_buffer_acquire_sz()
281 c = chunk_init_sz(((sz&~1uL)+(chunk_buf_sz-1)) & ~(chunk_buf_sz-1)); in chunk_buffer_acquire_sz()
284 c->next = chunk_buffers; in chunk_buffer_acquire_sz()
285 chunk_buffers = c; in chunk_buffer_acquire_sz()
286 b = c->mem; in chunk_buffer_acquire_sz()
287 c->mem = NULL; in chunk_buffer_acquire_sz()
298 chunk *c = chunk_buffers; in chunk_buffer_release() local
299 chunk_buffers = c->next; in chunk_buffer_release()
300 c->mem = b; in chunk_buffer_release()
303 c->next = chunks; in chunk_buffer_release()
304 chunks = c; in chunk_buffer_release()
307 chunk_push_oversized(c, b->size); in chunk_buffer_release()
309 chunk_free(c); in chunk_buffer_release()
347 chunk *c = chunks; in chunk_acquire() local
348 chunks = c->next; in chunk_acquire()
349 return c; in chunk_acquire()
356 chunk *c = chunk_pop_oversized(sz); in chunk_acquire() local
357 if (c) return c; in chunk_acquire()
363 static void chunk_release(chunk *c) { in chunk_release() argument
364 const size_t sz = c->mem->size; in chunk_release()
366 chunk_reset(c); in chunk_release()
367 c->next = chunks; in chunk_release()
368 chunks = c; in chunk_release()
371 chunk_reset(c); in chunk_release()
372 chunk_push_oversized(c, sz); in chunk_release()
374 else if (c->type == FILE_CHUNK) { in chunk_release()
375 chunk_reset(c); in chunk_release()
376 c->next = chunks_filechunk; in chunk_release()
377 chunks_filechunk = c; in chunk_release()
380 chunk_free(c); in chunk_release()
387 chunk *c = chunks_filechunk; in chunk_acquire_filechunk() local
388 chunks_filechunk = c->next; in chunk_acquire_filechunk()
389 return c; in chunk_acquire_filechunk()
396 for (chunk *next, *c = chunks; c; c = next) { in chunkqueue_chunk_pool_clear() local
397 next = c->next; in chunkqueue_chunk_pool_clear()
398 chunk_free(c); in chunkqueue_chunk_pool_clear()
401 for (chunk *next, *c = chunks_oversized; c; c = next) { in chunkqueue_chunk_pool_clear() local
402 next = c->next; in chunkqueue_chunk_pool_clear()
403 chunk_free(c); in chunkqueue_chunk_pool_clear()
407 for (chunk *next, *c = chunks_filechunk; c; c = next) { in chunkqueue_chunk_pool_clear() local
408 next = c->next; in chunkqueue_chunk_pool_clear()
409 chunk_free(c); in chunkqueue_chunk_pool_clear()
417 for (chunk *next, *c = chunk_buffers; c; c = next) { in chunkqueue_chunk_pool_free() local
418 next = c->next; in chunkqueue_chunk_pool_free()
420 free(c); in chunkqueue_chunk_pool_free()
422 c->mem = buffer_init(); /*(chunk_reset() expects c->mem != NULL)*/ in chunkqueue_chunk_pool_free()
423 chunk_free(c); in chunkqueue_chunk_pool_free()
430 static off_t chunk_remaining_length(const chunk *c) { in chunk_remaining_length() argument
432 return (c->type == MEM_CHUNK in chunk_remaining_length()
433 ? (off_t)buffer_clen(c->mem) in chunk_remaining_length()
434 : c->file.length) in chunk_remaining_length()
435 - c->offset; in chunk_remaining_length()
440 for (chunk *c; (c = cq->first); ) { in chunkqueue_release_chunks() local
441 cq->first = c->next; in chunkqueue_release_chunks()
442 chunk_release(c); in chunkqueue_release_chunks()
452 static void chunkqueue_prepend_chunk(chunkqueue * const restrict cq, chunk * const restrict c) { in chunkqueue_prepend_chunk() argument
453 if (NULL == (c->next = cq->first)) cq->last = c; in chunkqueue_prepend_chunk()
454 cq->first = c; in chunkqueue_prepend_chunk()
457 static void chunkqueue_append_chunk(chunkqueue * const restrict cq, chunk * const restrict c) { in chunkqueue_append_chunk() argument
458 c->next = NULL; in chunkqueue_append_chunk()
459 *(cq->last ? &cq->last->next : &cq->first) = c; in chunkqueue_append_chunk()
460 cq->last = c; in chunkqueue_append_chunk()
465 chunk *c = chunk_acquire(sz); in chunkqueue_prepend_mem_chunk() local
466 chunkqueue_prepend_chunk(cq, c); in chunkqueue_prepend_mem_chunk()
467 return c; in chunkqueue_prepend_mem_chunk()
472 chunk *c = chunk_acquire(sz); in chunkqueue_append_mem_chunk() local
473 chunkqueue_append_chunk(cq, c); in chunkqueue_append_mem_chunk()
474 return c; in chunkqueue_append_mem_chunk()
480 chunk * const c = chunk_acquire_filechunk(); in __attribute_nonnull__() local
481 chunkqueue_append_chunk(cq, c); in __attribute_nonnull__()
482 c->type = FILE_CHUNK; in __attribute_nonnull__()
483 c->offset = offset; in __attribute_nonnull__()
484 c->file.length = offset + len; in __attribute_nonnull__()
486 buffer_copy_buffer(c->mem, fn); in __attribute_nonnull__()
487 return c; in __attribute_nonnull__()
514 chunk *c = cq->last; in chunkqueue_append_mem_extend_chunk() local
516 if (c != NULL && c->type == MEM_CHUNK in chunkqueue_append_mem_extend_chunk()
517 && buffer_string_space(c->mem) >= len) { in chunkqueue_append_mem_extend_chunk()
518 buffer_append_string_len(c->mem, mem, len); in chunkqueue_append_mem_extend_chunk()
527 chunk *c; in chunkqueue_append_buffer() local
534 c = chunkqueue_append_mem_chunk(cq, chunk_buf_sz); in chunkqueue_append_buffer()
536 buffer_move(c->mem, mem); in chunkqueue_append_buffer()
541 chunk *c; in chunkqueue_append_mem() local
545 c = chunkqueue_append_mem_chunk(cq, len+1); in chunkqueue_append_mem()
547 buffer_copy_string_len(c->mem, mem, len); in chunkqueue_append_mem()
552 chunk *c; in chunkqueue_append_mem_min() local
556 c = chunk_init_sz(len+1); in chunkqueue_append_mem_min()
557 chunkqueue_append_chunk(cq, c); in chunkqueue_append_mem_min()
559 buffer_copy_string_len(c->mem, mem, len); in chunkqueue_append_mem_min()
581 chunk * const c = chunkqueue_prepend_mem_chunk(cq, sz); in chunkqueue_prepend_buffer_open_sz() local
582 return c->mem; in chunkqueue_prepend_buffer_open_sz()
597 chunk * const c = chunkqueue_append_mem_chunk(cq, sz); in chunkqueue_append_buffer_open_sz() local
598 return c->mem; in chunkqueue_append_buffer_open_sz()
615 chunk *c = cq->last; in chunkqueue_get_memory() local
616 if (NULL != c && MEM_CHUNK == c->type) { in chunkqueue_get_memory()
618 size_t avail = buffer_string_space(c->mem); in chunkqueue_get_memory()
621 b = c->mem; in chunkqueue_get_memory()
653 void chunkqueue_update_file(chunkqueue * const restrict cq, chunk *c, off_t len) { in chunkqueue_update_file() argument
655 c->file.length += len; in chunkqueue_update_file()
657 if (0 == chunk_remaining_length(c)) in chunkqueue_update_file()
677 static void chunkqueue_dup_file_chunk_fd (chunk * const restrict d, const chunk * const restrict c)… in chunkqueue_dup_file_chunk_fd() argument
681 if (c->file.fd >= 0) { in chunkqueue_dup_file_chunk_fd()
682 if (c->file.refchg) { in chunkqueue_dup_file_chunk_fd()
683 d->file.fd = c->file.fd; in chunkqueue_dup_file_chunk_fd()
684 d->file.ref = c->file.ref; in chunkqueue_dup_file_chunk_fd()
685 d->file.refchg = c->file.refchg; in chunkqueue_dup_file_chunk_fd()
689 d->file.fd = fdevent_dup_cloexec(c->file.fd); in chunkqueue_dup_file_chunk_fd()
691 if ((d->file.view = c->file.view)) in chunkqueue_dup_file_chunk_fd()
698 …ial_file_chunk(chunkqueue * const restrict dest, const chunk * const restrict c, const off_t len) { in chunkqueue_steal_partial_file_chunk() argument
699 chunkqueue_append_file(dest, c->mem, c->offset, len); in chunkqueue_steal_partial_file_chunk()
700 chunkqueue_dup_file_chunk_fd(dest->last, c); in chunkqueue_steal_partial_file_chunk()
708 chunk * const c = src->first; in chunkqueue_steal() local
709 if (__builtin_expect( (NULL == c), 0)) break; in chunkqueue_steal()
711 clen = chunk_remaining_length(c); in chunkqueue_steal()
715 src->first = c->next; in chunkqueue_steal()
716 if (c == src->last) src->last = NULL; in chunkqueue_steal()
719 chunkqueue_append_chunk(dest, c); in chunkqueue_steal()
723 chunk_release(c); in chunkqueue_steal()
727 switch (c->type) { in chunkqueue_steal()
729 chunkqueue_append_mem(dest, c->mem->ptr + c->offset, len); in chunkqueue_steal()
733 chunkqueue_steal_partial_file_chunk(dest, c, len); in chunkqueue_steal()
737 c->offset += len; in chunkqueue_steal()
758 chunk * const restrict c = chunkqueue_append_file_chunk(cq, &emptyb, 0, 0); in chunkqueue_get_append_newtempfile() local
759 buffer * const restrict template = c->mem; in chunkqueue_get_append_newtempfile()
760 c->file.is_temp = 1; in chunkqueue_get_append_newtempfile()
766 c->file.fd = in chunkqueue_get_append_newtempfile()
768 if (-1 != c->file.fd) return c; in chunkqueue_get_append_newtempfile()
772 c->file.fd = in chunkqueue_get_append_newtempfile()
774 if (-1 != c->file.fd) return c; in chunkqueue_get_append_newtempfile()
781 c->file.is_temp = 0; in chunkqueue_get_append_newtempfile()
786 chunk_release(c); in chunkqueue_get_append_newtempfile()
799 chunk * const c = cq->last; in chunkqueue_get_append_tempfile() local
800 if (NULL != c && c->file.is_temp && c->file.fd >= 0) { in chunkqueue_get_append_tempfile()
802 if (c->file.length < (off_t)cq->upload_temp_file_size) in chunkqueue_get_append_tempfile()
803 return c; /* ok, take the last chunk for our job */ in chunkqueue_get_append_tempfile()
806 force_assert(0 == c->file.refchg); /*(else should not happen)*/ in chunkqueue_get_append_tempfile()
807 int rc = close(c->file.fd); in chunkqueue_get_append_tempfile()
808 c->file.fd = -1; in chunkqueue_get_append_tempfile()
811 "close() temp-file %s failed", c->mem->ptr); in chunkqueue_get_append_tempfile()
819 …e_append_tempfile_err(chunkqueue * const cq, log_error_st * const restrict errh, chunk * const c) { in chunkqueue_append_tempfile_err() argument
827 "write() temp-file %s failed", c->mem->ptr); in chunkqueue_append_tempfile_err()
829 if (0 == chunk_remaining_length(c)) { in chunkqueue_append_tempfile_err()
834 force_assert(0 == c->file.refchg); /*(else should not happen)*/ in chunkqueue_append_tempfile_err()
835 int rc = close(c->file.fd); in chunkqueue_append_tempfile_err()
836 c->file.fd = -1; in chunkqueue_append_tempfile_err()
839 "close() temp-file %s failed", c->mem->ptr); in chunkqueue_append_tempfile_err()
926 static ssize_t chunkqueue_append_cqmem_to_tempfile_partial(chunkqueue * const dest, chunk * const c… in chunkqueue_append_cqmem_to_tempfile_partial() argument
929 while (ckpt->next != c) ckpt = ckpt->next; in chunkqueue_append_cqmem_to_tempfile_partial()
936 c->next = dest->first; /*(place tempfile at beginning of dest cq)*/ in chunkqueue_append_cqmem_to_tempfile_partial()
937 dest->first = c; in chunkqueue_append_cqmem_to_tempfile_partial()
950 chunk *c; in chunkqueue_append_cqmem_to_tempfile() local
951 for (c = dest->first; c && c->type == MEM_CHUNK; c = c->next) { in chunkqueue_append_cqmem_to_tempfile()
952 const off_t clen = chunk_remaining_length(c); in chunkqueue_append_cqmem_to_tempfile()
953 iov[iovcnt].iov_base = c->mem->ptr + c->offset; in chunkqueue_append_cqmem_to_tempfile()
960 if (__builtin_expect( (c != NULL), 0) && dest->first->type == MEM_CHUNK) { in chunkqueue_append_cqmem_to_tempfile()
970 for (c = src->first; c && c->type == MEM_CHUNK; c = c->next) { in chunkqueue_append_cqmem_to_tempfile()
971 off_t clen = chunk_remaining_length(c); in chunkqueue_append_cqmem_to_tempfile()
973 iov[iovcnt].iov_base = c->mem->ptr + c->offset; in chunkqueue_append_cqmem_to_tempfile()
985 c = chunkqueue_get_append_tempfile(dest, errh); in chunkqueue_append_cqmem_to_tempfile()
986 if (NULL == c) in chunkqueue_append_cqmem_to_tempfile()
989 if (c->file.fd < 0) return -1; in chunkqueue_append_cqmem_to_tempfile()
992 ssize_t wr = pwritev(c->file.fd, iov, (int)iovcnt, c->file.length); in chunkqueue_append_cqmem_to_tempfile()
1000 c->file.length += wr; in chunkqueue_append_cqmem_to_tempfile()
1005 chunkqueue_append_cqmem_to_tempfile_partial(dest,c,wr,errh); in chunkqueue_append_cqmem_to_tempfile()
1012 else if (chunkqueue_append_tempfile_err(dest, errh, c)) in chunkqueue_append_cqmem_to_tempfile()
1065 chunk * const c = chunkqueue_get_append_tempfile(cq, errh); in chunkqueue_append_splice_pipe_tempfile() local
1066 if (__builtin_expect( (NULL == c), 0)) return -errno; in chunkqueue_append_splice_pipe_tempfile()
1068 loff_t off = c->file.length; in chunkqueue_append_splice_pipe_tempfile()
1069 ssize_t wr = splice(fd, NULL, c->file.fd, &off, len, in chunkqueue_append_splice_pipe_tempfile()
1073 c->file.length += len; in chunkqueue_append_splice_pipe_tempfile()
1083 c->file.length += (size_t)wr; in chunkqueue_append_splice_pipe_tempfile()
1095 if (0 == chunk_remaining_length(c)) { in chunkqueue_append_splice_pipe_tempfile()
1104 if (!chunkqueue_append_tempfile_err(cq, errh, c)) in chunkqueue_append_splice_pipe_tempfile()
1173 chunk * const c = src->first; in chunkqueue_steal_with_tempfiles() local
1174 if (__builtin_expect( (NULL == c), 0)) break; in chunkqueue_steal_with_tempfiles()
1178 if (c->type == MEM_CHUNK) { in chunkqueue_steal_with_tempfiles()
1184 clen = chunk_remaining_length(c); in chunkqueue_steal_with_tempfiles()
1191 clen = chunk_remaining_length(c); in chunkqueue_steal_with_tempfiles()
1194 switch (c->type) { in chunkqueue_steal_with_tempfiles()
1203 c->mem->ptr+c->offset, in chunkqueue_steal_with_tempfiles()
1221 for (const chunk *c = src->first; len > 0 && c != NULL; c = c->next) { in chunkqueue_append_cq_range() local
1223 off_t clen = chunk_remaining_length(c); in chunkqueue_append_cq_range()
1232 if (c->type == FILE_CHUNK) { in chunkqueue_append_cq_range()
1233 chunkqueue_append_file(dst, c->mem, c->offset + offset, clen); in chunkqueue_append_cq_range()
1234 chunkqueue_dup_file_chunk_fd(dst->last, c); in chunkqueue_append_cq_range()
1239 chunkqueue_append_mem(dst, c->mem->ptr + c->offset + offset, clen); in chunkqueue_append_cq_range()
1248 for (chunk *c = cq->first; c; ) { in chunkqueue_mark_written() local
1249 off_t c_len = chunk_remaining_length(c); in chunkqueue_mark_written()
1251 chunk * const x = c; in chunkqueue_mark_written()
1252 c = c->next; in chunkqueue_mark_written()
1257 c->offset += len; in chunkqueue_mark_written()
1258 cq->first = c; in chunkqueue_mark_written()
1266 for (chunk *c; (c = cq->first) && 0 == chunk_remaining_length(c); ){ in chunkqueue_remove_finished_chunks() local
1267 if (NULL == (cq->first = c->next)) cq->last = NULL; in chunkqueue_remove_finished_chunks()
1268 chunk_release(c); in chunkqueue_remove_finished_chunks()
1273 chunk *c; in chunkqueue_remove_empty_chunks() local
1276 for (c = cq->first; c && c->next; c = c->next) { in chunkqueue_remove_empty_chunks()
1277 if (0 == chunk_remaining_length(c->next)) { in chunkqueue_remove_empty_chunks()
1278 chunk *empty = c->next; in chunkqueue_remove_empty_chunks()
1279 c->next = empty->next; in chunkqueue_remove_empty_chunks()
1280 if (empty == cq->last) cq->last = c; in chunkqueue_remove_empty_chunks()
1287 chunk * const restrict c = cq->first; in chunkqueue_compact_mem_offset() local
1288 if (0 == c->offset) return; in chunkqueue_compact_mem_offset()
1289 if (c->type != MEM_CHUNK) return; /*(should not happen)*/ in chunkqueue_compact_mem_offset()
1291 buffer * const restrict b = c->mem; in chunkqueue_compact_mem_offset()
1292 size_t len = buffer_clen(b) - c->offset; in chunkqueue_compact_mem_offset()
1293 memmove(b->ptr, b->ptr+c->offset, len); in chunkqueue_compact_mem_offset()
1294 c->offset = 0; in chunkqueue_compact_mem_offset()
1301 chunk *c = cq->first; in chunkqueue_compact_mem() local
1302 buffer *b = c->mem; in chunkqueue_compact_mem()
1303 size_t len = buffer_clen(b) - c->offset; in chunkqueue_compact_mem()
1311 buffer_append_string_len(b, c->mem->ptr + c->offset, len); in chunkqueue_compact_mem()
1312 cq->first->next = c->next; in chunkqueue_compact_mem()
1313 if (NULL == c->next) cq->last = cq->first; in chunkqueue_compact_mem()
1314 chunk_release(c); in chunkqueue_compact_mem()
1315 c = cq->first; in chunkqueue_compact_mem()
1318 for (chunk *fc = c; ((clen -= len) && (c = fc->next)); ) { in chunkqueue_compact_mem()
1319 len = buffer_clen(c->mem) - c->offset; in chunkqueue_compact_mem()
1321 buffer_append_string_len(b, c->mem->ptr + c->offset, clen); in chunkqueue_compact_mem()
1322 c->offset += clen; in chunkqueue_compact_mem()
1325 buffer_append_string_len(b, c->mem->ptr + c->offset, len); in chunkqueue_compact_mem()
1326 fc->next = c->next; in chunkqueue_compact_mem()
1327 if (NULL == c->next) cq->last = fc; in chunkqueue_compact_mem()
1328 chunk_release(c); in chunkqueue_compact_mem()
1334 static int chunk_open_file_chunk(chunk * const restrict c, log_error_st * const restrict errh) { in chunk_open_file_chunk() argument
1335 if (-1 == c->file.fd) { in chunk_open_file_chunk()
1337 if (-1 == (c->file.fd = fdevent_open_cloexec(c->mem->ptr, 1, O_RDONLY, 0))) { in chunk_open_file_chunk()
1338 log_perror(errh, __FILE__, __LINE__, "open failed: %s",c->mem->ptr); in chunk_open_file_chunk()
1344 if (c->file.is_temp) return 0; in chunk_open_file_chunk()
1347 if (-1 == fstat(c->file.fd, &st)) { in chunk_open_file_chunk()
1353 if (c->file.length > st.st_size) { in chunk_open_file_chunk()
1354 log_error(errh, __FILE__, __LINE__, "file shrunk: %s", c->mem->ptr); in chunk_open_file_chunk()
1381 chunkqueue_write_chunk_file_intermed (const int fd, chunk * const restrict c, log_error_st * const … in chunkqueue_write_chunk_file_intermed() argument
1385 const off_t len = c->file.length - c->offset; in chunkqueue_write_chunk_file_intermed()
1387 chunkqueue cq = {c,c,0,0,0,0,0}; /*(fake cq for chunkqueue_peek_data())*/ in chunkqueue_write_chunk_file_intermed()
1401 chunkqueue_write_chunk_file (const int fd, chunk * const restrict c, log_error_st * const errh) in chunkqueue_write_chunk_file() argument
1406 if (0 != chunk_open_file_chunk(c, errh)) in chunkqueue_write_chunk_file()
1409 const off_t len = c->file.length - c->offset; in chunkqueue_write_chunk_file()
1416 off_t offset = c->offset; in chunkqueue_write_chunk_file()
1418 sendfile(fd, c->file.fd, &offset, len < INT32_MAX ? len : INT32_MAX); in chunkqueue_write_chunk_file()
1425 chunkqueue_chunk_file_view(c, len, errh); in chunkqueue_write_chunk_file()
1427 const off_t mmap_avail = chunk_file_view_dlen(cfv, c->offset); in chunkqueue_write_chunk_file()
1428 return chunkqueue_write_data(fd, chunk_file_view_dptr(cfv, c->offset), in chunkqueue_write_chunk_file()
1433 return chunkqueue_write_chunk_file_intermed(fd, c, errh); in chunkqueue_write_chunk_file()
1438 chunkqueue_write_chunk_mem (const int fd, const chunk * const restrict c) in chunkqueue_write_chunk_mem() argument
1440 const void * const buf = c->mem->ptr + c->offset; in chunkqueue_write_chunk_mem()
1441 const size_t len = buffer_clen(c->mem) - (size_t)c->offset; in chunkqueue_write_chunk_mem()
1450 chunk * const c = cq->first; in chunkqueue_write_chunk() local
1451 switch (c->type) { in chunkqueue_write_chunk()
1453 return chunkqueue_write_chunk_mem(fd, c); in chunkqueue_write_chunk()
1455 return chunkqueue_write_chunk_file(fd, c, errh); in chunkqueue_write_chunk()
1467 chunk * const c = cq->first; in chunkqueue_write_chunk_to_pipe() local
1468 if (c->type == FILE_CHUNK) { in chunkqueue_write_chunk_to_pipe()
1469 const size_t len = (size_t)(c->file.length - c->offset); in chunkqueue_write_chunk_to_pipe()
1470 loff_t abs_offset = c->offset; in chunkqueue_write_chunk_to_pipe()
1472 return (0 == chunk_open_file_chunk(c, errh)) in chunkqueue_write_chunk_to_pipe()
1473 ? splice(c->file.fd, &abs_offset, fd, NULL, len, SPLICE_F_NONBLOCK) in chunkqueue_write_chunk_to_pipe()
1496 chunk * restrict c = cq->first; in chunkqueue_small_resp_optim() local
1497 chunk * const restrict filec = c->next; /*(require file already be open)*/ in chunkqueue_small_resp_optim()
1505 if ((size_t)len > buffer_string_space(c->mem)) { in chunkqueue_small_resp_optim()
1506 c->next = chunk_acquire((size_t)len+1); in chunkqueue_small_resp_optim()
1507 c = c->next; in chunkqueue_small_resp_optim()
1511 c->next = NULL; in chunkqueue_small_resp_optim()
1512 cq->last = c; in chunkqueue_small_resp_optim()
1516 char * const ptr = buffer_extend(c->mem, len); in chunkqueue_small_resp_optim()
1525 buffer_truncate(c->mem, (uint32_t)(ptr + offset - c->mem->ptr)); in chunkqueue_small_resp_optim()
1526 cq->last = c->next = filec; in chunkqueue_small_resp_optim()
1529 else if (__builtin_expect( (cq->first != c), 0)) { in chunkqueue_small_resp_optim()
1531 chunk_release(c); in chunkqueue_small_resp_optim()
1560 for (chunk *c = cq->first; c; ) { in chunkqueue_peek_data() local
1562 switch (c->type) { in chunkqueue_peek_data()
1565 uint32_t have = buffer_clen(c->mem) - (uint32_t)c->offset; in chunkqueue_peek_data()
1571 memcpy(data_in + *dlen, c->mem->ptr + c->offset, have); in chunkqueue_peek_data()
1573 *data = c->mem->ptr + c->offset; /*(reference; defer copy)*/ in chunkqueue_peek_data()
1579 if (c->file.fd >= 0 || 0 == chunk_open_file_chunk(c, errh)) { in chunkqueue_peek_data()
1580 off_t len = c->file.length - c->offset; in chunkqueue_peek_data()
1601 const chunk_file_view * const restrict cfv = (!c->file.is_temp) in chunkqueue_peek_data()
1602 ? chunkqueue_chunk_file_view(c, len, errh) in chunkqueue_peek_data()
1604 if (cfv && chunk_file_view_dlen(cfv, c->offset) >= len) { in chunkqueue_peek_data()
1606 char * const mdata = chunk_file_view_dptr(cfv, c->offset); in chunkqueue_peek_data()
1607 if (!c->file.is_temp) {/*(might be changed to policy flag)*/ in chunkqueue_peek_data()
1611 "SIGBUS in mmap: %s %d", c->mem->ptr, c->file.fd); in chunkqueue_peek_data()
1625 ssize_t rd = chunk_file_pread(c->file.fd, data_in+*dlen, in chunkqueue_peek_data()
1626 (size_t)len, c->offset); in chunkqueue_peek_data()
1629 c->mem->ptr); in chunkqueue_peek_data()
1645 c = c->next; in chunkqueue_peek_data()
1646 if (NULL == c) in chunkqueue_peek_data()
1686 chunk * const c = chunk_acquire((uint32_t)cqlen+1); in chunkqueue_read_squash() local
1687 char *data = c->mem->ptr; in chunkqueue_read_squash()
1691 chunk_release(c); in chunkqueue_read_squash()
1694 buffer_truncate(c->mem, dlen); in chunkqueue_read_squash()
1697 chunkqueue_append_chunk(cq, c); in chunkqueue_read_squash()
1698 return c->mem; in chunkqueue_read_squash()
1705 chunkqueue_chunk_file_viewadj (chunk * const c, off_t n, log_error_st * restrict errh) in chunkqueue_chunk_file_viewadj() argument
1708 chunk_file_view * restrict cfv = c->file.view; in chunkqueue_chunk_file_viewadj()
1712 cfv = c->file.view = chunk_file_view_init(); in chunkqueue_chunk_file_viewadj()
1718 if (c->file.fd < 0 && 0 != chunk_open_file_chunk(c, errh)) { in chunkqueue_chunk_file_viewadj()
1719 c->file.view = chunk_file_view_failed(cfv); in chunkqueue_chunk_file_viewadj()
1723 cfv->foff = mmap_align_offset(c->offset); in chunkqueue_chunk_file_viewadj()
1726 cfv->mlen = c->offset - cfv->foff + n; in chunkqueue_chunk_file_viewadj()
1739 if (cfv->mlen > c->file.length - cfv->foff) in chunkqueue_chunk_file_viewadj()
1740 cfv->mlen = c->file.length - cfv->foff; in chunkqueue_chunk_file_viewadj()
1743 c->file.is_temp ? MAP_PRIVATE : chunk_mmap_flags, in chunkqueue_chunk_file_viewadj()
1744 c->file.fd, cfv->foff); in chunkqueue_chunk_file_viewadj()
1751 MAP_PRIVATE, c->file.fd, cfv->foff); in chunkqueue_chunk_file_viewadj()
1754 c->file.view = chunk_file_view_failed(cfv); in chunkqueue_chunk_file_viewadj()
1763 if (c->file.is_temp && !c->file.refchg) { in chunkqueue_chunk_file_viewadj()
1764 close(c->file.fd); in chunkqueue_chunk_file_viewadj()
1765 c->file.fd = -1; in chunkqueue_chunk_file_viewadj()