changeset 20706:85fe66810c94

lib-stats: stats_connection_send() now returns whether it succeeded or not
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 08 Sep 2016 20:18:46 +0300
parents 21b48eb9ce22
children a9bdefa7d022
files src/lib-stats/stats-connection.c src/lib-stats/stats-connection.h
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-stats/stats-connection.c	Thu Sep 08 16:50:02 2016 +0300
+++ b/src/lib-stats/stats-connection.c	Thu Sep 08 20:18:46 2016 +0300
@@ -69,7 +69,7 @@
 	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 @@
 	   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 @@
 	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 @@
 			conn->next_warning_timestamp = ioloop_time +
 				STATS_EAGAIN_WARN_INTERVAL_SECS;
 		}
+		return -1;
 	} else {
 		/* error - reconnect */
 		if (ret < 0) {
@@ -114,5 +116,6 @@
 		if (close(conn->fd) < 0)
 			i_error("close(%s) failed: %m", conn->path);
 		conn->fd = -1;
+		return -1;
 	}
 }
--- a/src/lib-stats/stats-connection.h	Thu Sep 08 16:50:02 2016 +0300
+++ b/src/lib-stats/stats-connection.h	Thu Sep 08 20:18:46 2016 +0300
@@ -5,6 +5,7 @@
 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