From: Timo Sirainen Date: Tue, 21 Apr 2015 13:50:43 +0000 (+0300) Subject: lib-lda: Added lmtp-client to track timestamps when various events happen. X-Git-Tag: 2.2.17.rc1~186 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5072e5009f39991c849ac424467eda8e75a8a4f7;p=thirdparty%2Fdovecot%2Fcore.git lib-lda: Added lmtp-client to track timestamps when various events happen. --- diff --git a/src/lib-lda/lmtp-client.c b/src/lib-lda/lmtp-client.c index 2e236da3a0..b468406446 100644 --- a/src/lib-lda/lmtp-client.c +++ b/src/lib-lda/lmtp-client.c @@ -71,6 +71,7 @@ struct lmtp_client { unsigned int rcpt_next_send_idx; struct istream *data_input; unsigned char output_last; + struct lmtp_client_times times; unsigned int running:1; unsigned int xclient_sent:1; @@ -392,6 +393,8 @@ static int lmtp_client_send_data(struct lmtp_client *client) } o_stream_nsend(client->output, ".\r\n", 3); client->output_finished = TRUE; + io_loop_time_refresh(); + client->times.data_sent = ioloop_timeval; return 0; } @@ -507,6 +510,7 @@ static int lmtp_client_input_line(struct lmtp_client *client, const char *line) "451 4.5.0 Received invalid greeting: %s", line)); return -1; } + client->times.banner_received = ioloop_timeval; lmtp_client_send_handshake(client); client->input_state = LMTP_INPUT_STATE_LHLO; break; @@ -561,6 +565,7 @@ static int lmtp_client_input_line(struct lmtp_client *client, const char *line) return -1; } client->input_state++; + client->times.data_started = ioloop_timeval; if (client->data_header != NULL) o_stream_nsend_str(client->output, client->data_header); if (lmtp_client_send_data(client) < 0) @@ -662,6 +667,8 @@ static int lmtp_client_connect(struct lmtp_client *client) { i_assert(client->fd == -1); + client->times.connect_started = ioloop_timeval; + client->fd = net_connect_ip(&client->ip, client->port, NULL); if (client->fd == -1) { i_error("lmtp client: connect(%s, %u) failed: %m", @@ -879,3 +886,9 @@ void lmtp_client_set_data_output_callback(struct lmtp_client *client, client->data_output_callback = callback; client->data_output_context = context; } + +const struct lmtp_client_times * +lmtp_client_get_times(struct lmtp_client *client) +{ + return &client->times; +} diff --git a/src/lib-lda/lmtp-client.h b/src/lib-lda/lmtp-client.h index 3f4ace0736..e7c52c5af0 100644 --- a/src/lib-lda/lmtp-client.h +++ b/src/lib-lda/lmtp-client.h @@ -26,6 +26,13 @@ struct lmtp_recipient_params { const char *dsn_orcpt; }; +struct lmtp_client_times { + struct timeval connect_started; + struct timeval banner_received; + struct timeval data_started; + struct timeval data_sent; +}; + struct lmtp_client_settings { const char *my_hostname; /* The whole MAIL FROM line, including parameters */ @@ -93,5 +100,8 @@ const char *lmtp_client_state_to_string(struct lmtp_client *client); void lmtp_client_set_data_output_callback(struct lmtp_client *client, void (*callback)(void *), void *context); +/* Return LMTP client statistics. */ +const struct lmtp_client_times * +lmtp_client_get_times(struct lmtp_client *client); #endif