istream-mmap.c revision dd62b77c932d1b518f2a3e4bf80e36542becc256
/* Copyright (c) 2002-2003 Timo Sirainen */
#include "lib.h"
#include "mmap-util.h"
#include "istream-internal.h"
#include <unistd.h>
struct mmap_istream {
int fd;
void *mmap_base;
unsigned int autoclose_fd:1;
};
static size_t mmap_pagesize = 0;
static size_t mmap_pagemask = 0;
{
i_error("mmap_istream.close() failed: %m");
}
}
{
i_error("mmap_istream.munmap() failed: %m");
_stream->buffer_size = 0;
mstream->mmap_offset = 0;
}
}
{
}
{
/* allow only full page sizes */
if (max_size < mmap_pagesize)
else {
if (max_size % mmap_pagesize != 0)
}
}
void (*timeout_cb)(void *) __attr_unused__,
void *context __attr_unused__)
{
/* we never block */
}
{
/* more bytes available without needing to mmap() */
}
return -1;
}
/* didn't skip enough bytes */
return -2;
}
i_error("io_stream_read_mmaped(): munmap() failed: %m");
}
stream->buffer_size = 0;
i_error("mmap_istream.mmap() failed: %m");
return -1;
}
MADV_SEQUENTIAL) < 0)
i_error("mmap_istream.madvise(): %m");
}
}
{
if (stream->buffer_size != 0 &&
/* already mmaped */
} else {
/* force reading next time */
}
}
{
}
int autoclose_fd)
{
struct mmap_istream *mstream;
if (mmap_pagesize == 0) {
mmap_pagesize = getpagesize();
}
if (v_size == 0) {
i_error("i_stream_create_mmap(): fstat() failed: %m");
else {
if (start_offset > v_size)
v_size -= start_offset;
}
}
return istream;
}