dovecot-2.2: lib: Added io_stream_get_disconnect_reason() to ios...

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 24 09:11:10 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/ca2f5d3575b3
changeset: 18989:ca2f5d3575b3
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 24 12:10:08 2015 +0300
description:
lib: Added io_stream_get_disconnect_reason() to iostream.h

diffstat:

 src/lib/Makefile.am        |   1 +
 src/lib/iostream-private.h |   2 ++
 src/lib/iostream.c         |  24 ++++++++++++++++++++++++
 src/lib/iostream.h         |   8 ++++++++
 4 files changed, 35 insertions(+), 0 deletions(-)

diffs (73 lines):

diff -r 984ce015e9d0 -r ca2f5d3575b3 src/lib/Makefile.am
--- a/src/lib/Makefile.am	Mon Aug 24 12:04:55 2015 +0300
+++ b/src/lib/Makefile.am	Mon Aug 24 12:10:08 2015 +0300
@@ -193,6 +193,7 @@
 	hostpid.h \
 	imem.h \
 	ipwd.h \
+	iostream.h \
 	iostream-private.h \
 	iostream-rawlog.h \
 	iostream-rawlog-private.h \
diff -r 984ce015e9d0 -r ca2f5d3575b3 src/lib/iostream-private.h
--- a/src/lib/iostream-private.h	Mon Aug 24 12:04:55 2015 +0300
+++ b/src/lib/iostream-private.h	Mon Aug 24 12:10:08 2015 +0300
@@ -1,6 +1,8 @@
 #ifndef IOSTREAM_PRIVATE_H
 #define IOSTREAM_PRIVATE_H
 
+#include "iostream.h"
+
 /* This file is private to input stream and output stream implementations */
 
 struct iostream_destroy_callback {
diff -r 984ce015e9d0 -r ca2f5d3575b3 src/lib/iostream.c
--- a/src/lib/iostream.c	Mon Aug 24 12:04:55 2015 +0300
+++ b/src/lib/iostream.c	Mon Aug 24 12:10:08 2015 +0300
@@ -2,6 +2,8 @@
 
 #include "lib.h"
 #include "array.h"
+#include "istream.h"
+#include "ostream.h"
 #include "iostream-private.h"
 
 static void
@@ -106,3 +108,25 @@
 	i_free(stream->error);
 	stream->error = i_strdup_vprintf(fmt, args);
 }
+
+const char *io_stream_get_disconnect_reason(struct istream *input,
+					    struct ostream *output)
+{
+	const char *errstr;
+
+	if (input != NULL && input->stream_errno != 0) {
+		errno = input->stream_errno;
+		errstr = i_stream_get_error(input);
+	} else if (output != NULL && output->stream_errno != 0) {
+		errno = output->stream_errno;
+		errstr = o_stream_get_error(output);
+	} else {
+		errno = 0;
+		errstr = "";
+	}
+
+	if (errno == 0 || errno == EPIPE)
+		return "Connection closed";
+	else
+		return t_strdup_printf("Connection closed: %s", errstr);
+}
diff -r 984ce015e9d0 -r ca2f5d3575b3 src/lib/iostream.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/iostream.h	Mon Aug 24 12:10:08 2015 +0300
@@ -0,0 +1,8 @@
+#ifndef IOSTREAM_H
+#define IOSTREAM_H
+
+/* Returns human-readable reason for why iostream was disconnected. */
+const char *io_stream_get_disconnect_reason(struct istream *input,
+					    struct ostream *output);
+
+#endif


More information about the dovecot-cvs mailing list