#include "stats-plugin.h"
#include "mail-stats-connection.h"
-void mail_stats_connection_connect(struct stats_connection *conn,
- struct mail_user *user)
+int mail_stats_connection_connect(struct stats_connection *conn,
+ struct mail_user *user)
{
struct stats_user *suser = STATS_USER_CONTEXT(user);
string_t *str = t_str_new(128);
str_append(str, net_ip2addr(user->remote_ip));
}
str_append_c(str, '\n');
- stats_connection_send(conn, str);
+ return stats_connection_send(conn, str);
}
void mail_stats_connection_disconnect(struct stats_connection *conn,
str_append(str, "DISCONNECT\t");
str_append(str, suser->stats_session_id);
str_append_c(str, '\n');
- stats_connection_send(conn, str);
+ if (stats_connection_send(conn, str) < 0) {
+ /* we could retry this later, but stats process will forget it
+ anyway after 15 minutes. */
+ }
}
void mail_stats_connection_send_session(struct stats_connection *conn,
base64_encode(buf->data, buf->used, str);
str_append_c(str, '\n');
- stats_connection_send(conn, str);
+ (void)stats_connection_send(conn, str);
}
struct mail_stats;
struct mail_user;
-void mail_stats_connection_connect(struct stats_connection *conn,
- struct mail_user *user);
+int mail_stats_connection_connect(struct stats_connection *conn,
+ struct mail_user *user);
void mail_stats_connection_disconnect(struct stats_connection *conn,
struct mail_user *user);
time_t now = time(NULL);
bool changed;
- if (session_stats_need_send(suser, now, &changed, &to_next_secs)) {
+ if (!suser->stats_connected) {
+ if (mail_stats_connection_connect(suser->stats_conn, user) == 0)
+ suser->stats_connected = TRUE;
+ }
+ if (session_stats_need_send(suser, now, &changed, &to_next_secs) &&
+ suser->stats_connected) {
suser->session_sent_duplicate = !changed;
suser->last_session_update = now;
stats_copy(suser->last_sent_session_stats, suser->session_stats);
stats_io_deactivate, user);
/* send final stats before disconnection */
session_stats_refresh(user);
- mail_stats_connection_disconnect(stats_conn, user);
+ if (suser->stats_connected)
+ mail_stats_connection_disconnect(stats_conn, user);
if (suser->to_stats_timeout != NULL)
timeout_remove(&suser->to_stats_timeout);
suser->last_sent_session_stats = stats_alloc(user->pool);
MODULE_CONTEXT_SET(user, stats_user_module, suser);
- mail_stats_connection_connect(suser->stats_conn, user);
+ if (mail_stats_connection_connect(suser->stats_conn, user) == 0)
+ suser->stats_connected = TRUE;
suser->to_stats_timeout =
timeout_add(suser->refresh_secs*1000,
session_stats_refresh_timeout, user);
struct ioloop_context *ioloop_ctx;
struct stats_connection *stats_conn;
const char *stats_session_id;
+ bool stats_connected;
unsigned int refresh_secs;
bool track_commands;