1 /* Copyright 2002-2004 Justin Erenkrantz and Greg Stein
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <apr_pools.h>
20 #include "serf_bucket_util.h"
31 SERF_DECLARE(serf_bucket_t *) serf_bucket_mmap_create(
32 apr_mmap_t *file_mmap,
33 serf_bucket_alloc_t *allocator)
37 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
38 ctx->mmap = file_mmap;
41 ctx->remaining = ctx->mmap->size;
43 return serf_bucket_create(&serf_bucket_type_mmap, allocator, ctx);
46 static apr_status_t serf_mmap_read(serf_bucket_t *bucket,
48 const char **data, apr_size_t *len)
50 mmap_context_t *ctx = bucket->data;
52 if (requested == SERF_READ_ALL_AVAIL || requested > ctx->remaining) {
53 *len = ctx->remaining;
59 /* ### Would it be faster to call this once and do the offset ourselves? */
60 apr_mmap_offset((void**)data, ctx->mmap, ctx->offset);
62 /* For the next read... */
64 ctx->remaining -= *len;
66 if (ctx->remaining == 0) {
72 static apr_status_t serf_mmap_readline(serf_bucket_t *bucket,
73 int acceptable, int *found,
74 const char **data, apr_size_t *len)
76 mmap_context_t *ctx = bucket->data;
79 /* ### Would it be faster to call this once and do the offset ourselves? */
80 apr_mmap_offset((void**)data, ctx->mmap, ctx->offset);
83 /* XXX An overflow is generated if we pass &ctx->remaining to readline.
86 *len = ctx->remaining;
88 serf_util_readline(&end, len, acceptable, found);
93 ctx->remaining -= *len;
95 if (ctx->remaining == 0) {
101 static apr_status_t serf_mmap_peek(serf_bucket_t *bucket,
109 SERF_DECLARE_DATA const serf_bucket_type_t serf_bucket_type_mmap = {
113 serf_default_read_iovec,
114 serf_default_read_for_sendfile,
115 serf_default_read_bucket,
117 serf_default_destroy_and_data,