dovecot: Code cleanup

dovecot at dovecot.org dovecot at dovecot.org
Sun Jul 15 01:21:59 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/16f91815c7ed
changeset: 6002:16f91815c7ed
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jul 15 01:21:53 2007 +0300
description:
Code cleanup

diffstat:

1 file changed, 38 insertions(+), 29 deletions(-)
src/lib-index/mail-transaction-log-file.c |   67 ++++++++++++++++-------------

diffs (90 lines):

diff -r 2d81847eb3e6 -r 16f91815c7ed src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Sun Jul 15 01:04:56 2007 +0300
+++ b/src/lib-index/mail-transaction-log-file.c	Sun Jul 15 01:21:53 2007 +0300
@@ -854,12 +854,44 @@ mail_transaction_log_file_insert_read(st
 }
 
 static int
-mail_transaction_log_file_read(struct mail_transaction_log_file *file,
-			       uoff_t start_offset)
+mail_transaction_log_file_read_more(struct mail_transaction_log_file *file)
 {
 	void *data;
 	size_t size;
 	uint32_t read_offset;
+	ssize_t ret;
+
+	read_offset = file->buffer_offset + buffer_get_used_size(file->buffer);
+
+	do {
+		data = buffer_append_space_unsafe(file->buffer, LOG_PREFETCH);
+		ret = pread(file->fd, data, LOG_PREFETCH, read_offset);
+		if (ret > 0)
+			read_offset += ret;
+
+		size = read_offset - file->buffer_offset;
+		buffer_set_used_size(file->buffer, size);
+	} while (ret > 0 || (ret < 0 && errno == EINTR));
+
+	file->last_size = read_offset;
+
+	if (ret < 0) {
+		if (errno == ESTALE) {
+			/* log file was deleted in NFS server, fail silently */
+			return 0;
+		}
+
+		mail_index_file_set_syscall_error(file->log->index,
+						  file->filepath, "pread()");
+		return -1;
+	}
+	return 1;
+}
+
+static int
+mail_transaction_log_file_read(struct mail_transaction_log_file *file,
+			       uoff_t start_offset)
+{
 	int ret;
 
 	i_assert(file->mmap_base == NULL);
@@ -882,35 +914,12 @@ mail_transaction_log_file_read(struct ma
 		file->buffer_offset = start_offset;
 	}
 
-	/* read all records */
-	read_offset = file->buffer_offset + buffer_get_used_size(file->buffer);
-
-	do {
-		data = buffer_append_space_unsafe(file->buffer, LOG_PREFETCH);
-		ret = pread(file->fd, data, LOG_PREFETCH, read_offset);
-		if (ret > 0)
-			read_offset += ret;
-
-		size = read_offset - file->buffer_offset;
-		buffer_set_used_size(file->buffer, size);
-	} while (ret > 0 || (ret < 0 && errno == EINTR));
-
-	file->last_size = read_offset;
-
-	if (ret < 0) {
-		if (errno == ESTALE) {
-			/* log file was deleted in NFS server, fail silently */
-			return 0;
-		}
-
-		mail_index_file_set_syscall_error(file->log->index,
-						  file->filepath, "pread()");
-		return -1;
-	}
+	if ((ret = mail_transaction_log_file_read_more(file)) <= 0)
+		return ret;
 
 	if ((ret = mail_transaction_log_file_sync(file)) <= 0) {
-		i_assert(ret != 0);
-		return 0;
+		i_assert(ret != 0); /* happens only with mmap */
+		return -1;
 	}
 
 	i_assert(file->sync_offset >= file->buffer_offset);


More information about the dovecot-cvs mailing list