[dovecot-cvs] dovecot/src/plugins/zlib istream-zlib.c,1.2,1.3

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


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

Modified Files:
	istream-zlib.c 
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-zlib.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/zlib/istream-zlib.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- istream-zlib.c	13 Jan 2006 20:26:48 -0000	1.2
+++ istream-zlib.c	6 Feb 2007 10:40:18 -0000	1.3
@@ -124,7 +124,11 @@
 
 	i_assert(zstream->seek_offset == stream->istream.v_offset +
 		 (stream->pos - stream->skip));
-	ret = gzread(zstream->file, stream->w_buffer + stream->pos, size);
+	do {
+	       ret = gzread(zstream->file, stream->w_buffer + stream->pos,
+			    size);
+	} while (ret < 0 && errno == EINTR && stream->istream.blocking);
+
 	if (ret == 0) {
 		/* EOF */
 		stream->istream.eof = TRUE;
@@ -132,9 +136,10 @@
 	}
 
 	if (ret < 0) {
-		if (errno == EINTR || errno == EAGAIN)
+		if (errno == EAGAIN) {
+			i_assert(!stream->istream.blocking);
 			ret = 0;
-		else {
+		} else {
 			stream->istream.eof = TRUE;
 			stream->istream.stream_errno = errno;
 			return -1;
@@ -236,6 +241,7 @@
 struct istream *i_stream_create_zlib(int fd, pool_t pool)
 {
 	struct zlib_istream *zstream;
+	struct stat st;
 
 	zstream = p_new(pool, struct zlib_istream, 1);
 	zstream->fd = fd;
@@ -252,6 +258,11 @@
 	zstream->istream.stat = _stat;
 	zstream->istream.sync = _sync;
 
-	zstream->istream.istream.seekable = TRUE;
+	/* if it's a file, set the flags properly */
+	if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
+		zstream->istream.istream.blocking = TRUE;
+		zstream->istream.istream.seekable = TRUE;
+	}
+
 	return _i_stream_create(&zstream->istream, pool, fd, 0);
 }



More information about the dovecot-cvs mailing list