dovecot-2.2: Use io_stream_get_disconnect_reason() instead of du...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Aug 24 09:15:33 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/cd2c95d82d4c
changeset: 18990:cd2c95d82d4c
user: Timo Sirainen <tss at iki.fi>
date: Mon Aug 24 12:14:40 2015 +0300
description:
Use io_stream_get_disconnect_reason() instead of duplicating its code all over the place.
diffstat:
src/imap/imap-client.c | 20 +++++---------------
src/lib/connection.c | 19 ++-----------------
src/lmtp/client.c | 12 +++---------
src/login-common/client-common-auth.c | 10 ++--------
src/pop3/pop3-client.c | 19 +++++--------------
5 files changed, 17 insertions(+), 63 deletions(-)
diffs (187 lines):
diff -r ca2f5d3575b3 -r cd2c95d82d4c src/imap/imap-client.c
--- a/src/imap/imap-client.c Mon Aug 24 12:10:08 2015 +0300
+++ b/src/imap/imap-client.c Mon Aug 24 12:14:40 2015 +0300
@@ -6,6 +6,7 @@
#include "str.h"
#include "hostpid.h"
#include "net.h"
+#include "iostream.h"
#include "istream.h"
#include "ostream.h"
#include "time-util.h"
@@ -248,19 +249,6 @@
return str_c(str);
}
-static const char *client_get_disconnect_reason(struct client *client)
-{
- errno = client->input->stream_errno != 0 ?
- client->input->stream_errno :
- client->output->stream_errno;
- if (errno == 0 || errno == EPIPE)
- return "Connection closed";
- return t_strdup_printf("Connection closed: %s",
- client->input->stream_errno != 0 ?
- i_stream_get_error(client->input) :
- o_stream_get_error(client->output));
-}
-
void client_destroy(struct client *client, const char *reason)
{
client->v.destroy(client, reason);
@@ -275,8 +263,10 @@
if (!client->disconnected) {
client->disconnected = TRUE;
- if (reason == NULL)
- reason = client_get_disconnect_reason(client);
+ if (reason == NULL) {
+ reason = io_stream_get_disconnect_reason(client->input,
+ client->output);
+ }
i_info("%s %s", reason, client_stats(client));
}
diff -r ca2f5d3575b3 -r cd2c95d82d4c src/lib/connection.c
--- a/src/lib/connection.c Mon Aug 24 12:10:08 2015 +0300
+++ b/src/lib/connection.c Mon Aug 24 12:14:40 2015 +0300
@@ -4,6 +4,7 @@
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
+#include "iostream.h"
#include "net.h"
#include "strescape.h"
#include "llist.h"
@@ -358,23 +359,7 @@
const char *connection_disconnect_reason(struct connection *conn)
{
- const char *errstr;
-
- if (conn->input != NULL && conn->input->stream_errno != 0) {
- errno = conn->input->stream_errno;
- 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
- return t_strdup_printf("Connection closed: %s", errstr);
+ return io_stream_get_disconnect_reason(conn->input, conn->output);
}
void connection_switch_ioloop(struct connection *conn)
diff -r ca2f5d3575b3 -r cd2c95d82d4c src/lmtp/client.c
--- a/src/lmtp/client.c Mon Aug 24 12:10:08 2015 +0300
+++ b/src/lmtp/client.c Mon Aug 24 12:14:40 2015 +0300
@@ -5,6 +5,7 @@
#include "base64.h"
#include "str.h"
#include "llist.h"
+#include "iostream.h"
#include "istream.h"
#include "ostream.h"
#include "hostpid.h"
@@ -323,16 +324,9 @@
err);
}
}
- errno = client->input->stream_errno != 0 ?
- client->input->stream_errno :
- client->output->stream_errno;
- if (errno == 0 || errno == EPIPE)
- return "Connection closed";
- return t_strdup_printf("Connection closed: %s",
- client->input->stream_errno != 0 ?
- i_stream_get_error(client->input) :
- o_stream_get_error(client->output));
+ return io_stream_get_disconnect_reason(client->input, client->output);
}
+
void client_disconnect(struct client *client, const char *prefix,
const char *reason)
{
diff -r ca2f5d3575b3 -r cd2c95d82d4c src/login-common/client-common-auth.c
--- a/src/login-common/client-common-auth.c Mon Aug 24 12:10:08 2015 +0300
+++ b/src/login-common/client-common-auth.c Mon Aug 24 12:14:40 2015 +0300
@@ -2,6 +2,7 @@
#include "hostpid.h"
#include "login-common.h"
+#include "iostream.h"
#include "istream.h"
#include "ostream.h"
#include "str.h"
@@ -216,13 +217,6 @@
client_auth_failed(client);
}
-static const char *get_disconnect_reason(struct istream *input)
-{
- errno = input->stream_errno;
- return errno == 0 || errno == EPIPE ? "Connection closed" :
- t_strdup_printf("Connection closed: %m");
-}
-
static void proxy_input(struct client *client)
{
struct istream *input;
@@ -262,7 +256,7 @@
"(state=%u, duration=%us)%s",
login_proxy_get_host(client->login_proxy),
login_proxy_get_port(client->login_proxy),
- get_disconnect_reason(input),
+ io_stream_get_disconnect_reason(input, NULL),
client->proxy_state, duration,
line == NULL ? "" : t_strdup_printf(
" - BUG: line not read: %s", line)));
diff -r ca2f5d3575b3 -r cd2c95d82d4c src/pop3/pop3-client.c
--- a/src/pop3/pop3-client.c Mon Aug 24 12:10:08 2015 +0300
+++ b/src/pop3/pop3-client.c Mon Aug 24 12:14:40 2015 +0300
@@ -4,6 +4,7 @@
#include "array.h"
#include "ioloop.h"
#include "net.h"
+#include "iostream.h"
#include "istream.h"
#include "ostream.h"
#include "crc32.h"
@@ -556,18 +557,6 @@
return str_c(str);
}
-static const char *client_get_disconnect_reason(struct client *client)
-{
- errno = client->input->stream_errno != 0 ?
- client->input->stream_errno :
- client->output->stream_errno;
- if (errno == 0 || errno == EPIPE)
- return "Connection closed";
- return t_strdup_printf("Connection closed: %s",
- client->input->stream_errno != 0 ?
- i_stream_get_error(client->input) :
- o_stream_get_error(client->output));
-}
void client_destroy(struct client *client, const char *reason)
{
client->v.destroy(client, reason);
@@ -579,8 +568,10 @@
(void)client_update_mails(client);
if (!client->disconnected) {
- if (reason == NULL)
- reason = client_get_disconnect_reason(client);
+ if (reason == NULL) {
+ reason = io_stream_get_disconnect_reason(client->input,
+ client->output);
+ }
i_info("%s %s", reason, client_stats(client));
}
More information about the dovecot-cvs
mailing list