From: Timo Sirainen Date: Tue, 2 Mar 2021 13:07:56 +0000 (+0200) Subject: lib: Add o_stream_get_disconnect_reason() X-Git-Tag: 2.3.15~263 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a0a04a86fcff7be2374e2dcaa14211ed1dbaf843;p=thirdparty%2Fdovecot%2Fcore.git lib: Add o_stream_get_disconnect_reason() --- diff --git a/src/lib/ostream.c b/src/lib/ostream.c index 8c1394b9bd..acfa527d1f 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -43,6 +43,11 @@ const char *o_stream_get_error(struct ostream *stream) return strerror(stream->stream_errno); } +const char *o_stream_get_disconnect_reason(struct ostream *stream) +{ + return io_stream_get_disconnect_reason(NULL, stream); +} + static void o_stream_close_full(struct ostream *stream, bool close_parents) { /* Ideally o_stream_finish() would be called for all non-failed diff --git a/src/lib/ostream.h b/src/lib/ostream.h index a43e8043ad..2063847ca0 100644 --- a/src/lib/ostream.h +++ b/src/lib/ostream.h @@ -94,6 +94,12 @@ const char *o_stream_get_name(struct ostream *stream); int o_stream_get_fd(struct ostream *stream); /* Returns error string for the previous error. */ const char *o_stream_get_error(struct ostream *stream); +/* Returns human-readable reason for why ostream was disconnected. + The output is either "Connection closed" for clean disconnections or + "Connection closed: " for unclean disconnections. This is an + alternative to o_stream_get_error(), which is preferred to be used when + logging errors about client connections. */ +const char *o_stream_get_disconnect_reason(struct ostream *stream); /* Close this stream (but not its parents) and unreference it. */ void o_stream_destroy(struct ostream **stream);