diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-30 14:27:43 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-30 14:27:43 -0800 |
| commit | a74d853241fa21ef4b6352fd39c25b4d4c6a4ab3 (patch) | |
| tree | d501426eab2f3dc641d9b67ac922bcc2dafd5a32 | |
| parent | fcc39223cfbd68d14a30b32a8be4f3fe0ab25e1c (diff) | |
| download | nng-a74d853241fa21ef4b6352fd39c25b4d4c6a4ab3.tar.gz nng-a74d853241fa21ef4b6352fd39c25b4d4c6a4ab3.tar.bz2 nng-a74d853241fa21ef4b6352fd39c25b4d4c6a4ab3.zip | |
ipc/tcp stream tests: use dup() to avoid confusion and hang in teardown
This was observed only in the select poller, but the behavior of having
the same file descriptor registered in the poller more than once is undefined.
| -rw-r--r-- | src/platform/ipc_stream_test.c | 5 | ||||
| -rw-r--r-- | src/platform/tcp_stream_test.c | 10 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/platform/ipc_stream_test.c b/src/platform/ipc_stream_test.c index e1ee86b0..7e5e7701 100644 --- a/src/platform/ipc_stream_test.c +++ b/src/platform/ipc_stream_test.c @@ -133,6 +133,11 @@ test_ipc_listen_activation(void) NUTS_PASS(nng_stream_dialer_alloc(&d, addr)); NUTS_PASS(nng_stream_listener_get_int(l1, NNG_OPT_LISTEN_FD, &fd)); + fd = dup(fd); + // dupe this because we need to separate the file descriptors to + // prevent confusion when we clean up (only one FD can be registered at + // a time!) + NUTS_ASSERT(fd >= -1); NUTS_PASS(nng_stream_listener_alloc(&l2, addr)); NUTS_PASS(nng_stream_listener_set_int(l2, NNG_OPT_LISTEN_FD, fd)); nng_stream_dialer_dial(d, aio2); diff --git a/src/platform/tcp_stream_test.c b/src/platform/tcp_stream_test.c index b9c20844..e2ca694b 100644 --- a/src/platform/tcp_stream_test.c +++ b/src/platform/tcp_stream_test.c @@ -115,10 +115,6 @@ test_tcp_stream(void) NUTS_TRUE(sa2.s_in.sa_addr == sa.s_in.sa_addr); NUTS_TRUE(sa2.s_in.sa_port == sa.s_in.sa_port); - nng_stream_listener_close(l); - nng_stream_dialer_close(d); - nng_stream_listener_stop(l); - nng_stream_dialer_stop(d); nng_stream_listener_free(l); nng_stream_dialer_free(d); nng_aio_free(aio1); @@ -214,6 +210,12 @@ test_tcp_listen_activation(void) NUTS_PASS(nng_stream_dialer_alloc(&d, url)); NUTS_PASS(nng_stream_listener_get_int(l1, NNG_OPT_LISTEN_FD, &fd)); + fd = dup(fd); + // dupe this because we need to separate the file descriptors to + // prevent confusion when we clean up (only one FD can be registered at + // a time!) + NUTS_ASSERT(fd >= -1); + NUTS_PASS(nng_stream_listener_alloc(&l2, "tcp4://")); NUTS_PASS(nng_stream_listener_set_int(l2, NNG_OPT_LISTEN_FD, fd)); nng_stream_dialer_dial(d, aio2); |
