aboutsummaryrefslogtreecommitdiff
path: root/src/core/socket.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-04-21 12:23:07 -0700
committerGitHub <noreply@github.com>2024-04-21 12:23:07 -0700
commit56507ab5c4db009be5251bde832f594fe5ed3d5e (patch)
treec70e7d669c3548a5c58ab27c0fc6118a96580863 /src/core/socket.c
parent3593eba5272bf627b99a2521b3f025141a49bcad (diff)
downloadnng-56507ab5c4db009be5251bde832f594fe5ed3d5e.tar.gz
nng-56507ab5c4db009be5251bde832f594fe5ed3d5e.tar.bz2
nng-56507ab5c4db009be5251bde832f594fe5ed3d5e.zip
Logging improvements (#1816)
* Add nng_str_sockaddr to get string representation of socket address. * Added nng_log_get_level() is meant to allow users to obtain the current level and avoid some possibly expensive operations just to collect debugging information when debugging is not in effect. We use a custom logger for NUTS, and this fits within the NUTS test framework well, so that if -v is supplied we get more content. All tests now get this by default.
Diffstat (limited to 'src/core/socket.c')
-rw-r--r--src/core/socket.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index 98999f6e..44612036 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -9,7 +9,9 @@
//
#include "core/nng_impl.h"
+#include "core/pipe.h"
#include "list.h"
+#include "nng/nng.h"
#include "sockimpl.h"
#include <stdio.h>
@@ -1522,8 +1524,12 @@ nni_dialer_add_pipe(nni_dialer *d, void *tpipe)
nni_stat_inc(&d->st_reject, 1);
nni_stat_inc(&s->st_rejects, 1);
#endif
- nng_log_debug("NNG-PIPEREJECT",
- "Pipe closed by pipe callback before added to socket");
+ if (nng_log_get_level() >= NNG_LOG_DEBUG) {
+ char addr[NNG_MAXADDRSTRLEN];
+ nng_log_debug("NNG-PIPEREJECT",
+ "Pipe on socket<%u> from %s rejected by callback",
+ nni_pipe_sock_id(p), nni_pipe_peer_addr(p, addr));
+ }
nni_pipe_rele(p);
return;
}
@@ -1543,6 +1549,12 @@ nni_dialer_add_pipe(nni_dialer *d, void *tpipe)
nni_stat_register(&p->st_root);
#endif
nni_pipe_run_cb(p, NNG_PIPE_EV_ADD_POST);
+ if (nng_log_get_level() >= NNG_LOG_DEBUG) {
+ char addr[NNG_MAXADDRSTRLEN];
+ nng_log_debug("NNG-CONNECT",
+ "Connected pipe<%u> on socket<%u> to %s", nni_pipe_id(p),
+ nni_sock_id(s), nni_pipe_peer_addr(p, addr));
+ }
nni_pipe_rele(p);
}
@@ -1653,6 +1665,12 @@ nni_listener_add_pipe(nni_listener *l, void *tpipe)
nni_stat_register(&p->st_root);
#endif
nni_pipe_run_cb(p, NNG_PIPE_EV_ADD_POST);
+ if (nng_log_get_level() >= NNG_LOG_DEBUG) {
+ char addr[NNG_MAXADDRSTRLEN];
+ nng_log_debug("NNG-ACCEPT",
+ "Accepted pipe<%u> on socket<%u> from %s", nni_pipe_id(p),
+ nni_sock_id(s), nni_pipe_peer_addr(p, addr));
+ }
nni_pipe_rele(p);
}