From 70ae513e4dda50864f7d45b6676549ed5246144d Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 27 Apr 2025 22:09:42 -0700 Subject: Transport listen: use nng_err --- src/core/sockfd.c | 4 ++-- src/core/stream.h | 2 +- src/platform/posix/posix_ipclisten.c | 8 ++++---- src/platform/posix/posix_tcplisten.c | 6 +++--- src/platform/windows/win_ipclisten.c | 10 +++++----- src/platform/windows/win_tcplisten.c | 6 +++--- src/sp/transport.h | 2 +- src/sp/transport/inproc/inproc.c | 4 ++-- src/sp/transport/ipc/ipc.c | 4 ++-- src/sp/transport/socket/sockfd.c | 2 +- src/sp/transport/tcp/tcp.c | 6 +++--- src/sp/transport/tls/tls.c | 6 +++--- src/sp/transport/udp/udp.c | 6 +++--- src/sp/transport/ws/websocket.c | 6 +++--- src/supplemental/tls/tls_listener.c | 2 +- src/supplemental/websocket/websocket.c | 11 ++++++----- 16 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/core/sockfd.c b/src/core/sockfd.c index f67ab64f..3a43359d 100644 --- a/src/core/sockfd.c +++ b/src/core/sockfd.c @@ -69,12 +69,12 @@ sfd_listener_stop(void *arg) sfd_listener_close(arg); } -static int +static nng_err sfd_listener_listen(void *arg) { NNI_ARG_UNUSED(arg); // nothing really for us to do - return (0); + return (NNG_OK); } static void diff --git a/src/core/stream.h b/src/core/stream.h index ebc13b26..5a07e5e5 100644 --- a/src/core/stream.h +++ b/src/core/stream.h @@ -68,7 +68,7 @@ struct nng_stream_listener { void (*sl_free)(void *); void (*sl_close)(void *); void (*sl_stop)(void *); - int (*sl_listen)(void *); + nng_err (*sl_listen)(void *); void (*sl_accept)(void *, nng_aio *); int (*sl_get)(void *, const char *, void *, size_t *, nni_type); int (*sl_set)(void *, const char *, const void *, size_t, nni_type); diff --git a/src/platform/posix/posix_ipclisten.c b/src/platform/posix/posix_ipclisten.c index ea540918..c651b9ab 100644 --- a/src/platform/posix/posix_ipclisten.c +++ b/src/platform/posix/posix_ipclisten.c @@ -358,13 +358,13 @@ ipc_listener_chmod(ipc_listener *l, const char *path) return (0); } -int +nng_err ipc_listener_listen(void *arg) { ipc_listener *l = arg; socklen_t len; struct sockaddr_storage ss; - int rv; + nng_err rv; int fd; char *path; @@ -420,7 +420,7 @@ ipc_listener_listen(void *arg) (listen(fd, 128) != 0)) { rv = nni_plat_errno(errno); } - if (rv != 0) { + if (rv != NNG_OK) { nni_mtx_unlock(&l->mtx); (void) close(fd); if (path != NULL) { @@ -457,7 +457,7 @@ ipc_listener_listen(void *arg) l->path = path; nni_mtx_unlock(&l->mtx); - return (0); + return (NNG_OK); } static void diff --git a/src/platform/posix/posix_tcplisten.c b/src/platform/posix/posix_tcplisten.c index 73374dc5..29255df2 100644 --- a/src/platform/posix/posix_tcplisten.c +++ b/src/platform/posix/posix_tcplisten.c @@ -176,13 +176,13 @@ tcp_listener_cancel(nni_aio *aio, void *arg, nng_err rv) nni_mtx_unlock(&l->mtx); } -static int +static nng_err tcp_listener_listen(void *arg) { tcp_listener *l = arg; socklen_t len; struct sockaddr_storage ss; - int rv; + nng_err rv; int fd; if (((len = nni_posix_nn2sockaddr(&ss, &l->sa)) == 0) || @@ -244,7 +244,7 @@ tcp_listener_listen(void *arg) l->started = true; nni_mtx_unlock(&l->mtx); - return (0); + return (NNG_OK); } static void diff --git a/src/platform/windows/win_ipclisten.c b/src/platform/windows/win_ipclisten.c index 56ec5cc3..e8670afe 100644 --- a/src/platform/windows/win_ipclisten.c +++ b/src/platform/windows/win_ipclisten.c @@ -191,11 +191,11 @@ ipc_listener_get( return (nni_getopt(ipc_listener_options, name, l, buf, szp, t)); } -static int +static nng_err ipc_listener_listen(void *arg) { ipc_listener *l = arg; - int rv; + nng_err rv; HANDLE f; char *path; @@ -209,7 +209,7 @@ ipc_listener_listen(void *arg) return (NNG_ECLOSED); } rv = nni_asprintf(&path, IPC_PIPE_PREFIX "%s", l->sa.s_ipc.sa_path); - if (rv != 0) { + if (rv != NNG_OK) { nni_mtx_unlock(&l->mtx); return (rv); } @@ -230,7 +230,7 @@ ipc_listener_listen(void *arg) nni_strfree(path); return (rv); } - if ((rv = nni_win_io_register(f)) != 0) { + if ((rv = nni_win_io_register(f)) != NNG_OK) { CloseHandle(f); nni_mtx_unlock(&l->mtx); nni_strfree(path); @@ -241,7 +241,7 @@ ipc_listener_listen(void *arg) l->path = path; l->started = true; nni_mtx_unlock(&l->mtx); - return (0); + return (NNG_OK); } static void diff --git a/src/platform/windows/win_tcplisten.c b/src/platform/windows/win_tcplisten.c index aa4a18e9..b92470ca 100644 --- a/src/platform/windows/win_tcplisten.c +++ b/src/platform/windows/win_tcplisten.c @@ -130,10 +130,10 @@ tcp_listener_free(void *arg) NNI_FREE_STRUCT(l); } -static int +static nng_err tcp_listener_listen(void *arg) { - int rv; + nng_err rv; BOOL yes; DWORD no; int len; @@ -192,7 +192,7 @@ tcp_listener_listen(void *arg) } l->started = true; nni_mtx_unlock(&l->mtx); - return (0); + return (NNG_OK); } static void diff --git a/src/sp/transport.h b/src/sp/transport.h index 1c9f930b..733388e8 100644 --- a/src/sp/transport.h +++ b/src/sp/transport.h @@ -92,7 +92,7 @@ struct nni_sp_listener_ops { // address, or NNG_EACCESS for permission problems. The transport // should update the url if it has changed (e.g. due to converting // from port 0 to a real port.) - int (*l_bind)(void *, nng_url *); + nng_err (*l_bind)(void *, nng_url *); // l_accept accepts an inbound connection. void (*l_accept)(void *, nni_aio *); diff --git a/src/sp/transport/inproc/inproc.c b/src/sp/transport/inproc/inproc.c index 1c7b88e6..8c662ca3 100644 --- a/src/sp/transport/inproc/inproc.c +++ b/src/sp/transport/inproc/inproc.c @@ -483,7 +483,7 @@ inproc_ep_connect(void *arg, nni_aio *aio) nni_mtx_unlock(&nni_inproc.mx); } -static int +static nng_err inproc_ep_bind(void *arg, nng_url *url) { inproc_ep *ep = arg; @@ -500,7 +500,7 @@ inproc_ep_bind(void *arg, nng_url *url) } nni_list_append(list, ep); nni_mtx_unlock(&nni_inproc.mx); - return (0); + return (NNG_OK); } static void diff --git a/src/sp/transport/ipc/ipc.c b/src/sp/transport/ipc/ipc.c index 82ec3f7e..0163767b 100644 --- a/src/sp/transport/ipc/ipc.c +++ b/src/sp/transport/ipc/ipc.c @@ -902,11 +902,11 @@ ipc_ep_set_recv_max_sz(void *arg, const void *v, size_t sz, nni_type t) return (rv); } -static int +static nng_err ipc_ep_bind(void *arg, nng_url *url) { ipc_ep *ep = arg; - int rv; + nng_err rv; NNI_ARG_UNUSED(url); nni_mtx_lock(&ep->mtx); diff --git a/src/sp/transport/socket/sockfd.c b/src/sp/transport/socket/sockfd.c index 5138afaa..e7b25d8b 100644 --- a/src/sp/transport/socket/sockfd.c +++ b/src/sp/transport/socket/sockfd.c @@ -768,7 +768,7 @@ sfd_tran_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_opt_type t) return (rv); } -static int +static nng_err sfd_tran_ep_bind(void *arg, nng_url *url) { sfd_tran_ep *ep = arg; diff --git a/src/sp/transport/tcp/tcp.c b/src/sp/transport/tcp/tcp.c index 3bc124ee..6bcbca9e 100644 --- a/src/sp/transport/tcp/tcp.c +++ b/src/sp/transport/tcp/tcp.c @@ -913,15 +913,15 @@ tcptran_ep_set_recvmaxsz(void *arg, const void *v, size_t sz, nni_opt_type t) return (rv); } -static int +static nng_err tcptran_ep_bind(void *arg, nng_url *url) { tcptran_ep *ep = arg; - int rv; + nng_err rv; nni_mtx_lock(&ep->mtx); rv = nng_stream_listener_listen(ep->listener); - if (rv == 0) { + if (rv == NNG_OK) { int port; nng_stream_listener_get_int( ep->listener, NNG_OPT_TCP_BOUND_PORT, &port); diff --git a/src/sp/transport/tls/tls.c b/src/sp/transport/tls/tls.c index 643146f7..5d2e6d9e 100644 --- a/src/sp/transport/tls/tls.c +++ b/src/sp/transport/tls/tls.c @@ -853,15 +853,15 @@ tlstran_ep_connect(void *arg, nni_aio *aio) nni_mtx_unlock(&ep->mtx); } -static int +static nng_err tlstran_ep_bind(void *arg, nng_url *url) { tlstran_ep *ep = arg; - int rv; + nng_err rv; nni_mtx_lock(&ep->mtx); rv = nng_stream_listener_listen(ep->listener); - if (rv == 0) { + if (rv == NNG_OK) { int port; nng_stream_listener_get_int( ep->listener, NNG_OPT_TCP_BOUND_PORT, &port); diff --git a/src/sp/transport/udp/udp.c b/src/sp/transport/udp/udp.c index 2e85fd0f..43fbabe1 100644 --- a/src/sp/transport/udp/udp.c +++ b/src/sp/transport/udp/udp.c @@ -1709,11 +1709,11 @@ udp_ep_start(udp_ep *ep) udp_start_rx(ep); } -static int +static nng_err udp_ep_bind(void *arg, nng_url *url) { udp_ep *ep = arg; - int rv; + nng_err rv; nni_mtx_lock(&ep->mtx); if (ep->started) { @@ -1722,7 +1722,7 @@ udp_ep_bind(void *arg, nng_url *url) } rv = nni_udp_open(&ep->udp, &ep->self_sa); - if (rv != 0) { + if (rv != NNG_OK) { nni_mtx_unlock(&ep->mtx); return (rv); } diff --git a/src/sp/transport/ws/websocket.c b/src/sp/transport/ws/websocket.c index f93b1f49..df157e02 100644 --- a/src/sp/transport/ws/websocket.c +++ b/src/sp/transport/ws/websocket.c @@ -225,13 +225,13 @@ wstran_pipe_peer(void *arg) return (p->peer); } -static int +static nng_err wstran_listener_bind(void *arg, nng_url *url) { ws_listener *l = arg; - int rv; + nng_err rv; - if ((rv = nng_stream_listener_listen(l->listener)) == 0) { + if ((rv = nng_stream_listener_listen(l->listener)) == NNG_OK) { int port; nng_stream_listener_get_int( l->listener, NNG_OPT_TCP_BOUND_PORT, &port); diff --git a/src/supplemental/tls/tls_listener.c b/src/supplemental/tls/tls_listener.c index b16877b1..0ab0f57b 100644 --- a/src/supplemental/tls/tls_listener.c +++ b/src/supplemental/tls/tls_listener.c @@ -54,7 +54,7 @@ tls_listener_free(void *arg) } } -static int +static nng_err tls_listener_listen(void *arg) { tls_listener *l = arg; diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index b3410dea..36312b69 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -1688,11 +1688,11 @@ nni_ws_listener_hook( nni_mtx_unlock(&l->mtx); } -static int +static nng_err ws_listener_listen(void *arg) { nni_ws_listener *l = arg; - int rv; + nng_err rv; nni_mtx_lock(&l->mtx); if (l->closed) { @@ -1704,14 +1704,15 @@ ws_listener_listen(void *arg) return (NNG_ESTATE); } - if ((rv = nni_http_server_add_handler(l->server, l->handler)) != 0) { + if ((rv = nni_http_server_add_handler(l->server, l->handler)) != + NNG_OK) { nni_http_server_fini(l->server); l->server = NULL; nni_mtx_unlock(&l->mtx); return (rv); } - if ((rv = nni_http_server_start(l->server)) != 0) { + if ((rv = nni_http_server_start(l->server)) != NNG_OK) { nni_http_server_del_handler(l->server, l->handler); nni_http_server_fini(l->server); l->server = NULL; @@ -1722,7 +1723,7 @@ ws_listener_listen(void *arg) l->started = true; nni_mtx_unlock(&l->mtx); - return (0); + return (NNG_OK); } static int -- cgit v1.2.3-70-g09d2