Skip to content

Commit

Permalink
nng_fini: Simpler clean up of sockets, add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Dec 1, 2024
1 parent 3904684 commit 11503fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/core/init_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ test_init_concurrent(void)
nng_fini();
}

void
test_fini_closes_socket(void)
{
nng_socket s;
NUTS_OPEN(s);
nng_fini();
NUTS_FAIL(nng_close(s), NNG_ECLOSED);
}

NUTS_TESTS = {
{ "init parameter", test_init_param },
{ "init zero resolvers", test_init_zero_resolvers },
Expand All @@ -203,6 +212,7 @@ NUTS_TESTS = {
{ "init too many poller threads", test_init_too_many_poller_threads },
{ "init repeated", test_init_repeated },
{ "init concurrent", test_init_concurrent },
{ "fini closes socket", test_fini_closes_socket },

{ NULL, NULL },
};
12 changes: 1 addition & 11 deletions src/core/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,19 +706,9 @@ nni_sock_closeall(void)
nni_sock *s;
uint32_t next = 0;

nni_mtx_lock(&sock_lk);
while (nni_id_visit(&sock_ids, NULL, (void **) &s, &next)) {
if (nni_atomic_flag_test_and_set(&s->s_close_once)) {
continue;
}
s->s_closed = true;
nni_id_remove(&sock_ids, s->s_id);

sock_close_children(s);

nni_reap(&sock_reap_list, s);
nni_sock_close(s);
}
nni_mtx_unlock(&sock_lk);
}

void
Expand Down

0 comments on commit 11503fc

Please sign in to comment.