[dovecot-cvs] dovecot/src/lib istream-data.c, 1.16, 1.17 istream-file.c, 1.29, 1.30 istream-internal.h, 1.11, 1.12 istream-mmap.c, 1.21, 1.22 istream.c, 1.36, 1.37
tss at dovecot.org
tss at dovecot.org
Sat Mar 31 11:32:35 EEST 2007
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv13974
Modified Files:
istream-data.c istream-file.c istream-internal.h
istream-mmap.c istream.c
Log Message:
If istream implementation doesn't set set_max_buffer_size() or stat(),
implement them ourself. Moved some generic code to istream.
Index: istream-data.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-data.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- istream-data.c 6 Feb 2007 10:40:16 -0000 1.16
+++ istream-data.c 31 Mar 2007 08:32:32 -0000 1.17
@@ -11,11 +11,6 @@
{
}
-static void _set_max_buffer_size(struct _iostream *stream __attr_unused__,
- size_t max_size __attr_unused__)
-{
-}
-
static ssize_t _read(struct _istream *stream __attr_unused__)
{
stream->istream.eof = TRUE;
@@ -29,13 +24,6 @@
stream->istream.v_offset = v_offset;
}
-static const struct stat *
-_stat(struct _istream *stream, bool exact __attr_unused__)
-{
- stream->statbuf.st_size = stream->pos;
- return &stream->statbuf;
-}
-
struct istream *i_stream_create_from_data(pool_t pool, const void *data,
size_t size)
{
@@ -47,11 +35,10 @@
stream->iostream.close = _close;
stream->iostream.destroy = _destroy;
- stream->iostream.set_max_buffer_size = _set_max_buffer_size;
+ stream->statbuf.st_size = size;
stream->read = _read;
stream->seek = _seek;
- stream->stat = _stat;
stream->istream.blocking = TRUE;
stream->istream.seekable = TRUE;
Index: istream-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-file.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- istream-file.c 7 Mar 2007 14:51:04 -0000 1.29
+++ istream-file.c 31 Mar 2007 08:32:32 -0000 1.30
@@ -16,7 +16,6 @@
struct file_istream {
struct _istream istream;
- size_t max_buffer_size;
uoff_t skip_left;
unsigned int file:1;
@@ -42,38 +41,6 @@
p_free(_stream->iostream.pool, _stream->w_buffer);
}
-static void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
-{
- struct file_istream *fstream = (struct file_istream *) stream;
-
- fstream->max_buffer_size = max_size;
-}
-
-static void i_stream_grow_buffer(struct _istream *stream, size_t bytes)
-{
- struct file_istream *fstream = (struct file_istream *) stream;
- size_t old_size;
-
- old_size = stream->buffer_size;
-
- stream->buffer_size = stream->pos + bytes;
- if (stream->buffer_size <= I_STREAM_MIN_SIZE)
- stream->buffer_size = I_STREAM_MIN_SIZE;
- else {
- stream->buffer_size =
- pool_get_exp_grown_size(stream->iostream.pool,
- old_size, stream->buffer_size);
- }
-
- if (fstream->max_buffer_size > 0 &&
- stream->buffer_size > fstream->max_buffer_size)
- stream->buffer_size = fstream->max_buffer_size;
-
- stream->buffer = stream->w_buffer =
- p_realloc(stream->iostream.pool, stream->w_buffer,
- old_size, stream->buffer_size);
-}
-
static void i_stream_compress(struct _istream *stream)
{
memmove(stream->w_buffer, stream->w_buffer + stream->skip,
@@ -98,10 +65,10 @@
if (stream->skip > 0) {
/* remove the unused bytes from beginning of buffer */
i_stream_compress(stream);
- } else if (fstream->max_buffer_size == 0 ||
- stream->buffer_size < fstream->max_buffer_size) {
+ } else if (stream->max_buffer_size == 0 ||
+ stream->buffer_size < stream->max_buffer_size) {
/* buffer is full - grow it */
- i_stream_grow_buffer(stream, I_STREAM_MIN_SIZE);
+ _i_stream_grow_buffer(stream, I_STREAM_MIN_SIZE);
}
if (stream->pos == stream->buffer_size)
@@ -210,13 +177,12 @@
struct stat st;
fstream = p_new(pool, struct file_istream, 1);
- fstream->max_buffer_size = max_buffer_size;
fstream->autoclose_fd = autoclose_fd;
fstream->istream.iostream.close = _close;
fstream->istream.iostream.destroy = _destroy;
- fstream->istream.iostream.set_max_buffer_size = _set_max_buffer_size;
+ fstream->istream.max_buffer_size = max_buffer_size;
fstream->istream.read = _read;
fstream->istream.seek = _seek;
fstream->istream.sync = _sync;
Index: istream-internal.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-internal.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- istream-internal.h 30 May 2006 13:36:07 -0000 1.11
+++ istream-internal.h 31 Mar 2007 08:32:32 -0000 1.12
@@ -18,17 +18,21 @@
struct istream istream;
int fd;
- const unsigned char *buffer;
- unsigned char *w_buffer; /* may be NULL */
- string_t *line_str; /* for i_stream_next_line() if w_buffer == NULL */
- size_t buffer_size;
uoff_t abs_start_offset;
struct stat statbuf;
+ const unsigned char *buffer;
+ unsigned char *w_buffer; /* may be NULL */
+
+ size_t buffer_size, max_buffer_size;
size_t skip, pos;
+
+ string_t *line_str; /* for i_stream_next_line() if w_buffer == NULL */
};
struct istream *_i_stream_create(struct _istream *_buf, pool_t pool, int fd,
uoff_t abs_start_offset);
+void _i_stream_grow_buffer(struct _istream *stream, size_t bytes);
+
#endif
Index: istream-mmap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-mmap.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- istream-mmap.c 6 Feb 2007 10:40:16 -0000 1.21
+++ istream-mmap.c 31 Mar 2007 08:32:32 -0000 1.22
@@ -15,7 +15,6 @@
void *mmap_base;
off_t mmap_offset;
- size_t mmap_block_size;
uoff_t v_size;
unsigned int autoclose_fd:1;
@@ -55,20 +54,10 @@
i_stream_munmap(mstream);
}
-static void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
+static size_t mstream_get_mmap_block_size(struct _istream *stream)
{
- struct mmap_istream *mstream = (struct mmap_istream *) stream;
-
- /* allow only full page sizes */
- if (max_size < mmap_get_page_size())
- mstream->mmap_block_size = mmap_get_page_size();
- else {
- if (max_size % mmap_get_page_size() != 0) {
- max_size += mmap_get_page_size() -
- (max_size % mmap_get_page_size());
- }
- mstream->mmap_block_size = max_size;
- }
+ return (stream->max_buffer_size + mmap_get_page_size() - 1) & ~
+ (mmap_get_page_size() - 1);
}
static ssize_t _read(struct _istream *stream)
@@ -105,7 +94,7 @@
}
top = mstream->v_size - mstream->mmap_offset;
- stream->buffer_size = I_MIN(top, mstream->mmap_block_size);
+ stream->buffer_size = I_MIN(top, mstream_get_mmap_block_size(stream));
i_assert((uoff_t)mstream->mmap_offset + stream->buffer_size <=
mstream->v_size);
@@ -219,14 +208,13 @@
}
mstream = p_new(pool, struct mmap_istream, 1);
- _set_max_buffer_size(&mstream->istream.iostream, block_size);
mstream->autoclose_fd = autoclose_fd;
mstream->v_size = v_size;
mstream->istream.iostream.close = _close;
mstream->istream.iostream.destroy = _destroy;
- mstream->istream.iostream.set_max_buffer_size = _set_max_buffer_size;
+ mstream->istream.max_buffer_size = block_size;
mstream->istream.read = _read;
mstream->istream.seek = _seek;
mstream->istream.sync = _sync;
Index: istream.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- istream.c 6 Feb 2007 10:40:16 -0000 1.36
+++ istream.c 31 Mar 2007 08:32:32 -0000 1.37
@@ -5,6 +5,8 @@
#include "str.h"
#include "istream-internal.h"
+#define I_STREAM_MIN_SIZE 512
+
void i_stream_destroy(struct istream **stream)
{
i_stream_close(*stream);
@@ -263,6 +265,43 @@
return -1;
}
+void _i_stream_grow_buffer(struct _istream *stream, size_t bytes)
+{
+ size_t old_size;
+
+ old_size = stream->buffer_size;
+
+ stream->buffer_size = stream->pos + bytes;
+ if (stream->buffer_size <= I_STREAM_MIN_SIZE)
+ stream->buffer_size = I_STREAM_MIN_SIZE;
+ else {
+ stream->buffer_size =
+ pool_get_exp_grown_size(stream->iostream.pool,
+ old_size, stream->buffer_size);
+ }
+
+ if (stream->max_buffer_size > 0 &&
+ stream->buffer_size > stream->max_buffer_size)
+ stream->buffer_size = stream->max_buffer_size;
+
+ stream->buffer = stream->w_buffer =
+ p_realloc(stream->iostream.pool, stream->w_buffer,
+ old_size, stream->buffer_size);
+}
+
+static void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
+{
+ struct _istream *_stream = (struct _istream *) stream;
+
+ _stream->max_buffer_size = max_size;
+}
+
+static const struct stat *
+_stat(struct _istream *stream, bool exact __attr_unused__)
+{
+ return &stream->statbuf;
+}
+
struct istream *_i_stream_create(struct _istream *_stream, pool_t pool, int fd,
uoff_t abs_start_offset)
{
@@ -270,6 +309,11 @@
_stream->abs_start_offset = abs_start_offset;
_stream->istream.real_stream = _stream;
+ if (_stream->stat == NULL)
+ _stream->stat = _stat;
+ if (_stream->iostream.set_max_buffer_size == NULL)
+ _stream->iostream.set_max_buffer_size = _set_max_buffer_size;
+
memset(&_stream->statbuf, 0, sizeof(_stream->statbuf));
_stream->statbuf.st_size = -1;
_stream->statbuf.st_atime =
More information about the dovecot-cvs
mailing list