]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lda: Added lmtp-client to track timestamps when various events happen.
authorTimo Sirainen <tss@iki.fi>
Tue, 21 Apr 2015 13:50:43 +0000 (16:50 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 21 Apr 2015 13:50:43 +0000 (16:50 +0300)
src/lib-lda/lmtp-client.c
src/lib-lda/lmtp-client.h

index 2e236da3a043bb64984a41cdecc71c8f66de5f0a..b468406446fcb22c48d97d59666739a5284f6ebe 100644 (file)
@@ -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;
+}
index 3f4ace07362bd8e62a516dda0a7c4c2008c8b92e..e7c52c5af0bb402b756c600b7e6d54354c7ba273 100644 (file)
@@ -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