]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-stats: stats_connection_send() now returns whether it succeeded or not
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 8 Sep 2016 17:18:46 +0000 (20:18 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 9 Sep 2016 11:22:29 +0000 (14:22 +0300)
src/lib-stats/stats-connection.c
src/lib-stats/stats-connection.h

index 740acad7df5e18306ba7a86f2eff583726003962..f342626656b0264d3fdffb961e646bc0e3c643f0 100644 (file)
@@ -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;
@@ -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) {
@@ -95,6 +95,7 @@ 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) {
@@ -102,6 +103,7 @@ void stats_connection_send(struct stats_connection *conn, const string_t *str)
                        conn->next_warning_timestamp = ioloop_time +
                                STATS_EAGAIN_WARN_INTERVAL_SECS;
                }
+               return -1;
        } else {
                /* error - reconnect */
                if (ret < 0) {
@@ -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;
        }
 }
index 7555f72e321b97ca09ac8f15f57d060ab18aef9a..2295e09ef3d6f464af39090b82c36a31ef02dfd4 100644 (file)
@@ -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