Lines Matching full:seg

153 static int evbuffer_file_segment_materialize(struct evbuffer_file_segment *seg);
2967 struct evbuffer_file_segment *seg = in evbuffer_file_segment_new() local
2969 if (!seg) in evbuffer_file_segment_new()
2971 seg->refcnt = 1; in evbuffer_file_segment_new()
2972 seg->fd = fd; in evbuffer_file_segment_new()
2973 seg->flags = flags; in evbuffer_file_segment_new()
2974 seg->file_offset = offset; in evbuffer_file_segment_new()
2975 seg->cleanup_cb = NULL; in evbuffer_file_segment_new()
2976 seg->cleanup_cb_arg = NULL; in evbuffer_file_segment_new()
2994 seg->length = length; in evbuffer_file_segment_new()
3003 seg->can_sendfile = 1; in evbuffer_file_segment_new()
3008 if (evbuffer_file_segment_materialize(seg)<0) in evbuffer_file_segment_new()
3015 EVTHREAD_ALLOC_LOCK(seg->lock, 0); in evbuffer_file_segment_new()
3017 return seg; in evbuffer_file_segment_new()
3019 mm_free(seg); in evbuffer_file_segment_new()
3040 evbuffer_file_segment_materialize(struct evbuffer_file_segment *seg) in evbuffer_file_segment_materialize() argument
3042 const unsigned flags = seg->flags; in evbuffer_file_segment_materialize()
3043 const int fd = seg->fd; in evbuffer_file_segment_materialize()
3044 const ev_off_t length = seg->length; in evbuffer_file_segment_materialize()
3045 const ev_off_t offset = seg->file_offset; in evbuffer_file_segment_materialize()
3047 if (seg->contents) in evbuffer_file_segment_materialize()
3077 seg->mapping = mapped; in evbuffer_file_segment_materialize()
3078 seg->contents = (char*)mapped+offset_leftover; in evbuffer_file_segment_materialize()
3079 seg->mmap_offset = 0; in evbuffer_file_segment_materialize()
3080 seg->is_mapping = 1; in evbuffer_file_segment_materialize()
3096 seg->mapping_handle = m; in evbuffer_file_segment_materialize()
3097 seg->mmap_offset = offset; in evbuffer_file_segment_materialize()
3098 seg->is_mapping = 1; in evbuffer_file_segment_materialize()
3137 seg->contents = mem; in evbuffer_file_segment_materialize()
3146 void evbuffer_file_segment_add_cleanup_cb(struct evbuffer_file_segment *seg, in evbuffer_file_segment_add_cleanup_cb() argument
3149 EVUTIL_ASSERT(seg->refcnt > 0); in evbuffer_file_segment_add_cleanup_cb()
3150 seg->cleanup_cb = cb; in evbuffer_file_segment_add_cleanup_cb()
3151 seg->cleanup_cb_arg = arg; in evbuffer_file_segment_add_cleanup_cb()
3155 evbuffer_file_segment_free(struct evbuffer_file_segment *seg) in evbuffer_file_segment_free() argument
3158 EVLOCK_LOCK(seg->lock, 0); in evbuffer_file_segment_free()
3159 refcnt = --seg->refcnt; in evbuffer_file_segment_free()
3160 EVLOCK_UNLOCK(seg->lock, 0); in evbuffer_file_segment_free()
3165 if (seg->is_mapping) { in evbuffer_file_segment_free()
3167 CloseHandle(seg->mapping_handle); in evbuffer_file_segment_free()
3170 offset_leftover = seg->file_offset % get_page_size(); in evbuffer_file_segment_free()
3171 if (munmap(seg->mapping, seg->length + offset_leftover) == -1) in evbuffer_file_segment_free()
3174 } else if (seg->contents) { in evbuffer_file_segment_free()
3175 mm_free(seg->contents); in evbuffer_file_segment_free()
3178 if ((seg->flags & EVBUF_FS_CLOSE_ON_FREE) && seg->fd >= 0) { in evbuffer_file_segment_free()
3179 close(seg->fd); in evbuffer_file_segment_free()
3182 if (seg->cleanup_cb) { in evbuffer_file_segment_free()
3183 (*seg->cleanup_cb)((struct evbuffer_file_segment const*)seg, in evbuffer_file_segment_free()
3184 seg->flags, seg->cleanup_cb_arg); in evbuffer_file_segment_free()
3185 seg->cleanup_cb = NULL; in evbuffer_file_segment_free()
3186 seg->cleanup_cb_arg = NULL; in evbuffer_file_segment_free()
3189 EVTHREAD_FREE_LOCK(seg->lock, 0); in evbuffer_file_segment_free()
3190 mm_free(seg); in evbuffer_file_segment_free()
3195 struct evbuffer_file_segment *seg, ev_off_t offset, ev_off_t length) in evbuffer_add_file_segment() argument
3202 EVLOCK_LOCK(seg->lock, 0); in evbuffer_add_file_segment()
3206 if (!seg->contents) { in evbuffer_add_file_segment()
3207 if (evbuffer_file_segment_materialize(seg)<0) { in evbuffer_add_file_segment()
3208 EVLOCK_UNLOCK(seg->lock, 0); in evbuffer_add_file_segment()
3214 EVLOCK_UNLOCK(seg->lock, 0); in evbuffer_add_file_segment()
3220 if (offset > seg->length) in evbuffer_add_file_segment()
3222 length = seg->length - offset; in evbuffer_add_file_segment()
3226 if (offset+length > seg->length) in evbuffer_add_file_segment()
3235 if (can_use_sendfile && seg->can_sendfile) { in evbuffer_add_file_segment()
3237 chain->misalign = seg->file_offset + offset; in evbuffer_add_file_segment()
3240 } else if (seg->is_mapping) { in evbuffer_add_file_segment()
3242 ev_uint64_t total_offset = seg->mmap_offset+offset; in evbuffer_add_file_segment()
3253 seg->mapping_handle, in evbuffer_add_file_segment()
3267 chain->buffer = (unsigned char*)(seg->contents + offset); in evbuffer_add_file_segment()
3272 chain->buffer = (unsigned char*)(seg->contents + offset); in evbuffer_add_file_segment()
3277 EVLOCK_LOCK(seg->lock, 0); in evbuffer_add_file_segment()
3278 ++seg->refcnt; in evbuffer_add_file_segment()
3279 EVLOCK_UNLOCK(seg->lock, 0); in evbuffer_add_file_segment()
3280 extra->segment = seg; in evbuffer_add_file_segment()
3291 evbuffer_file_segment_free(seg); /* Lowers the refcount */ in evbuffer_add_file_segment()
3298 struct evbuffer_file_segment *seg; in evbuffer_add_file() local
3302 seg = evbuffer_file_segment_new(fd, offset, length, flags); in evbuffer_add_file()
3303 if (!seg) in evbuffer_add_file()
3305 r = evbuffer_add_file_segment(buf, seg, 0, length); in evbuffer_add_file()
3307 evbuffer_file_segment_free(seg); in evbuffer_add_file()