From patchwork Tue Nov 17 12:18:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Erlbeck X-Patchwork-Id: 545552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (unknown [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 8471A141420 for ; Tue, 17 Nov 2015 23:19:26 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 74CAC9406; Tue, 17 Nov 2015 12:19:24 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.sysmocom.de (mail.sysmocom.de [IPv6:2a01:4f8:191:444c::2:4]) by lists.osmocom.org (Postfix) with ESMTP id B82AA93BE for ; Tue, 17 Nov 2015 12:19:22 +0000 (UTC) Received: from sysmocom-tmp.am93.sysmocom.de (ip5b4185b8.dynamic.kabel-deutschland.de [91.65.133.184]) by mail.sysmocom.de (Postfix) with ESMTPSA id 7DE941D2B10; Tue, 17 Nov 2015 12:18:52 +0000 (UTC) From: Jacob Erlbeck To: openbsc@lists.osmocom.org Subject: [PATCH 2/5] stats: Reorder functions in stats.c Date: Tue, 17 Nov 2015 13:18:22 +0100 Message-Id: <1447762705-14297-2-git-send-email-jerlbeck@sysmocom.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447762705-14297-1-git-send-email-jerlbeck@sysmocom.de> References: <1447762705-14297-1-git-send-email-jerlbeck@sysmocom.de> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" 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 ***/