Mercurial > dovecot > core-2.2
changeset 20625:3faece727565
lib: Added connection_input_timeout_reason()
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Wed, 10 Aug 2016 17:54:29 +0300 |
parents | cf6b671fc3e8 |
children | 9df9bdd84ab1 |
files | src/lib/connection.c src/lib/connection.h |
diffstat | 2 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/connection.c Wed Aug 10 17:44:26 2016 +0300 +++ b/src/lib/connection.c Wed Aug 10 17:54:29 2016 +0300 @@ -8,6 +8,7 @@ #include "net.h" #include "strescape.h" #include "llist.h" +#include "time-util.h" #include "connection.h" #include <unistd.h> @@ -386,6 +387,24 @@ i_unreached(); } +const char *connection_input_timeout_reason(struct connection *conn) +{ + if (conn->last_input_tv.tv_sec != 0) { + int diff = timeval_diff_msecs(&ioloop_timeval, &conn->last_input_tv); + return t_strdup_printf("No input for %u.%03u secs", + diff/1000, diff%1000); + } else if (conn->connect_finished.tv_sec != 0) { + int diff = timeval_diff_msecs(&ioloop_timeval, &conn->connect_finished); + return t_strdup_printf( + "No input since connected %u.%03u secs ago", + diff/1000, diff%1000); + } else { + int diff = timeval_diff_msecs(&ioloop_timeval, &conn->connect_started); + return t_strdup_printf("connect() timed out after %u.%03u secs", + diff/1000, diff%1000); + } +} + void connection_switch_ioloop(struct connection *conn) { if (conn->io != NULL)
--- a/src/lib/connection.h Wed Aug 10 17:44:26 2016 +0300 +++ b/src/lib/connection.h Wed Aug 10 17:54:29 2016 +0300 @@ -129,6 +129,9 @@ /* Returns human-readable reason for why connection was disconnected. */ const char *connection_disconnect_reason(struct connection *conn); +/* Returns human-readable reason for why connection timed out, + e.g. "No input for 10.023 secs". */ +const char *connection_input_timeout_reason(struct connection *conn); void connection_switch_ioloop(struct connection *conn);