# HG changeset patch # User Timo Sirainen # Date 1128111038 -10800 # Node ID e05a1af4bbc770908a9a62a87ce6db7c5f84ea05 # Parent 571336db01f46da5d37c06239b1982e80bf810c2 Added i_stream_seek_mark() and used it diff -r 571336db01f4 -r e05a1af4bbc7 src/lib-mail/istream-header-filter.c --- a/src/lib-mail/istream-header-filter.c Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib-mail/istream-header-filter.c Fri Sep 30 23:10:38 2005 +0300 @@ -234,7 +234,8 @@ return ret; } -static void _seek(struct _istream *stream, uoff_t v_offset) +static void _seek(struct _istream *stream, uoff_t v_offset, + int mark __attr_unused__) { struct header_filter_istream *mstream = (struct header_filter_istream *)stream; diff -r 571336db01f4 -r e05a1af4bbc7 src/lib-storage/index/mbox/istream-raw-mbox.c --- a/src/lib-storage/index/mbox/istream-raw-mbox.c Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib-storage/index/mbox/istream-raw-mbox.c Fri Sep 30 23:10:38 2005 +0300 @@ -279,7 +279,8 @@ return ret; } -static void _seek(struct _istream *stream, uoff_t v_offset) +static void _seek(struct _istream *stream, uoff_t v_offset, + int mark __attr_unused__) { struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream; @@ -492,8 +493,8 @@ rstream->body_offset = (uoff_t)-1; if (stream->v_offset != rstream->from_offset) - i_stream_seek(stream, rstream->from_offset); - i_stream_seek(rstream->input, rstream->from_offset); + i_stream_seek_mark(stream, rstream->from_offset); + i_stream_seek_mark(rstream->input, rstream->from_offset); rstream->eof = FALSE; rstream->istream.istream.eof = FALSE; @@ -535,8 +536,8 @@ check = TRUE; } - i_stream_seek(stream, offset); - i_stream_seek(rstream->input, offset); + i_stream_seek_mark(stream, offset); + i_stream_seek_mark(rstream->input, offset); if (check) (void)_read(&rstream->istream); diff -r 571336db01f4 -r e05a1af4bbc7 src/lib/istream-data.c --- a/src/lib/istream-data.c Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib/istream-data.c Fri Sep 30 23:10:38 2005 +0300 @@ -22,7 +22,8 @@ return -1; } -static void _seek(struct _istream *stream, uoff_t v_offset) +static void _seek(struct _istream *stream, uoff_t v_offset, + int mark __attr_unused__) { stream->skip = v_offset; stream->istream.v_offset = v_offset; diff -r 571336db01f4 -r e05a1af4bbc7 src/lib/istream-file.c --- a/src/lib/istream-file.c Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib/istream-file.c Fri Sep 30 23:10:38 2005 +0300 @@ -159,7 +159,8 @@ return ret; } -static void _seek(struct _istream *stream, uoff_t v_offset) +static void _seek(struct _istream *stream, uoff_t v_offset, + int mark __attr_unused__) { struct file_istream *fstream = (struct file_istream *) stream; diff -r 571336db01f4 -r e05a1af4bbc7 src/lib/istream-internal.h --- a/src/lib/istream-internal.h Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib/istream-internal.h Fri Sep 30 23:10:38 2005 +0300 @@ -12,7 +12,7 @@ /* methods: */ ssize_t (*read)(struct _istream *stream); - void (*seek)(struct _istream *stream, uoff_t v_offset); + void (*seek)(struct _istream *stream, uoff_t v_offset, int mark); void (*sync)(struct _istream *stream); const struct stat *(*stat)(struct _istream *stream); diff -r 571336db01f4 -r e05a1af4bbc7 src/lib/istream-limit.c --- a/src/lib/istream-limit.c Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib/istream-limit.c Fri Sep 30 23:10:38 2005 +0300 @@ -80,7 +80,8 @@ return ret; } -static void _seek(struct _istream *stream, uoff_t v_offset) +static void _seek(struct _istream *stream, uoff_t v_offset, + int mark __attr_unused__) { struct limit_istream *lstream = (struct limit_istream *) stream; diff -r 571336db01f4 -r e05a1af4bbc7 src/lib/istream-mmap.c --- a/src/lib/istream-mmap.c Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib/istream-mmap.c Fri Sep 30 23:10:38 2005 +0300 @@ -141,7 +141,8 @@ return stream->pos - stream->skip; } -static void _seek(struct _istream *stream, uoff_t v_offset) +static void _seek(struct _istream *stream, uoff_t v_offset, + int mark __attr_unused__) { struct mmap_istream *mstream = (struct mmap_istream *) stream; diff -r 571336db01f4 -r e05a1af4bbc7 src/lib/istream-seekable.c --- a/src/lib/istream-seekable.c Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib/istream-seekable.c Fri Sep 30 23:10:38 2005 +0300 @@ -255,7 +255,8 @@ return ret; } -static void _seek(struct _istream *stream, uoff_t v_offset) +static void _seek(struct _istream *stream, uoff_t v_offset, + int mark __attr_unused__) { stream->istream.stream_errno = 0; stream->istream.v_offset = v_offset; diff -r 571336db01f4 -r e05a1af4bbc7 src/lib/istream.c --- a/src/lib/istream.c Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib/istream.c Fri Sep 30 23:10:38 2005 +0300 @@ -72,7 +72,7 @@ if (stream->closed) return; - _stream->seek(_stream, stream->v_offset + count); + _stream->seek(_stream, stream->v_offset + count, FALSE); } void i_stream_seek(struct istream *stream, uoff_t v_offset) @@ -88,7 +88,18 @@ return; stream->eof = FALSE; - _stream->seek(_stream, v_offset); + _stream->seek(_stream, v_offset, FALSE); +} + +void i_stream_seek_mark(struct istream *stream, uoff_t v_offset) +{ + struct _istream *_stream = stream->real_stream; + + if (stream->closed) + return; + + stream->eof = FALSE; + _stream->seek(_stream, v_offset, TRUE); } void i_stream_sync(struct istream *stream) diff -r 571336db01f4 -r e05a1af4bbc7 src/lib/istream.h --- a/src/lib/istream.h Fri Sep 30 21:55:00 2005 +0300 +++ b/src/lib/istream.h Fri Sep 30 23:10:38 2005 +0300 @@ -52,6 +52,11 @@ /* Seek to specified position from beginning of file. Never fails, the next read tells if it was successful. This works only for files. */ void i_stream_seek(struct istream *stream, uoff_t v_offset); +/* Like i_stream_seek(), but also giving a hint that after reading some data + we could be seeking back to this mark or somewhere after it. If input + stream's implementation is slow in seeking backwards, it can use this hint + to cache some of the data in memory. */ +void i_stream_seek_mark(struct istream *stream, uoff_t v_offset); /* Returns struct stat, or NULL if error. As the underlying stream may not be a file, only some of the fields might be set, others would be zero. st_size is always set, and if it's not known, it's -1. */