static apr_status_t serf_mmap_readline(serf_bucket_t *bucket, int acceptable, int *found, const char **data, apr_size_t *len) { mmap_context_t *ctx = bucket->data; const char *end; /* ### Would it be faster to call this once and do the offset ourselves? */ apr_mmap_offset((void**)data, ctx->mmap, ctx->offset); end = *data; /* XXX An overflow is generated if we pass &ctx->remaining to readline. * Not real clear why. */ *len = ctx->remaining; serf_util_readline(&end, len, acceptable, found); *len = end - *data; ctx->offset += *len; ctx->remaining -= *len; if (ctx->remaining == 0) { return APR_EOF; } return APR_SUCCESS; }
static apr_status_t serf_mmap_read(serf_bucket_t *bucket, apr_size_t requested, const char **data, apr_size_t *len) { mmap_context_t *ctx = bucket->data; if (requested == SERF_READ_ALL_AVAIL || requested > ctx->remaining) { *len = ctx->remaining; } else { *len = requested; } /* ### Would it be faster to call this once and do the offset ourselves? */ apr_mmap_offset((void**)data, ctx->mmap, ctx->offset); /* For the next read... */ ctx->offset += *len; ctx->remaining -= *len; if (ctx->remaining == 0) { return APR_EOF; } return APR_SUCCESS; }
static void test_mmap_offset(abts_case *tc, void *data) { apr_status_t rv; void *addr; ABTS_PTR_NOTNULL(tc, themmap); rv = apr_mmap_offset(&addr, themmap, 5); /* Must use nEquals since the string is not guaranteed to be NULL terminated */ ABTS_STR_NEQUAL(tc, addr, TEST_STRING + 5, thisfsize-5); }
static int jk2_shm_create(jk_env_t *env, jk_shm_t *shm) { int rc; apr_file_t *file; apr_finfo_t finfo; apr_mmap_t *aprMmap; apr_pool_t *globalShmPool; globalShmPool= (apr_pool_t *)env->getAprPool( env ); if( globalShmPool==NULL ) return JK_FALSE; /* Check if the scoreboard is in a note. That's the only way we can get HP-UX to work */ apr_pool_userdata_get( & shm->image, "mod_jk_shm",globalShmPool ); if( shm->image!=NULL ) { shm->head = (jk_shm_head_t *)shm->image; if( shm->mbean->debug > 0 ) env->l->jkLog(env, env->l, JK_LOG_DEBUG, "shm.create(): GLOBAL_SHM %#lx\n", shm->image ); return JK_OK; } else { if( shm->mbean->debug > 0 ) env->l->jkLog(env, env->l, JK_LOG_DEBUG, "shm.create(): NO GLOBAL_SHM %#lx\n", shm->image ); } /* First make sure the file exists and is big enough */ rc=apr_file_open( &file, shm->fname, APR_READ | APR_WRITE | APR_CREATE | APR_BINARY, APR_OS_DEFAULT, globalShmPool); if (rc!=JK_OK) { char error[256]; apr_strerror( rc, error, 256 ); env->l->jkLog(env, env->l, JK_LOG_ERROR, "shm.create(): error opening file %s %d %s\n", shm->fname, rc, error ); shm->privateData=NULL; return rc; } rc=apr_file_info_get(&finfo, APR_FINFO_SIZE, file); if( shm->mbean->debug > 0 ) env->l->jkLog(env, env->l, JK_LOG_DEBUG, "shm.create(): file open %s %d %d\n", shm->fname, shm->size, finfo.size ); if( finfo.size < shm->size ) { char bytes[1024]; apr_size_t toWrite = (apr_size_t)(shm->size-finfo.size); apr_off_t off=0; memset( bytes, 0, 1024 ); apr_file_seek( file, APR_END, &off); while( toWrite > 0 ) { apr_size_t written; rc=apr_file_write_full(file, bytes, 1024, &written); if( rc!=APR_SUCCESS ) { env->l->jkLog(env, env->l, JK_LOG_ERROR, "shm.create(): Can't write %s %d %s\n", shm->fname, errno, strerror( errno )); return JK_ERR; } if( toWrite < written ){ toWrite=0; }else{ toWrite-=written; } } rc=apr_file_info_get(&finfo, APR_FINFO_SIZE, file); } /* Now mmap it */ rc=apr_mmap_create( &aprMmap, file, (apr_off_t)0, (apr_size_t)finfo.size, APR_MMAP_READ | APR_MMAP_WRITE, globalShmPool ); if( rc!=JK_OK ) { char error[256]; apr_strerror( rc, error, 256 ); env->l->jkLog(env, env->l, JK_LOG_ERROR, "shm.create(): error creating %s %d %d %#lx %s\n", shm->fname, finfo.size, rc, globalShmPool, error ); shm->privateData=NULL; return rc; } shm->privateData=aprMmap; apr_mmap_offset(& shm->image, aprMmap, (apr_off_t)0); apr_pool_userdata_set( shm->image, "mod_jk_shm", NULL, globalShmPool ); shm->head = (jk_shm_head_t *)shm->image; if( shm->image==NULL ) { env->l->jkLog(env, env->l, JK_LOG_ERROR, "shm.create(): No base memory %s\n", shm->fname); return JK_ERR; } return JK_OK; }