Skip to content

Commit

Permalink
lib-stats: stats_connection_send() now returns whether it succeeded o…
Browse files Browse the repository at this point in the history
…r not
  • Loading branch information
sirainen committed Sep 8, 2016
1 parent af2cc75 commit a94f190
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/lib-stats/stats-connection.c
Expand Up @@ -69,7 +69,7 @@ void stats_connection_unref(struct stats_connection **_conn)
i_free(conn);
}

void stats_connection_send(struct stats_connection *conn, const string_t *str)
int stats_connection_send(struct stats_connection *conn, const string_t *str)
{
static bool pipe_warned = FALSE;
ssize_t ret;
Expand All @@ -78,11 +78,11 @@ void stats_connection_send(struct stats_connection *conn, const string_t *str)
to notify the stats process anymore. even if one exists, it doesn't
know about us. */
if (master_service_is_master_stopped(master_service))
return;
return -1;

if (conn->fd == -1) {
if (!stats_connection_open(conn))
return;
return -1;
}

if (str_len(str) > PIPE_BUF && !pipe_warned) {
Expand All @@ -95,13 +95,15 @@ void stats_connection_send(struct stats_connection *conn, const string_t *str)
ret = write(conn->fd, str_data(str), str_len(str));
if (ret == (ssize_t)str_len(str)) {
/* success */
return 0;
} else if (ret < 0 && errno == EAGAIN) {
/* stats process is busy */
if (ioloop_time > conn->next_warning_timestamp) {
i_warning("write(%s) failed: %m (stats process is busy)", conn->path);
conn->next_warning_timestamp = ioloop_time +
STATS_EAGAIN_WARN_INTERVAL_SECS;
}
return -1;
} else {
/* error - reconnect */
if (ret < 0) {
Expand All @@ -114,5 +116,6 @@ void stats_connection_send(struct stats_connection *conn, const string_t *str)
if (close(conn->fd) < 0)
i_error("close(%s) failed: %m", conn->path);
conn->fd = -1;
return -1;
}
}
3 changes: 2 additions & 1 deletion src/lib-stats/stats-connection.h
Expand Up @@ -5,6 +5,7 @@ struct stats_connection *stats_connection_create(const char *path);
void stats_connection_ref(struct stats_connection *conn);
void stats_connection_unref(struct stats_connection **conn);

void stats_connection_send(struct stats_connection *conn, const string_t *str);
/* Returns 0 on success, -1 on failure. */
int stats_connection_send(struct stats_connection *conn, const string_t *str);

#endif

0 comments on commit a94f190

Please sign in to comment.