changeset 18988:984ce015e9d0

lib: connection_disconnect_reason() now returns the full iostream error string.
author Timo Sirainen <tss@iki.fi>
date Mon, 24 Aug 2015 12:04:55 +0300
parents 9f815e781beb
children ca2f5d3575b3
files src/lib/connection.c
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/connection.c	Thu Aug 20 16:04:48 2015 +0300
+++ b/src/lib/connection.c	Mon Aug 24 12:04:55 2015 +0300
@@ -358,15 +358,23 @@
 
 const char *connection_disconnect_reason(struct connection *conn)
 {
-	if (conn->input != NULL && conn->input->stream_errno != 0)
+	const char *errstr;
+
+	if (conn->input != NULL && conn->input->stream_errno != 0) {
 		errno = conn->input->stream_errno;
-	else if (conn->output != NULL && conn->output->stream_errno != 0)
+		errstr = i_stream_get_error(conn->input);
+	} else if (conn->output != NULL && conn->output->stream_errno != 0) {
 		errno = conn->output->stream_errno;
+		errstr = o_stream_get_error(conn->output);
+	} else {
+		errno = 0;
+		errstr = "";
+	}
+
+	if (errno == 0 || errno == EPIPE)
+		return "Connection closed";
 	else
-		errno = 0;
-
-	return errno == 0 || errno == EPIPE ? "Connection closed" :
-		t_strdup_printf("Connection closed: %m");
+		return t_strdup_printf("Connection closed: %s", errstr);
 }
 
 void connection_switch_ioloop(struct connection *conn)