[dovecot-cvs] dovecot/src/lib istream-file.c,1.1,1.2 network.c,1.12,1.13 network.h,1.6,1.7 randgen.c,1.4,1.5

cras at procontrol.fi cras at procontrol.fi
Thu Dec 12 20:57:49 EET 2002


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv31337/src/lib

Modified Files:
	istream-file.c network.c network.h randgen.c 
Log Message:
net_receive, net_transmit: Return -2 for regular disconnection errors. Don't
log those errors. Some other cleanups.



Index: istream-file.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/istream-file.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- istream-file.c	6 Dec 2002 01:09:22 -0000	1.1
+++ istream-file.c	12 Dec 2002 18:57:47 -0000	1.2
@@ -199,6 +199,12 @@
 		}
 
 		if (ret < 0) {
+			if (errno == ECONNRESET || errno == ETIMEDOUT) {
+				/* treat as disconnection */
+				stream->istream.stream_errno = 0;
+				return -1;
+			}
+
 			if (errno == EINTR || errno == EAGAIN)
 				ret = 0;
 			else {

Index: network.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/network.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- network.c	12 Dec 2002 18:33:32 -0000	1.12
+++ network.c	12 Dec 2002 18:57:47 -0000	1.13
@@ -378,11 +378,21 @@
 	i_assert(len <= SSIZE_T_MAX);
 
 	ret = recv(fd, buf, len, 0);
-	if (ret == 0)
-		return -1; /* disconnected */
+	if (ret == 0) {
+		/* disconnected */
+		errno = 0;
+		return -2;
+	}
 
-	if (ret < 0 && (errno == EINTR || errno == EAGAIN))
-                return 0;
+	if (ret < 0) {
+		if (errno == EINTR || errno == EAGAIN)
+			return 0;
+
+		if (errno == ECONNRESET || errno == ETIMEDOUT) {
+                        /* treat as disconnection */
+			return -2;
+		}
+	}
 
 	return ret;
 }
@@ -397,8 +407,11 @@
 	i_assert(len <= SSIZE_T_MAX);
 
 	ret = send(fd, data, len, 0);
-	if (ret == -1 && (errno == EINTR || errno == EPIPE || errno == EAGAIN))
-                return 0;
+	if (ret == -1 && (errno == EINTR || errno == EAGAIN))
+		return 0;
+
+	if (errno == EPIPE)
+		return -2;
 
         return ret;
 }

Index: network.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/network.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- network.h	12 Dec 2002 18:33:32 -0000	1.6
+++ network.h	12 Dec 2002 18:57:47 -0000	1.7
@@ -71,9 +71,10 @@
    -2 for fatal failure */
 int net_accept(int fd, IPADDR *addr, unsigned int *port);
 
-/* Read data from socket, return number of bytes read, -1 = error */
+/* Read data from socket, return number of bytes read,
+   -1 = error, -2 = disconnected */
 ssize_t net_receive(int fd, void *buf, size_t len);
-/* Transmit data, return number of bytes sent, -1 = error */
+/* Transmit data, return number of bytes sent, -1 = error, -2 = disconnected */
 ssize_t net_transmit(int fd, const void *data, size_t len);
 
 /* Get IP addresses for host. ips contains ips_count of IPs, they don't need

Index: randgen.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/randgen.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- randgen.c	1 Dec 2002 15:58:36 -0000	1.4
+++ randgen.c	12 Dec 2002 18:57:47 -0000	1.5
@@ -43,7 +43,7 @@
 
 	for (pos = 0; pos < size; pos += ret) {
 		ret = read(urandom_fd, (char *) buf + pos, size - pos);
-		if (ret < 0)
+		if (ret < 0 && errno != EINTR)
 			i_fatal("Error reading from /dev/urandom: %m");
 	}
 }




More information about the dovecot-cvs mailing list