dovecot-2.2: istreams: Added default seek() implementation for s...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 29 09:02:37 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/11e774a9d22c
changeset: 14700:11e774a9d22c
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 29 09:01:56 2012 +0300
description:
istreams: Added default seek() implementation for seekable streams.

diffstat:

 src/lib-storage/index/istream-mail.c |   9 ---------
 src/lib/istream-base64-encoder.c     |   2 +-
 src/lib/istream-limit.c              |   8 --------
 src/lib/istream-private.h            |   4 ++--
 src/lib/istream-seekable.c           |   8 --------
 src/lib/istream-sized.c              |  13 -------------
 src/lib/istream.c                    |  17 +++++++++++++----
 7 files changed, 16 insertions(+), 45 deletions(-)

diffs (165 lines):

diff -r 38b0986605a6 -r 11e774a9d22c src/lib-storage/index/istream-mail.c
--- a/src/lib-storage/index/istream-mail.c	Fri Jun 29 08:01:08 2012 +0300
+++ b/src/lib-storage/index/istream-mail.c	Fri Jun 29 09:01:56 2012 +0300
@@ -93,14 +93,6 @@
 	return ret;
 }
 
-static void
-i_stream_mail_seek(struct istream_private *stream,
-		   uoff_t v_offset, bool mark ATTR_UNUSED)
-{
-	stream->istream.v_offset = v_offset;
-	stream->skip = stream->pos = 0;
-}
-
 static const struct stat *
 i_stream_mail_stat(struct istream_private *stream, bool exact)
 {
@@ -121,7 +113,6 @@
 
 	mstream->istream.parent = input;
 	mstream->istream.read = i_stream_mail_read;
-	mstream->istream.seek = i_stream_mail_seek;
 	mstream->istream.stat = i_stream_mail_stat;
 
 	mstream->istream.istream.blocking = input->blocking;
diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-base64-encoder.c
--- a/src/lib/istream-base64-encoder.c	Fri Jun 29 08:01:08 2012 +0300
+++ b/src/lib/istream-base64-encoder.c	Fri Jun 29 09:01:56 2012 +0300
@@ -147,7 +147,7 @@
 		bstream->cur_line_len = 0;
 		i_stream_seek(stream->parent, 0);
 	}
-	i_stream_default_seek(stream, v_offset, mark);
+	i_stream_default_seek_nonseekable(stream, v_offset, mark);
 }
 
 struct istream *
diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-limit.c
--- a/src/lib/istream-limit.c	Fri Jun 29 08:01:08 2012 +0300
+++ b/src/lib/istream-limit.c	Fri Jun 29 09:01:56 2012 +0300
@@ -71,13 +71,6 @@
 	return ret;
 }
 
-static void i_stream_limit_seek(struct istream_private *stream, uoff_t v_offset,
-				bool mark ATTR_UNUSED)
-{
-	stream->istream.v_offset = v_offset;
-	stream->skip = stream->pos = 0;
-}
-
 static const struct stat *
 i_stream_limit_stat(struct istream_private *stream, bool exact)
 {
@@ -126,7 +119,6 @@
 	lstream->istream.iostream.destroy = i_stream_limit_destroy;
 	lstream->istream.parent = input;
 	lstream->istream.read = i_stream_limit_read;
-	lstream->istream.seek = i_stream_limit_seek;
 	lstream->istream.stat = i_stream_limit_stat;
 	lstream->istream.get_size = i_stream_limit_get_size;
 
diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-private.h
--- a/src/lib/istream-private.h	Fri Jun 29 08:01:08 2012 +0300
+++ b/src/lib/istream-private.h	Fri Jun 29 09:01:56 2012 +0300
@@ -58,7 +58,7 @@
 		   size_t wanted_size, size_t *size_r);
 void *i_stream_alloc(struct istream_private *stream, size_t size);
 ssize_t i_stream_read_copy_from_parent(struct istream *istream);
