From 85927b8d0d0a751e4c65849c392ef9d0e42a1bd7 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 5 Nov 2024 22:25:24 -0800 Subject: ipc: listener cancellation test --- .github/workflows/coverage.yml | 2 +- src/platform/posix/posix_ipcdial.c | 14 +++++++------- src/platform/posix/posix_ipclisten.c | 19 +++++++++---------- src/sp/transport/ipc/ipc_test.c | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 30e3ff2a..22949659 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -27,7 +27,7 @@ jobs: uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} - yml: ./.codecov.yml + codecov_yml_path: ./.codecov.yml darwin-coverage: name: darwin diff --git a/src/platform/posix/posix_ipcdial.c b/src/platform/posix/posix_ipcdial.c index 6cbd7c17..81a8f1dc 100644 --- a/src/platform/posix/posix_ipcdial.c +++ b/src/platform/posix/posix_ipcdial.c @@ -80,7 +80,7 @@ static void ipc_dialer_cancel(nni_aio *aio, void *arg, int rv) { nni_ipc_dialer *d = arg; - nni_ipc_conn * c; + nni_ipc_conn *c; nni_mtx_lock(&d->mtx); if ((!nni_aio_list_active(aio)) || @@ -100,9 +100,9 @@ ipc_dialer_cancel(nni_aio *aio, void *arg, int rv) static void ipc_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg) { - nni_ipc_conn * c = arg; + nni_ipc_conn *c = arg; nni_ipc_dialer *d = c->dialer; - nni_aio * aio; + nni_aio *aio; int rv; nni_mtx_lock(&d->mtx); @@ -153,9 +153,9 @@ ipc_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg) void ipc_dialer_dial(void *arg, nni_aio *aio) { - ipc_dialer * d = arg; - nni_ipc_conn * c; - nni_posix_pfd * pfd = NULL; + ipc_dialer *d = arg; + nni_ipc_conn *c; + nni_posix_pfd *pfd = NULL; struct sockaddr_storage ss; size_t len; int fd; @@ -205,7 +205,7 @@ ipc_dialer_dial(void *arg, nni_aio *aio) goto error; } if (connect(fd, (void *) &ss, len) != 0) { - if (errno != EINPROGRESS) { + if (errno != EINPROGRESS && errno != EAGAIN) { if (errno == ENOENT) { // No socket present means nobody listening. rv = NNG_ECONNREFUSED; diff --git a/src/platform/posix/posix_ipclisten.c b/src/platform/posix/posix_ipclisten.c index 0fd70851..bd938841 100644 --- a/src/platform/posix/posix_ipclisten.c +++ b/src/platform/posix/posix_ipclisten.c @@ -31,12 +31,12 @@ typedef struct { nng_stream_listener sl; - nni_posix_pfd * pfd; + nni_posix_pfd *pfd; nng_sockaddr sa; nni_list acceptq; bool started; bool closed; - char * path; + char *path; mode_t perms; nni_mtx mtx; } ipc_listener; @@ -45,7 +45,7 @@ static void ipc_listener_doclose(ipc_listener *l) { nni_aio *aio; - char * path; + char *path; l->closed = true; while ((aio = nni_list_first(&l->acceptq)) != NULL) { @@ -82,7 +82,7 @@ ipc_listener_doaccept(ipc_listener *l) int fd; int rv; nni_posix_pfd *pfd; - nni_ipc_conn * c; + nni_ipc_conn *c; fd = nni_posix_pfd_fd(l->pfd); @@ -302,13 +302,13 @@ ipc_listener_chmod(ipc_listener *l, const char *path) int ipc_listener_listen(void *arg) { - ipc_listener * l = arg; + ipc_listener *l = arg; socklen_t len; struct sockaddr_storage ss; int rv; int fd; - nni_posix_pfd * pfd; - char * path; + nni_posix_pfd *pfd; + char *path; if ((len = nni_posix_nn2sockaddr(&ss, &l->sa)) < sizeof(sa_family_t)) { return (NNG_EADDRINVAL); @@ -358,8 +358,7 @@ ipc_listener_listen(void *arg) } } - if ((rv != 0) || - (ipc_listener_chmod(l, path) != 0) || + if ((rv != 0) || (ipc_listener_chmod(l, path) != 0) || (listen(fd, 128) != 0)) { rv = nni_plat_errno(errno); } @@ -407,7 +406,7 @@ ipc_listener_listen(void *arg) static void ipc_listener_free(void *arg) { - ipc_listener * l = arg; + ipc_listener *l = arg; nni_posix_pfd *pfd; nni_mtx_lock(&l->mtx); diff --git a/src/sp/transport/ipc/ipc_test.c b/src/sp/transport/ipc/ipc_test.c index f3ce8d41..083326bb 100644 --- a/src/sp/transport/ipc/ipc_test.c +++ b/src/sp/transport/ipc/ipc_test.c @@ -229,6 +229,27 @@ test_ipc_connect_blocking_accept(void) nng_stream_listener_free(l); } +void +test_ipc_listen_accept_cancel(void) +{ + nng_stream_listener *l; + char *addr; + nng_aio *aio; + + NUTS_ENABLE_LOG(NNG_LOG_INFO); + NUTS_ADDR(addr, "ipc"); + NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); + + // start a listening stream listener but do not call accept + NUTS_PASS(nng_stream_listener_alloc(&l, addr)); + NUTS_PASS(nng_stream_listener_listen(l)); + nng_stream_listener_accept(l, aio); + nng_msleep(100); + nng_aio_free(aio); + nng_stream_listener_close(l); + nng_stream_listener_free(l); +} + void test_ipc_listener_clean_stale(void) { @@ -539,6 +560,7 @@ TEST_LIST = { { "ipc connect blocking", test_ipc_connect_blocking }, { "ipc connect blocking accept", test_ipc_connect_blocking_accept }, { "ipc listen cleanup stale", test_ipc_listener_clean_stale }, + { "ipc listen accept cancel", test_ipc_listen_accept_cancel }, { "ipc abstract sockets", test_abstract_sockets }, { "ipc abstract auto bind", test_abstract_auto_bind }, { "ipc abstract name too long", test_abstract_too_long }, -- cgit v1.2.3-70-g09d2