From ba5635889cdaaea4a887698c3c9549c6e0aae306 Mon Sep 17 00:00:00 2001
From: Hauke Petersen <hauke.petersen@fu-berlin.de>
Date: Mon, 22 May 2017 13:50:59 +0200
Subject: [PATCH] net/gcoap: make gcoap_op_state return count directly

---
 examples/gcoap/gcoap_cli.c             | 3 +--
 sys/include/net/gcoap.h                | 4 ++--
 sys/net/application_layer/coap/gcoap.c | 8 +++-----
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/examples/gcoap/gcoap_cli.c b/examples/gcoap/gcoap_cli.c
index 8542bcab35..636e6998ad 100644
--- a/examples/gcoap/gcoap_cli.c
+++ b/examples/gcoap/gcoap_cli.c
@@ -165,8 +165,7 @@ int gcoap_cli_cmd(int argc, char **argv)
 
     if (strcmp(argv[1], "info") == 0) {
         if (argc == 2) {
-            uint8_t open_reqs;
-            gcoap_op_state(&open_reqs);
+            uint8_t open_reqs = gcoap_op_state();
 
             printf("CoAP server is listening on port %u\n", GCOAP_PORT);
             printf(" CLI requests sent: %u\n", req_count);
diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h
index 19b5a7abc9..cea75a6c48 100644
--- a/sys/include/net/gcoap.h
+++ b/sys/include/net/gcoap.h
@@ -407,9 +407,9 @@ static inline ssize_t gcoap_response(coap_pkt_t *pdu, uint8_t *buf, size_t len,
  *
  * Useful for monitoring.
  *
- * @param[out] open_reqs Count of unanswered requests
+ * @return count of unanswered requests
  */
-void gcoap_op_state(uint8_t *open_reqs);
+uint8_t gcoap_op_state(void);
 
 #ifdef __cplusplus
 }
diff --git a/sys/net/application_layer/coap/gcoap.c b/sys/net/application_layer/coap/gcoap.c
index e6cdb8856f..5a4df08ab9 100644
--- a/sys/net/application_layer/coap/gcoap.c
+++ b/sys/net/application_layer/coap/gcoap.c
@@ -109,9 +109,7 @@ static void _listen(sock_udp_t *sock)
     uint8_t buf[GCOAP_PDU_BUF_SIZE];
     sock_udp_ep_t remote;
     gcoap_request_memo_t *memo = NULL;
-    uint8_t open_reqs;
-
-    gcoap_op_state(&open_reqs);
+    uint8_t open_reqs = gcoap_op_state();
 
     ssize_t res = sock_udp_recv(sock, buf, sizeof(buf),
                                 open_reqs > 0 ? GCOAP_RECV_TIMEOUT : SOCK_NO_TIMEOUT,
@@ -520,7 +518,7 @@ int gcoap_resp_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code)
     return 0;
 }
 
-void gcoap_op_state(uint8_t *open_reqs)
+uint8_t gcoap_op_state(void)
 {
     uint8_t count = 0;
     for (int i = 0; i < GCOAP_REQ_WAITING_MAX; i++) {
@@ -528,7 +526,7 @@ void gcoap_op_state(uint8_t *open_reqs)
             count++;
         }
     }
-    *open_reqs = count;
+    return count;
 }
 
 /** @} */
-- 
GitLab