-void i_stream_default_seek(struct istream_private *stream,
-			   uoff_t v_offset, bool mark);
+void i_stream_default_seek_nonseekable(struct istream_private *stream,
+				       uoff_t v_offset, bool mark);
 
 #endif
diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-seekable.c
--- a/src/lib/istream-seekable.c	Fri Jun 29 08:01:08 2012 +0300
+++ b/src/lib/istream-seekable.c	Fri Jun 29 09:01:56 2012 +0300
@@ -286,13 +286,6 @@
 	return ret;
 }
 
-static void i_stream_seekable_seek(struct istream_private *stream,
-				   uoff_t v_offset, bool mark ATTR_UNUSED)
-{
-	stream->istream.v_offset = v_offset;
-	stream->skip = stream->pos = 0;
-}
-
 static const struct stat *
 i_stream_seekable_stat(struct istream_private *stream, bool exact)
 {
@@ -388,7 +381,6 @@
 		i_stream_seekable_set_max_buffer_size;
 
 	sstream->istream.read = i_stream_seekable_read;
-	sstream->istream.seek = i_stream_seekable_seek;
 	sstream->istream.stat = i_stream_seekable_stat;
 
 	sstream->istream.istream.readable_fd = FALSE;
diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-sized.c
--- a/src/lib/istream-sized.c	Fri Jun 29 08:01:08 2012 +0300
+++ b/src/lib/istream-sized.c	Fri Jun 29 09:01:56 2012 +0300
@@ -70,18 +70,6 @@
 	return ret;
 }
 
-static void
-i_stream_sized_seek(struct istream_private *stream,
-		    uoff_t v_offset, bool mark ATTR_UNUSED)
-{
-	struct sized_istream *sstream = (struct sized_istream *)stream;
-
-	i_assert(v_offset <= sstream->size);
-
-	stream->istream.v_offset = v_offset;
-	stream->skip = stream->pos = 0;
-}
-
 static const struct stat *
 i_stream_sized_stat(struct istream_private *stream, bool sized ATTR_UNUSED)
 {
@@ -110,7 +98,6 @@
 
 	sstream->istream.parent = input;
 	sstream->istream.read = i_stream_sized_read;
-	sstream->istream.seek = i_stream_sized_seek;
 	sstream->istream.stat = i_stream_sized_stat;
 
 	sstream->istream.istream.readable_fd = input->readable_fd;
diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream.c
--- a/src/lib/istream.c	Fri Jun 29 08:01:08 2012 +0300
+++ b/src/lib/istream.c	Fri Jun 29 09:01:56 2012 +0300
@@ -567,8 +567,16 @@
 		i_stream_unref(&_stream->parent);
 }
 
-void i_stream_default_seek(struct istream_private *stream,
-			   uoff_t v_offset, bool mark ATTR_UNUSED)
+static void
+i_stream_default_seek_seekable(struct istream_private *stream,
+			       uoff_t v_offset, bool mark ATTR_UNUSED)
+{
+	stream->istream.v_offset = v_offset;
+	stream->skip = stream->pos = 0;
+}
+
+void i_stream_default_seek_nonseekable(struct istream_private *stream,
+				       uoff_t v_offset, bool mark ATTR_UNUSED)
 {
 	size_t available;
 
@@ -632,8 +640,9 @@
 	if (_stream->iostream.destroy == NULL)
 		_stream->iostream.destroy = i_stream_default_destroy;
 	if (_stream->seek == NULL) {
-		i_assert(!_stream->istream.seekable);
-		_stream->seek = i_stream_default_seek;
+		_stream->seek = _stream->istream.seekable ?
+			i_stream_default_seek_seekable :
+			i_stream_default_seek_nonseekable;
 	}
 	if (_stream->stat == NULL)
 		_stream->stat = i_stream_default_stat;


More information about the dovecot-cvs mailing list