From b0874b1dad787c32093a3ff81311e2d638dc6538 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 31 Dec 2024 13:26:44 -0800 Subject: socket: rename nng_close to nng_socket_close --- demo/async/client.c | 6 +- demo/raw/raw.c | 12 +-- demo/reqrep/reqrep.c | 2 +- docs/man/libnng.3.adoc | 2 +- docs/man/nng_close.3.adoc | 59 ------------ docs/man/nng_ctx_close.3.adoc | 2 +- docs/man/nng_dialer_close.3.adoc | 2 +- docs/man/nng_listener_close.3.adoc | 2 +- docs/ref/api/sock.md | 22 +++++ docs/ref/migrate/nanomsg.md | 2 +- docs/ref/migrate/nng1.md | 5 + docs/ref/xref.md | 1 + include/nng/nng.h | 9 +- src/core/aio_test.c | 14 +-- src/core/buf_size_test.c | 2 +- src/core/socket.c | 2 +- src/nng.c | 2 +- src/sp/nonblock_test.c | 4 +- src/sp/pipe_test.c | 4 +- src/sp/protocol/bus0/bus_test.c | 2 +- src/sp/protocol/pair0/pair0_test.c | 12 +-- src/sp/protocol/pair1/pair1_test.c | 12 +-- src/sp/protocol/pipeline0/pull_test.c | 2 +- src/sp/protocol/pipeline0/push_test.c | 2 +- src/sp/protocol/pubsub0/pub_test.c | 2 +- src/sp/protocol/reqrep0/req_test.c | 2 +- src/sp/protocol/reqrep0/xrep_test.c | 6 +- src/sp/protocol/reqrep0/xreq_test.c | 2 +- src/sp/protocol/survey0/survey_test.c | 6 +- src/sp/reconnect_stress_test.c | 153 +++++++++++++++--------------- src/sp/scalability_test.c | 2 +- src/sp/transport/tcp/tcp_test.c | 2 +- src/sp/transport/tls/tls_tran_test.c | 4 +- src/sp/transport/udp/udp_tran_test.c | 2 +- src/supplemental/websocket/wssfile_test.c | 12 +-- src/testing/nuts.h | 4 +- src/tools/perf/perf.c | 8 +- src/tools/perf/pubdrop.c | 2 +- tests/cplusplus_pair.cc | 4 +- tests/trantest.h | 4 +- 40 files changed, 185 insertions(+), 214 deletions(-) delete mode 100644 docs/man/nng_close.3.adoc diff --git a/demo/async/client.c b/demo/async/client.c index 33ab9b36..bf9389a0 100644 --- a/demo/async/client.c +++ b/demo/async/client.c @@ -42,7 +42,7 @@ client(const char *url, const char *msecstr) { nng_socket sock; int rv; - nng_msg * msg; + nng_msg *msg; nng_time start; nng_time end; unsigned msec; @@ -76,9 +76,9 @@ client(const char *url, const char *msecstr) } end = nng_clock(); nng_msg_free(msg); - nng_close(sock); + nng_socket_close(sock); - printf("Request took %u milliseconds.\n", (uint32_t)(end - start)); + printf("Request took %u milliseconds.\n", (uint32_t) (end - start)); return (0); } diff --git a/demo/raw/raw.c b/demo/raw/raw.c index 1087fa6f..06f69143 100644 --- a/demo/raw/raw.c +++ b/demo/raw/raw.c @@ -47,9 +47,9 @@ // use in poll. struct work { enum { INIT, RECV, WAIT, SEND } state; - nng_aio * aio; + nng_aio *aio; nng_socket sock; - nng_msg * msg; + nng_msg *msg; }; void @@ -63,7 +63,7 @@ void server_cb(void *arg) { struct work *work = arg; - nng_msg * msg; + nng_msg *msg; int rv; uint32_t when; @@ -163,7 +163,7 @@ client(const char *url, const char *msecstr) { nng_socket sock; int rv; - nng_msg * msg; + nng_msg *msg; nng_time start; nng_time end; unsigned msec; @@ -196,9 +196,9 @@ client(const char *url, const char *msecstr) } end = nng_clock(); nng_msg_free(msg); - nng_close(sock); + nng_socket_close(sock); - printf("Request took %u milliseconds.\n", (uint32_t)(end - start)); + printf("Request took %u milliseconds.\n", (uint32_t) (end - start)); return (0); } diff --git a/demo/reqrep/reqrep.c b/demo/reqrep/reqrep.c index e23ba100..e390d523 100644 --- a/demo/reqrep/reqrep.c +++ b/demo/reqrep/reqrep.c @@ -173,7 +173,7 @@ client(const char *url) // This assumes that buf is ASCIIZ (zero terminated). nng_free(buf, sz); - nng_close(sock); + nng_socket_close(sock); return (0); } diff --git a/docs/man/libnng.3.adoc b/docs/man/libnng.3.adoc index 36117614..9cef1e0f 100644 --- a/docs/man/libnng.3.adoc +++ b/docs/man/libnng.3.adoc @@ -47,7 +47,7 @@ The following common functions exist in _libnng_. The following functions operate on sockets. |=== -|xref:nng_close.3.adoc[nng_close()]|close socket +|xref:nng_socket_close.3.adoc[nng_socket_close()]|close socket |xref:nng_dial.3.adoc[nng_dial()]|create and start dialer |xref:nng_get.3.adoc[nng_get()]|get socket option |xref:nng_listen.3.adoc[nng_listen()]|create and start listener diff --git a/docs/man/nng_close.3.adoc b/docs/man/nng_close.3.adoc deleted file mode 100644 index 1867df07..00000000 --- a/docs/man/nng_close.3.adoc +++ /dev/null @@ -1,59 +0,0 @@ -= nng_close(3) -// -// Copyright 2018 Staysail Systems, Inc. -// Copyright 2018 Capitar IT Group BV -// -// This document is supplied under the terms of the MIT License, a -// copy of which should be located in the distribution where this -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -== NAME - -nng_close - close socket - -== SYNOPSIS - -[source, c] ----- -#include - -int nng_close(nng_socket s); ----- - -== DESCRIPTION - -The `nng_close()` function closes the supplied socket, _s_. -Messages that have been submitted for sending may be flushed or delivered, -depending upon the transport. - -Further attempts to use the socket after this call returns will result -in `NNG_ECLOSED`. -Threads waiting for operations on the socket when this -call is executed may also return with an `NNG_ECLOSED` result. - -NOTE: Closing the socket while data is in transmission will likely lead to loss -of that data. -There is no automatic linger or flush to ensure that the socket send buffers -have completely transmitted. -It is recommended to wait a brief period after calling -xref:nng_send.3.adoc[`nng_send()`] or similar functions, before calling this -function. - -== RETURN VALUES - -This function returns 0 on success, and non-zero otherwise. - -== ERRORS - -[horizontal] -`NNG_ECLOSED`:: The socket _s_ is already closed or was never opened. - -== SEE ALSO - -[.text-left] -xref:nng_strerror.3.adoc[nng_strerror(3)], -xref:nng_options.5.adoc[nng_options(5)], -xref:nng_socket.5.adoc[nng_socket(5)], -xref:nng.7.adoc[nng(7)] diff --git a/docs/man/nng_ctx_close.3.adoc b/docs/man/nng_ctx_close.3.adoc index cfc51bfa..ff43d0b3 100644 --- a/docs/man/nng_ctx_close.3.adoc +++ b/docs/man/nng_ctx_close.3.adoc @@ -34,7 +34,7 @@ Threads waiting for operations on the context when this call is executed may also return with an `NNG_ECLOSED` result. NOTE: Closing the socket associated with _ctx_ -(using xref:nng_close.3.adoc[`nng_close()`]) also closes this context. +(using xref:nng_socket_close.3.adoc[`nng_socket_close()`]) also closes this context. == RETURN VALUES diff --git a/docs/man/nng_dialer_close.3.adoc b/docs/man/nng_dialer_close.3.adoc index 6af73ae4..84308b9b 100644 --- a/docs/man/nng_dialer_close.3.adoc +++ b/docs/man/nng_dialer_close.3.adoc @@ -48,7 +48,7 @@ This function returns 0 on success, and non-zero otherwise. == SEE ALSO [.text-left] -xref:nng_close.3.adoc[nng_close(3)], +xref:nng_socket_close.3.adoc[nng_socket_close(3)], xref:nng_dial.3.adoc[nng_dial(3)], xref:nng_dialer_create.3.adoc[nng_dialer_create(3)] xref:nng_strerror.3.adoc[nng_strerror(3)], diff --git a/docs/man/nng_listener_close.3.adoc b/docs/man/nng_listener_close.3.adoc index 239fe26b..b5109f42 100644 --- a/docs/man/nng_listener_close.3.adoc +++ b/docs/man/nng_listener_close.3.adoc @@ -48,7 +48,7 @@ This function returns 0 on success, and non-zero otherwise. == SEE ALSO [.text-left] -xref:nng_close.3.adoc[nng_close(3)], +xref:nng_socket_close.3.adoc[nng_socket_close(3)], xref:nng_listen.3.adoc[nng_listen(3)], xref:nng_listener_create.3.adoc[nng_listener_create(3)] xref:nng_strerror.3.adoc[nng_strerror(3)], diff --git a/docs/ref/api/sock.md b/docs/ref/api/sock.md index 59570240..40190d33 100644 --- a/docs/ref/api/sock.md +++ b/docs/ref/api/sock.md @@ -127,6 +127,28 @@ The following functions open a socket in [raw] mode: - {{i:`nng_sub0_open_raw`}} - [SUB][sub] version 0, raw mode - {{i:`nng_surveyor0_open_raw`}} - [SURVEYOR][surveyor] version 0, raw mode +## Closing a Socket + +```c +int nng_socket_close(nng_socket s); +``` + +The {{i:`nng_socket_close`}} function closes a socket, releasing all resources +associated with it. Any operations that are in progress will be terminated with +a result of [`NNG_ECLOSED`]. + +> [!NOTE] +> Closing a socket also invalidates any [dialers][dialer], [listeners][listener], +> [pipes][pipe], or [contexts][context] associated with it. + +> [!NOTE] +> This function will wait for any outstanding operations to be aborted, or to complete, +> before returning. Consequently it is not safe to call this from contexts that cannot +> block. + +> [!NOTE] +> Closing the socket may be disruptive to transfers that are still in progress. + ## Polling Socket Events ```c diff --git a/docs/ref/migrate/nanomsg.md b/docs/ref/migrate/nanomsg.md index 66add9b2..f7c6b971 100644 --- a/docs/ref/migrate/nanomsg.md +++ b/docs/ref/migrate/nanomsg.md @@ -38,7 +38,7 @@ NNG approach to messages. Likewise there is no `struct nn_cmsghdr` equivalent. | `nn_strerror` | [`nng_strerror`] | | `nn_errno` | None | Errors are returned directly rather than through `errno`. | | `nn_socket` | Various | Use the appropriate protocol constructor, such as `nng_req0_open`. | -| `nn_close` | `nng_close` | +| `nn_close` | `nng_socket_close` | | `nn_bind` | `nng_listen`, `nng_listener_create` | Allocating a listener with `nng_lister_create` and configuring it offers more capabilities. | | `nn_connect` | `nng_dial`, `nng_dialer_create` | Allocating a dialer with `nng_dialer_create` and configuring it offers more capabilities. | | `nn_shutdown` | `nng_lister_close`, `nng_dialer_close` | diff --git a/docs/ref/migrate/nng1.md b/docs/ref/migrate/nng1.md index 62a27432..663bf002 100644 --- a/docs/ref/migrate/nng1.md +++ b/docs/ref/migrate/nng1.md @@ -13,6 +13,11 @@ See the [Migrating From libnanomsg](nanomsg.md) chapter for details. It is now required for applications to initialize the library explicitly before using it. This is done using the [`nng_init`] function. +## Socket Close Function Renamed + +The `nng_close` function has been renamed to [`nng_socket_close`] to make it clearer that +the object being closed is a socket. + ## New AIO Error Code NNG_ESTOPPED When an operation fails with [`NNG_ESTOPPED`], it means that the associated [`nni_aio`] object has diff --git a/docs/ref/xref.md b/docs/ref/xref.md index 12146752..0dae482c 100644 --- a/docs/ref/xref.md +++ b/docs/ref/xref.md @@ -96,6 +96,7 @@ [`nng_iov`]: /api/aio.md#scatter-gather-vectors [`nng_socket_id`]: /api/sock.md#socket-identity [`nng_socket_raw`]: /api/sock.md#socket-identity +[`nng_socket_close`]: /api/sock.md#closing-a-socket [`nng_socket_proto_id`]: /api/sock.md#socket-identity [`nng_socket_proto_name`]: /api/sock.md#socket-identity [`nng_socket_peer_id`]: /api/sock.md#socket-identity diff --git a/include/nng/nng.h b/include/nng/nng.h index 61c1171f..e4e97f86 100644 --- a/include/nng/nng.h +++ b/include/nng/nng.h @@ -208,10 +208,10 @@ typedef struct nng_iov { #define NNG_DURATION_DEFAULT (-2) #define NNG_DURATION_ZERO (0) -// nng_close closes the socket, terminating all activity and +// nng_socket_close closes the socket, terminating all activity and // closing any underlying connections and releasing any associated // resources. -NNG_DECL int nng_close(nng_socket); +NNG_DECL int nng_socket_close(nng_socket); // nng_socket_id returns the positive socket id for the socket, or -1 // if the socket is not valid. @@ -435,8 +435,9 @@ NNG_DECL void nng_recv_aio(nng_socket, nng_aio *); // without resorting to raw mode sockets. See the protocol specific // documentation for further details. (Note that at this time, only // asynchronous send/recv are supported for contexts, but its easy enough -// to make synchronous versions with nng_aio_wait().) Note that nng_close -// of the parent socket will *block* as long as any contexts are open. +// to make synchronous versions with nng_aio_wait().) Note that +// nng_socket_close of the parent socket will *block* as long as any contexts +// are open. // nng_ctx_open creates a context. This returns NNG_ENOTSUP if the // protocol implementation does not support separate contexts. diff --git a/src/core/aio_test.c b/src/core/aio_test.c index f9663903..d8d70e12 100644 --- a/src/core/aio_test.c +++ b/src/core/aio_test.c @@ -155,7 +155,7 @@ test_consumer_cancel(void) NUTS_TRUE(nng_aio_result(a) == NNG_ECANCELED); nng_aio_free(a); - NUTS_TRUE(nng_close(s1) == 0); + NUTS_CLOSE(s1); } void @@ -207,8 +207,8 @@ test_traffic(void) nng_aio_free(rx_aio); nng_aio_free(tx_aio); - NUTS_PASS(nng_close(s1)); - NUTS_PASS(nng_close(s2)); + NUTS_CLOSE(s1); + NUTS_CLOSE(s2); } void @@ -226,7 +226,7 @@ test_explicit_timeout(void) NUTS_TRUE(done == 1); NUTS_FAIL(nng_aio_result(a), NNG_ETIMEDOUT); nng_aio_free(a); - NUTS_PASS(nng_close(s)); + NUTS_CLOSE(s); } void @@ -247,7 +247,7 @@ test_explicit_expiration(void) NUTS_TRUE(done == 1); NUTS_FAIL(nng_aio_result(a), NNG_ETIMEDOUT); nng_aio_free(a); - NUTS_PASS(nng_close(s)); + NUTS_CLOSE(s); } void @@ -265,7 +265,7 @@ test_inherited_timeout(void) NUTS_TRUE(done == 1); NUTS_FAIL(nng_aio_result(a), NNG_ETIMEDOUT); nng_aio_free(a); - NUTS_PASS(nng_close(s)); + NUTS_CLOSE(s); } void @@ -283,7 +283,7 @@ test_zero_timeout(void) NUTS_TRUE(done == 1); NUTS_FAIL(nng_aio_result(a), NNG_ETIMEDOUT); nng_aio_free(a); - NUTS_PASS(nng_close(s)); + NUTS_CLOSE(s); } static void diff --git a/src/core/buf_size_test.c b/src/core/buf_size_test.c index b33a713b..1290a5c2 100644 --- a/src/core/buf_size_test.c +++ b/src/core/buf_size_test.c @@ -43,7 +43,7 @@ test_buffer_options(void) // Buffer sizes are limited to sane levels NUTS_FAIL(nng_socket_set_int(s1, opt, 0x100000), NNG_EINVAL); } - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } NUTS_TESTS = { diff --git a/src/core/socket.c b/src/core/socket.c index 89352c03..0dfdb183 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -698,7 +698,7 @@ nni_sock_shutdown(nni_sock *sock) // At this point, there are no threads blocked inside of us // that are referencing socket state. User code should call - // nng_close to release the last resources. + // nng_socket_close to release the last resources. return (0); } diff --git a/src/nng.c b/src/nng.c index 0c96fd90..55e23214 100644 --- a/src/nng.c +++ b/src/nng.c @@ -26,7 +26,7 @@ #include int -nng_close(nng_socket s) +nng_socket_close(nng_socket s) { int rv; nni_sock *sock; diff --git a/src/sp/nonblock_test.c b/src/sp/nonblock_test.c index 0f9be034..7b2251c4 100644 --- a/src/sp/nonblock_test.c +++ b/src/sp/nonblock_test.c @@ -114,10 +114,10 @@ test_nonblocking(void) } nng_msleep(15000); - nng_close(rep); + nng_socket_close(rep); nng_thread_destroy(server); for (int i = 0; i < NCLIENTS; i++) { - nng_close(reqs[i]); + nng_socket_close(reqs[i]); nng_thread_destroy(clients[i]); } } diff --git a/src/sp/pipe_test.c b/src/sp/pipe_test.c index 787eac69..c0219813 100644 --- a/src/sp/pipe_test.c +++ b/src/sp/pipe_test.c @@ -143,8 +143,8 @@ init_cases(char *addr, struct testcase *push, struct testcase *pull) static void fini_cases(struct testcase *push, struct testcase *pull) { - nng_close(push->s); - nng_close(pull->s); + nng_socket_close(push->s); + nng_socket_close(pull->s); nng_cv_free(push->cv); nng_cv_free(pull->cv); nng_mtx_free(push->lk); diff --git a/src/sp/protocol/bus0/bus_test.c b/src/sp/protocol/bus0/bus_test.c index 94ba8329..fd0116e7 100644 --- a/src/sp/protocol/bus0/bus_test.c +++ b/src/sp/protocol/bus0/bus_test.c @@ -378,7 +378,7 @@ test_bus_cooked(void) NUTS_PASS(nng_bus0_open(&s)); NUTS_PASS(nng_socket_raw(s, &b)); NUTS_TRUE(!b); - NUTS_PASS(nng_close(s)); + NUTS_CLOSE(s); // raw pub only differs in the option setting NUTS_PASS(nng_bus0_open_raw(&s)); diff --git a/src/sp/protocol/pair0/pair0_test.c b/src/sp/protocol/pair0/pair0_test.c index d883f1e3..dc3264be 100644 --- a/src/sp/protocol/pair0/pair0_test.c +++ b/src/sp/protocol/pair0/pair0_test.c @@ -215,7 +215,7 @@ test_pair0_send_stopped_aio(void) NUTS_FAIL(nng_aio_result(aio), NNG_ESTOPPED); nng_msg_free(msg); nng_aio_free(aio); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void @@ -235,7 +235,7 @@ test_pair0_send_canceled_aio(void) NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED); nng_msg_free(msg); nng_aio_free(aio); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void @@ -251,7 +251,7 @@ test_pair0_recv_stopped_aio(void) nng_aio_wait(aio); NUTS_FAIL(nng_aio_result(aio), NNG_ESTOPPED); nng_aio_free(aio); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void @@ -267,7 +267,7 @@ test_pair0_recv_canceled_aio(void) nng_aio_wait(aio); NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED); nng_aio_free(aio); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void test_pair0_raw(void) @@ -278,12 +278,12 @@ test_pair0_raw(void) NUTS_PASS(nng_pair0_open(&s1)); NUTS_PASS(nng_socket_raw(s1, &raw)); NUTS_TRUE(raw == false); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); NUTS_PASS(nng_pair0_open_raw(&s1)); NUTS_PASS(nng_socket_raw(s1, &raw)); NUTS_TRUE(raw == true); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void diff --git a/src/sp/protocol/pair1/pair1_test.c b/src/sp/protocol/pair1/pair1_test.c index 55fbb09f..8ed6ccbf 100644 --- a/src/sp/protocol/pair1/pair1_test.c +++ b/src/sp/protocol/pair1/pair1_test.c @@ -281,7 +281,7 @@ test_pair1_send_stopped_aio(void) NUTS_FAIL(nng_aio_result(aio), NNG_ESTOPPED); nng_msg_free(msg); nng_aio_free(aio); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void @@ -301,7 +301,7 @@ test_pair1_send_canceled_aio(void) NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED); nng_msg_free(msg); nng_aio_free(aio); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void @@ -317,7 +317,7 @@ test_pair1_recv_stopped_aio(void) nng_aio_wait(aio); NUTS_FAIL(nng_aio_result(aio), NNG_ESTOPPED); nng_aio_free(aio); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void @@ -333,7 +333,7 @@ test_pair1_recv_canceled_aio(void) nng_aio_wait(aio); NUTS_FAIL(nng_aio_result(aio), NNG_ECANCELED); nng_aio_free(aio); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void @@ -345,12 +345,12 @@ test_pair1_raw(void) NUTS_PASS(nng_pair1_open(&s1)); NUTS_PASS(nng_socket_raw(s1, &raw)); NUTS_TRUE(raw == false); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); NUTS_PASS(nng_pair1_open_raw(&s1)); NUTS_PASS(nng_socket_raw(s1, &raw)); NUTS_TRUE(raw == true); - NUTS_PASS(nng_close(s1)); + NUTS_CLOSE(s1); } void diff --git a/src/sp/protocol/pipeline0/pull_test.c b/src/sp/protocol/pipeline0/pull_test.c index fb57b9a2..131ff92c 100644 --- a/src/sp/protocol/pipeline0/pull_test.c +++ b/src/sp/protocol/pipeline0/pull_test.c @@ -207,7 +207,7 @@ test_pull_close_recv(void) NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); nng_aio_set_timeout(aio, 1000); nng_recv_aio(s, aio); - NUTS_PASS(nng_close(s)); + NUTS_CLOSE(s); nng_aio_wait(aio); NUTS_FAIL(nng_aio_result(aio), NNG_ECLOSED); diff --git a/src/sp/protocol/pipeline0/push_test.c b/src/sp/protocol/pipeline0/push_test.c index e0d314ee..579178b5 100644 --- a/src/sp/protocol/pipeline0/push_test.c +++ b/src/sp/protocol/pipeline0/push_test.c @@ -271,7 +271,7 @@ test_push_close_send(void) nng_aio_set_timeout(aio, 1000); nng_aio_set_msg(aio, m); nng_send_aio(s, aio); - NUTS_PASS(nng_close(s)); + NUTS_CLOSE(s); nng_aio_wait(aio); NUTS_FAIL(nng_aio_result(aio), NNG_ECLOSED); diff --git a/src/sp/protocol/pubsub0/pub_test.c b/src/sp/protocol/pubsub0/pub_test.c index 8b3a5d78..2b571bef 100644 --- a/src/sp/protocol/pubsub0/pub_test.c +++ b/src/sp/protocol/pubsub0/pub_test.c @@ -193,7 +193,7 @@ test_pub_cooked(void) NUTS_PASS(nng_pub0_open(&s)); NUTS_PASS(nng_socket_raw(s, &b)); NUTS_TRUE(!b); - NUTS_PASS(nng_close(s)); + NUTS_CLOSE(s); // raw pub only differs in the option setting NUTS_PASS(nng_pub0_open_raw(&s)); diff --git a/src/sp/protocol/reqrep0/req_test.c b/src/sp/protocol/reqrep0/req_test.c index 1dc04a5c..d4dc8c27 100644 --- a/src/sp/protocol/reqrep0/req_test.c +++ b/src/sp/protocol/reqrep0/req_test.c @@ -932,7 +932,7 @@ test_req_ctx_recv_close_socket(void) NUTS_PASS(nng_aio_result(aio)); nng_ctx_recv(ctx, aio); - nng_close(req); + nng_socket_close(req); nng_aio_wait(aio); NUTS_FAIL(nng_aio_result(aio), NNG_ECLOSED); diff --git a/src/sp/protocol/reqrep0/xrep_test.c b/src/sp/protocol/reqrep0/xrep_test.c index 068d64a7..e3ba0f94 100644 --- a/src/sp/protocol/reqrep0/xrep_test.c +++ b/src/sp/protocol/reqrep0/xrep_test.c @@ -142,8 +142,8 @@ test_xrep_validate_peer(void) NUTS_TRUE(nng_stat_type(reject) == NNG_STAT_COUNTER); NUTS_TRUE(nng_stat_value(reject) > 0); - NUTS_PASS(nng_close(s1)); - NUTS_PASS(nng_close(s2)); + NUTS_CLOSE(s1); + NUTS_CLOSE(s2); nng_stats_free(stats); } @@ -353,7 +353,7 @@ test_xrep_ttl_option(void) NUTS_TRUE(nng_socket_set_bool(rep, opt, true) == NNG_EBADTYPE); NUTS_TRUE(nng_socket_get_bool(rep, opt, &b) == NNG_EBADTYPE); - NUTS_TRUE(nng_close(rep) == 0); + NUTS_CLOSE(rep); } static void diff --git a/src/sp/protocol/reqrep0/xreq_test.c b/src/sp/protocol/reqrep0/xreq_test.c index 1f06eb17..b51de556 100644 --- a/src/sp/protocol/reqrep0/xreq_test.c +++ b/src/sp/protocol/reqrep0/xreq_test.c @@ -358,7 +358,7 @@ test_xreq_ttl_option(void) NUTS_TRUE(nng_socket_set_bool(rep, opt, true) == NNG_EBADTYPE); NUTS_TRUE(nng_socket_get_bool(rep, opt, &b) == NNG_EBADTYPE); - NUTS_TRUE(nng_close(rep) == 0); + NUTS_CLOSE(rep); } NUTS_TESTS = { diff --git a/src/sp/protocol/survey0/survey_test.c b/src/sp/protocol/survey0/survey_test.c index 3f122abb..0489bf9f 100644 --- a/src/sp/protocol/survey0/survey_test.c +++ b/src/sp/protocol/survey0/survey_test.c @@ -502,7 +502,7 @@ test_surv_ctx_recv_close_socket(void) NUTS_PASS(nng_aio_result(aio)); nng_ctx_recv(ctx, aio); - nng_close(surv); + nng_socket_close(surv); nng_aio_wait(aio); NUTS_FAIL(nng_aio_result(aio), NNG_ECLOSED); @@ -594,8 +594,8 @@ test_surv_validate_peer(void) NUTS_TRUE(nng_stat_type(reject) == NNG_STAT_COUNTER); NUTS_TRUE(nng_stat_value(reject) > 0); - NUTS_PASS(nng_close(s1)); - NUTS_PASS(nng_close(s2)); + NUTS_CLOSE(s1); + NUTS_CLOSE(s2); nng_stats_free(stats); } diff --git a/src/sp/reconnect_stress_test.c b/src/sp/reconnect_stress_test.c index f463e0e5..578e34bd 100644 --- a/src/sp/reconnect_stress_test.c +++ b/src/sp/reconnect_stress_test.c @@ -8,12 +8,12 @@ // #include -#include #include -#include -#include -#include +#include #include +#include +#include +#include #include @@ -26,10 +26,10 @@ struct work; typedef void (*work_fn)(struct work *); struct work { - work_fn start; - nng_socket socket; - nng_aio * aio; - enum state state; + work_fn start; + nng_socket socket; + nng_aio *aio; + enum state state; nni_atomic_int received; }; @@ -40,10 +40,10 @@ fatal(const char *msg, int result) abort(); } -#define PASS(cond) \ - do { \ - int result_ = (cond); \ - if (result_ != 0) \ +#define PASS(cond) \ + do { \ + int result_ = (cond); \ + if (result_ != 0) \ fatal(#cond, result_); \ } while (0) @@ -76,7 +76,7 @@ work_listen(struct work *w, const char *url) } void -work_dial(struct work *w, const char * const * urls, size_t urls_size) +work_dial(struct work *w, const char *const *urls, size_t urls_size) { size_t i; @@ -87,7 +87,7 @@ work_dial(struct work *w, const char * const * urls, size_t urls_size) void close_work(struct work *w) { - nng_close(w->socket); + nng_socket_close(w->socket); nng_aio_wait(w->aio); nng_aio_free(w->aio); } @@ -101,39 +101,39 @@ ping_start(struct work *w) void ping_cb(void *arg) { - nng_msg *msg; - struct work *w = arg; - int result = nng_aio_result(w->aio); + nng_msg *msg; + struct work *w = arg; + int result = nng_aio_result(w->aio); if (result) switch (result) { - case NNG_ETIMEDOUT: - case NNG_ESTATE: - free_aio_msg(w); - ping_start(w); - return; - case NNG_ECANCELED: - case NNG_ECLOSED: - free_aio_msg(w); - return; - default: - fatal("ping_cb", result); + case NNG_ETIMEDOUT: + case NNG_ESTATE: + free_aio_msg(w); + ping_start(w); + return; + case NNG_ECANCELED: + case NNG_ECLOSED: + free_aio_msg(w); + return; + default: + fatal("ping_cb", result); } switch (w->state) { - case SEND: - w->state = RECV; - nng_recv_aio(w->socket, w->aio); - break; - case RECV: - msg = nng_aio_get_msg(w->aio); - assert(msg != NULL); - assert(nng_msg_len(msg) == 5); - assert(0 == strncmp(nng_msg_body(msg), "echo", 4)); - nng_msg_free(msg); - nni_atomic_inc(&w->received); - ping_start(w); - break; + case SEND: + w->state = RECV; + nng_recv_aio(w->socket, w->aio); + break; + case RECV: + msg = nng_aio_get_msg(w->aio); + assert(msg != NULL); + assert(nng_msg_len(msg) == 5); + assert(0 == strncmp(nng_msg_body(msg), "echo", 4)); + nng_msg_free(msg); + nni_atomic_inc(&w->received); + ping_start(w); + break; } } @@ -147,48 +147,49 @@ echo_start(struct work *w) void echo_cb(void *arg) { - nng_msg *msg; - struct work *w = arg; - int result = nng_aio_result(w->aio); + nng_msg *msg; + struct work *w = arg; + int result = nng_aio_result(w->aio); if (result) switch (result) { - case NNG_ECANCELED: - case NNG_ECLOSED: - free_aio_msg(w); - return; - default: - fatal("echo_cb", result); + case NNG_ECANCELED: + case NNG_ECLOSED: + free_aio_msg(w); + return; + default: + fatal("echo_cb", result); } switch (w->state) { - case RECV: - msg = nng_aio_get_msg(w->aio); - assert(msg != NULL); - assert(nng_msg_len(msg) == 5); - assert(0 == strncmp(nng_msg_body(msg), "ping", 4)); - nng_msg_free(msg); - nni_atomic_inc(&w->received); - work_send(w, "echo", 5); - break; - case SEND: - echo_start(w); - break; + case RECV: + msg = nng_aio_get_msg(w->aio); + assert(msg != NULL); + assert(nng_msg_len(msg) == 5); + assert(0 == strncmp(nng_msg_body(msg), "ping", 4)); + nng_msg_free(msg); + nni_atomic_inc(&w->received); + work_send(w, "echo", 5); + break; + case SEND: + echo_start(w); + break; } } -#define CLIENTS_COUNT 64 -#define SERVICES_COUNT 8 -#define CLIENT_RX_COUNT 100 -#define TEST_DURATION_MS 3000 -#define SURVEY_TIMEOUT_MS 100 +#define CLIENTS_COUNT 64 +#define SERVICES_COUNT 8 +#define CLIENT_RX_COUNT 100 +#define TEST_DURATION_MS 3000 +#define SURVEY_TIMEOUT_MS 100 void surveyor_open(struct work *w) { w->start = ping_start; NUTS_PASS(nng_surveyor_open(&w->socket)); - NUTS_PASS(nng_socket_set_ms(w->socket, NNG_OPT_SURVEYOR_SURVEYTIME, SURVEY_TIMEOUT_MS)); + NUTS_PASS(nng_socket_set_ms( + w->socket, NNG_OPT_SURVEYOR_SURVEYTIME, SURVEY_TIMEOUT_MS)); NUTS_PASS(nng_aio_alloc(&w->aio, ping_cb, w)); nni_atomic_init(&w->received); } @@ -223,14 +224,14 @@ rep_open(struct work *w) void run_test(work_fn open_service, work_fn open_client) { - int i; - nng_time stop_time; - struct work * service; - struct work * client; - struct work services[SERVICES_COUNT]; - struct work clients [CLIENTS_COUNT]; - - const char * service_urls[SERVICES_COUNT] = { + int i; + nng_time stop_time; + struct work *service; + struct work *client; + struct work services[SERVICES_COUNT]; + struct work clients[CLIENTS_COUNT]; + + const char *service_urls[SERVICES_COUNT] = { "inproc://stressA", "inproc://stressB", "inproc://stressC", diff --git a/src/sp/scalability_test.c b/src/sp/scalability_test.c index 6e9047a1..7579fe7f 100644 --- a/src/sp/scalability_test.c +++ b/src/sp/scalability_test.c @@ -38,7 +38,7 @@ serve(void *arg) if (msg != NULL) { nng_msg_free(msg); } - nng_close(rep); + nng_socket_close(rep); } int diff --git a/src/sp/transport/tcp/tcp_test.c b/src/sp/transport/tcp/tcp_test.c index c8e54a2d..a7ff5e96 100644 --- a/src/sp/transport/tcp/tcp_test.c +++ b/src/sp/transport/tcp/tcp_test.c @@ -198,7 +198,7 @@ test_tcp_recv_max(void) NUTS_TRUE(sz == 95); NUTS_PASS(nng_send(s1, msg, 150, 0)); NUTS_FAIL(nng_recv(s0, buf, &sz, 0), NNG_ETIMEDOUT); - NUTS_PASS(nng_close(s0)); + NUTS_CLOSE(s0); NUTS_CLOSE(s1); } diff --git a/src/sp/transport/tls/tls_tran_test.c b/src/sp/transport/tls/tls_tran_test.c index 6e1835a6..4e3ea00b 100644 --- a/src/sp/transport/tls/tls_tran_test.c +++ b/src/sp/transport/tls/tls_tran_test.c @@ -327,7 +327,7 @@ test_tls_recv_max(void) NUTS_TRUE(sz == 95); NUTS_PASS(nng_send(s1, msg, 150, 0)); NUTS_FAIL(nng_recv(s0, buf, &sz, 0), NNG_ETIMEDOUT); - NUTS_PASS(nng_close(s0)); + NUTS_CLOSE(s0); NUTS_CLOSE(s1); nng_tls_config_free(c0); nng_tls_config_free(c1); @@ -369,7 +369,7 @@ test_tls_psk(void) NUTS_PASS(nng_send(s1, msg, 95, 0)); NUTS_PASS(nng_recv(s0, buf, &sz, 0)); NUTS_TRUE(sz == 95); - NUTS_PASS(nng_close(s0)); + NUTS_CLOSE(s0); NUTS_CLOSE(s1); nng_tls_config_free(c0); nng_tls_config_free(c1); diff --git a/src/sp/transport/udp/udp_tran_test.c b/src/sp/transport/udp/udp_tran_test.c index 014c36dc..b1c3b60a 100644 --- a/src/sp/transport/udp/udp_tran_test.c +++ b/src/sp/transport/udp/udp_tran_test.c @@ -152,7 +152,7 @@ test_udp_recv_max(void) NUTS_TRUE(sz == 95); NUTS_PASS(nng_send(s1, msg, 150, 0)); NUTS_FAIL(nng_recv(s0, buf, &sz, 0), NNG_ETIMEDOUT); - NUTS_PASS(nng_close(s0)); + NUTS_CLOSE(s0); NUTS_CLOSE(s1); } diff --git a/src/supplemental/websocket/wssfile_test.c b/src/supplemental/websocket/wssfile_test.c index ac8ad4b9..7239a1c7 100644 --- a/src/supplemental/websocket/wssfile_test.c +++ b/src/supplemental/websocket/wssfile_test.c @@ -101,8 +101,8 @@ test_invalid_verify(void) NUTS_TRUE((rv == NNG_EPEERAUTH) || (rv == NNG_ECLOSED) || (rv == NNG_ECRYPTO)); - NUTS_PASS(nng_close(s1)); - NUTS_PASS(nng_close(s2)); + NUTS_CLOSE(s1); + NUTS_CLOSE(s2); } static void @@ -202,8 +202,8 @@ test_verify_works(void) NUTS_TRUE(b == true); nng_msg_free(msg); - NUTS_PASS(nng_close(s1)); - NUTS_PASS(nng_close(s2)); + NUTS_CLOSE(s1); + NUTS_CLOSE(s2); } static void @@ -271,8 +271,8 @@ test_tls_config(void) NUTS_TRUE((rv == NNG_EPEERAUTH) || (rv == NNG_ECLOSED) || (rv == NNG_ECRYPTO)); - NUTS_PASS(nng_close(s1)); - NUTS_PASS(nng_close(s2)); + NUTS_CLOSE(s1); + NUTS_CLOSE(s2); } #endif diff --git a/src/testing/nuts.h b/src/testing/nuts.h index 421e0a53..b0c30245 100644 --- a/src/testing/nuts.h +++ b/src/testing/nuts.h @@ -23,7 +23,7 @@ extern void nuts_logger( nng_log_level, nng_log_facility, const char *, const char *); // Call nng_fini during test finalization -- this avoids leak warnings. -// We add a 20 millisecond delay as a hack to allow for other subsytems to +/// We add a 20 millisecond delay as a hack to allow for other subsytems to // drain first. (Notably the HTTP framework can fail if we shut down too // quickly. These bugs should be fixed and then the sleep can be removed.) #ifndef TEST_FINI @@ -285,7 +285,7 @@ extern const char *nuts_ecdsa_client_crt; #define NUTS_OPEN(sock) NUTS_PASS(nng_pair1_open(&(sock))) -#define NUTS_CLOSE(sock) NUTS_PASS(nng_close(sock)) +#define NUTS_CLOSE(sock) NUTS_PASS(nng_socket_close(sock)) #define NUTS_SLEEP(ms) nuts_sleep(ms) diff --git a/src/tools/perf/perf.c b/src/tools/perf/perf.c index c7057c73..1b985c1c 100644 --- a/src/tools/perf/perf.c +++ b/src/tools/perf/perf.c @@ -499,7 +499,7 @@ latency_client(const char *addr, size_t msgsize, int trips) end = nng_clock(); nng_msg_free(msg); - nng_close(s); + nng_socket_close(s); total = (float) ((end - start)) / 1000; latency = ((float) ((total * 1000000)) / (float) (trips * 2)); @@ -544,7 +544,7 @@ latency_server(const char *addr, size_t msgsize, int trips) // Wait a bit for things to drain... linger should do this. // 100ms ought to be enough. nng_msleep(100); - nng_close(s); + nng_socket_close(s); } // Our throughput story is quite a mess. Mostly I think because of the poor @@ -598,7 +598,7 @@ throughput_server(const char *addr, size_t msgsize, int count) // and wait a bit to make sure it goes out the wire. nng_send(s, "", 0, 0); nng_msleep(200); - nng_close(s); + nng_socket_close(s); total = (float) ((end - start)) / 1000; msgpersec = (float) (count) / total; mbps = (float) (msgpersec * 8 * msgsize) / (1024 * 1024); @@ -664,5 +664,5 @@ throughput_client(const char *addr, size_t msgsize, int count) nng_msg_free(msg); } - nng_close(s); + nng_socket_close(s); } diff --git a/src/tools/perf/pubdrop.c b/src/tools/perf/pubdrop.c index 020bae0f..6f0e5553 100644 --- a/src/tools/perf/pubdrop.c +++ b/src/tools/perf/pubdrop.c @@ -179,7 +179,7 @@ pub_server(void *arg) end = nng_clock(); nng_msleep(1000); // drain the queue - nng_close(sock); + nng_socket_close(sock); nng_mtx_lock(pa->mtx); pa->beg = start; diff --git a/tests/cplusplus_pair.cc b/tests/cplusplus_pair.cc index d011c4cd..2a3cc20d 100644 --- a/tests/cplusplus_pair.cc +++ b/tests/cplusplus_pair.cc @@ -62,10 +62,10 @@ main(int argc, char **argv) if ((sz != 4) || (memcmp(buf, "DEF", 4) != 0)) { throw "Contents did not match"; } - if ((rv = nng_close(s1)) != 0) { + if ((rv = nng_socket_close(s1)) != 0) { throw nng_strerror(rv); } - if ((rv = nng_close(s2)) != 0) { + if ((rv = nng_socket_close(s2)) != 0) { throw nng_strerror(rv); } diff --git a/tests/trantest.h b/tests/trantest.h index 783f3767..e84ca87b 100644 --- a/tests/trantest.h +++ b/tests/trantest.h @@ -126,8 +126,8 @@ trantest_init(trantest *tt, const char *addr) void trantest_fini(trantest *tt) { - nng_close(tt->reqsock); - nng_close(tt->repsock); + nng_socket_close(tt->reqsock); + nng_socket_close(tt->repsock); } int -- cgit v1.2.3-70-g09d2