[dovecot-cvs] dovecot/src/lib istream-data.c, 1.15, 1.16 istream-file.c, 1.27, 1.28 istream-limit.c, 1.18, 1.19 istream-mmap.c, 1.20, 1.21 istream.c, 1.35, 1.36 istream.h, 1.26, 1.27

tss at dovecot.org tss at dovecot.org
Tue Feb 6 10:40:21 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv19479/lib

Modified Files:
	istream-data.c istream-file.c istream-limit.c istream-mmap.c 
	istream.c istream.h 
Log Message:
Added istream->blocking setting. It's now used to assert-crash early if a
blocking stream unexpectedly returns "need more data".



Index: istream-data.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-data.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- istream-data.c	13 Jan 2006 20:26:01 -0000	1.15
+++ istream-data.c	6 Feb 2007 10:40:16 -0000	1.16
@@ -53,6 +53,7 @@
 	stream->seek = _seek;
 	stream->stat = _stat;
 
+	stream->istream.blocking = TRUE;
 	stream->istream.seekable = TRUE;
 	return _i_stream_create(stream, pool, -1, 0);
 }

Index: istream-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-file.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- istream-file.c	7 Nov 2006 13:58:56 -0000	1.27
+++ istream-file.c	6 Feb 2007 10:40:16 -0000	1.28
@@ -114,15 +114,17 @@
 
 	ret = -1;
 
-	if (fstream->file) {
-		do {
+	do {
+		if (fstream->file) {
 			ret = pread(stream->fd, stream->w_buffer + stream->pos,
 				    size, stream->istream.v_offset +
 				    (stream->pos - stream->skip));
-		} while (ret < 0 && errno == EINTR);
-	} else {
-		ret = read(stream->fd, stream->w_buffer + stream->pos, size);
-	}
+		} else {
+			ret = read(stream->fd, stream->w_buffer + stream->pos,
+				   size);
+		}
+	} while (ret < 0 && errno == EINTR && stream->istream.blocking);
+
 	if (ret == 0) {
 		/* EOF */
 		stream->istream.eof = TRUE;
@@ -130,9 +132,10 @@
 	}
 
 	if (ret < 0) {
-		if (errno == EINTR || errno == EAGAIN)
+		if (errno == EINTR || errno == EAGAIN) {
+			i_assert(!stream->istream.blocking);
 			ret = 0;
-		else {
+		} else {
 			stream->istream.eof = TRUE;
 			stream->istream.stream_errno = errno;
 			return -1;
@@ -238,9 +241,10 @@
 	fstream->istream.sync = _sync;
 	fstream->istream.stat = _stat;
 
-	/* get size of fd if it's a file */
+	/* if it's a file, set the flags properly */
 	if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
 		fstream->file = TRUE;
+		fstream->istream.istream.blocking = TRUE;
 		fstream->istream.istream.seekable = TRUE;
 	}
 

Index: istream-limit.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-limit.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- istream-limit.c	14 Jan 2006 18:47:22 -0000	1.18
+++ istream-limit.c	6 Feb 2007 10:40:16 -0000	1.19
@@ -132,6 +132,7 @@
 	lstream->istream.seek = _seek;
 	lstream->istream.stat = _stat;
 
+	lstream->istream.istream.blocking = input->blocking;
 	lstream->istream.istream.seekable = input->seekable;
 	return _i_stream_create(&lstream->istream, pool, i_stream_get_fd(input),
 				input->real_stream->abs_start_offset +

Index: istream-mmap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream-mmap.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- istream-mmap.c	7 Nov 2006 13:58:56 -0000	1.20
+++ istream-mmap.c	6 Feb 2007 10:40:16 -0000	1.21
@@ -234,6 +234,7 @@
 
 	istream = _i_stream_create(&mstream->istream, pool, fd, start_offset);
 	istream->mmaped = TRUE;
+	istream->blocking = TRUE;
 	istream->seekable = TRUE;
 	return istream;
 }

Index: istream.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- istream.c	28 Jun 2006 13:10:33 -0000	1.35
+++ istream.c	6 Feb 2007 10:40:16 -0000	1.36
@@ -208,42 +208,42 @@
 	return line;
 }
 
-const unsigned char *i_stream_get_data(struct istream *stream, size_t *size)
+const unsigned char *i_stream_get_data(struct istream *stream, size_t *size_r)
 {
 	struct _istream *_stream = stream->real_stream;
 
 	if (_stream->skip >= _stream->pos) {
-		*size = 0;
+		*size_r = 0;
 		return NULL;
 	}
 
-        *size = _stream->pos - _stream->skip;
+        *size_r = _stream->pos - _stream->skip;
         return _stream->buffer + _stream->skip;
 }
 
 unsigned char *i_stream_get_modifiable_data(struct istream *stream,
-					    size_t *size)
+					    size_t *size_r)
 {
 	struct _istream *_stream = stream->real_stream;
 
 	if (_stream->skip >= _stream->pos || _stream->w_buffer == NULL) {
-		*size = 0;
+		*size_r = 0;
 		return NULL;
 	}
 
-        *size = _stream->pos - _stream->skip;
+        *size_r = _stream->pos - _stream->skip;
         return _stream->w_buffer + _stream->skip;
 }
 
