offset = next_offset;
invalidate = TRUE;
- if (cache->mmap_base != NULL) {
+ if (cache->mmap_base != NULL || cache->map_with_read) {
ret = mail_cache_map(cache, offset, sizeof(*field_hdr),
&data);
if (ret <= 0) {
#include <unistd.h>
+#define MAIL_CACHE_MIN_HEADER_READ_SIZE 4096
+
void mail_cache_set_syscall_error(struct mail_cache *cache,
const char *function)
{
} else {
buffer_set_used_size(cache->read_buf, 0);
}
+ if (offset == 0 && size < MAIL_CACHE_MIN_HEADER_READ_SIZE) {
+ /* we can usually read the fields header after the cache
+ header. we need them both, so try to read them all with one
+ pread() call. */
+ size = MAIL_CACHE_MIN_HEADER_READ_SIZE;
+ }
+
data = buffer_append_space_unsafe(cache->read_buf, size);
ret = pread(cache->fd, data, size, offset);
if (ret < 0) {