[PATCH 2/5] stats: Reorder functions in stats.c

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Tue Nov 17 12:18:22 UTC 2015


Due to prior refactoring, the functions do not have an sensible order
in the file. This commit tries to improve that a little bit.

Sponsored-by: On-Waves ehf
---
 src/stats.c | 120 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 61 insertions(+), 59 deletions(-)

diff --git a/src/stats.c b/src/stats.c
index 5547910..73b2703 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -286,6 +286,60 @@ int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep)
 	return update_srep_config(srep);
 }
 
+/*** i/o helper functions ***/
+
+int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep)
+{
+	int sock;
+	int rc;
+	int buffer_size = STATS_DEFAULT_BUFLEN;
+
+	if (srep->fd != -1 && srep->close)
+		 srep->close(srep);
+
+	sock = socket(AF_INET, SOCK_DGRAM, 0);
+	if (sock == -1)
+		return -errno;
+
+	if (srep->bind_addr_len > 0) {
+		rc = bind(sock, &srep->bind_addr, srep->bind_addr_len);
+		if (rc == -1)
+			goto failed;
+	}
+
+	srep->fd = sock;
+
+	if (srep->mtu > 0) {
+		buffer_size = srep->mtu - 20 /* IP */ - 8 /* UDP */;
+		srep->agg_enabled = 1;
+	}
+
+	srep->buffer = msgb_alloc(buffer_size, "stats buffer");
+
+	return 0;
+
+failed:
+	rc = -errno;
+	close(sock);
+
+	return rc;
+}
+
+int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep)
+{
+	int rc;
+	if (srep->fd == -1)
+		return -EBADF;
+
+	osmo_stats_reporter_send_buffer(srep);
+
+	rc = close(srep->fd);
+	srep->fd = -1;
+	msgb_free(srep->buffer);
+	srep->buffer = NULL;
+	return rc == -1 ? -errno : 0;
+}
+
 int osmo_stats_reporter_send(struct osmo_stats_reporter *srep, const char *data,
 	int data_len)
 {
@@ -315,16 +369,6 @@ int osmo_stats_reporter_send_buffer(struct osmo_stats_reporter *srep)
 	return rc;
 }
 
-static int osmo_stats_reporter_check_config(struct osmo_stats_reporter *srep,
-	unsigned int index, int class_id)
-{
-	if (class_id == OSMO_STATS_CLASS_UNKNOWN)
-		class_id = index != 0 ?
-			OSMO_STATS_CLASS_SUBSCRIBER : OSMO_STATS_CLASS_GLOBAL;
-
-	return class_id <= srep->max_class;
-}
-
 /*** log reporter ***/
 
 struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name)
@@ -380,58 +424,16 @@ static int osmo_stats_reporter_log_send_item(struct osmo_stats_reporter *srep,
 		desc->name, value, desc->unit);
 }
 
-/*** i/o helper functions ***/
-
-int osmo_stats_reporter_udp_open(struct osmo_stats_reporter *srep)
-{
-	int sock;
-	int rc;
-	int buffer_size = STATS_DEFAULT_BUFLEN;
-
-	if (srep->fd != -1 && srep->close)
-		 srep->close(srep);
-
-	sock = socket(AF_INET, SOCK_DGRAM, 0);
-	if (sock == -1)
-		return -errno;
+/*** helper for reporting ***/
 
-	if (srep->bind_addr_len > 0) {
-		rc = bind(sock, &srep->bind_addr, srep->bind_addr_len);
-		if (rc == -1)
-			goto failed;
-	}
-
-	srep->fd = sock;
-
-	if (srep->mtu > 0) {
-		buffer_size = srep->mtu - 20 /* IP */ - 8 /* UDP */;
-		srep->agg_enabled = 1;
-	}
-
-	srep->buffer = msgb_alloc(buffer_size, "stats buffer");
-
-	return 0;
-
-failed:
-	rc = -errno;
-	close(sock);
-
-	return rc;
-}
-
-int osmo_stats_reporter_udp_close(struct osmo_stats_reporter *srep)
+static int osmo_stats_reporter_check_config(struct osmo_stats_reporter *srep,
+	unsigned int index, int class_id)
 {
-	int rc;
-	if (srep->fd == -1)
-		return -EBADF;
-
-	osmo_stats_reporter_send_buffer(srep);
+	if (class_id == OSMO_STATS_CLASS_UNKNOWN)
+		class_id = index != 0 ?
+			OSMO_STATS_CLASS_SUBSCRIBER : OSMO_STATS_CLASS_GLOBAL;
 
-	rc = close(srep->fd);
-	srep->fd = -1;
-	msgb_free(srep->buffer);
-	srep->buffer = NULL;
-	return rc == -1 ? -errno : 0;
+	return class_id <= srep->max_class;
 }
 
 /*** generic rate counter support ***/
-- 
1.9.1




More information about the OpenBSC mailing list