-int i_stream_read_data(struct istream *stream, const unsigned char **data,
-		       size_t *size, size_t threshold)
+int i_stream_read_data(struct istream *stream, const unsigned char **data_r,
+		       size_t *size_r, size_t threshold)
 {
 	ssize_t ret = 0;
 	bool read_more = FALSE;
 
 	do {
-		*data = i_stream_get_data(stream, size);
-		if (*size > threshold)
+		*data_r = i_stream_get_data(stream, size_r);
+		if (*size_r > threshold)
 			return 1;
 
 		/* we need more data */
@@ -252,9 +252,15 @@
 			read_more = TRUE;
 	} while (ret > 0);
 
-	*data = i_stream_get_data(stream, size);
-	return ret == -2 ? -2 :
-		(read_more || ret == 0 ? 0 : -1);
+	*data_r = i_stream_get_data(stream, size_r);
+	if (ret == -2)
+		return -2;
+
+	if (read_more || ret == 0) {
+		i_assert(!stream->blocking || stream->eof);
+		return 0;
+	}
+	return -1;
 }
 
 struct istream *_i_stream_create(struct _istream *_stream, pool_t pool, int fd,

Index: istream.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- istream.h	28 Jun 2006 13:10:33 -0000	1.26
+++ istream.h	6 Feb 2007 10:40:16 -0000	1.27
@@ -9,6 +9,7 @@
 
 	int stream_errno;
 	unsigned int mmaped:1; /* be careful when copying data */
+	unsigned int blocking:1; /* read() shouldn't return 0 */
 	unsigned int closed:1;
 	unsigned int seekable:1; /* we can seek() backwards */
 	unsigned int eof:1; /* read() has reached to end of file
@@ -85,16 +86,16 @@
 
 /* Returns pointer to beginning of read data, or NULL if there's no data
    buffered. */
-const unsigned char *i_stream_get_data(struct istream *stream, size_t *size);
+const unsigned char *i_stream_get_data(struct istream *stream, size_t *size_r);
 /* Like i_stream_get_data(), but returns non-const data. This only works with
    buffered streams (currently only file), others return NULL. */
 unsigned char *i_stream_get_modifiable_data(struct istream *stream,
-					    size_t *size);
+					    size_t *size_r);
 /* Like i_stream_get_data(), but read more when needed. Returns 1 if more
    than threshold bytes are available, 0 if less, -1 if error or EOF with no
    bytes read that weren't already in buffer, or -2 if stream's input buffer
    is full. */
-int i_stream_read_data(struct istream *stream, const unsigned char **data,
-		       size_t *size, size_t threshold);
+int i_stream_read_data(struct istream *stream, const unsigned char **data_r,
+		       size_t *size_r, size_t threshold);
 
 #endif



More information about the dovecot-cvs mailing list