aboutsummaryrefslogtreecommitdiff
path: root/src/core/sockfd.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-12 17:55:48 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-12 17:55:48 -0800
commit81f5d3c6268ff91ee9c36c4cb34f6f9bfd54740d (patch)
treef9f21aa66bd22cfd95ae0c4b8abe57036c8fce0d /src/core/sockfd.c
parent371eedeeb6fafe628ae89b9ad2690fa3d6a57e8a (diff)
downloadnng-81f5d3c6268ff91ee9c36c4cb34f6f9bfd54740d.tar.gz
nng-81f5d3c6268ff91ee9c36c4cb34f6f9bfd54740d.tar.bz2
nng-81f5d3c6268ff91ee9c36c4cb34f6f9bfd54740d.zip
streams: add explicit stop functions
This allows us to explicitly stop streams, dialers, and listeners, before we start tearing down things. This hopefully will be useful in resolving use-after-free bugs in http, tls, and websockets. The new functions are not yet documented, but they are nng_stream_stop, nng_stream_dialer_stop, and nng_stream_listener_stop. They should be called after close, and before free. The close functions now close without blocking, but the stop function is allowed to block.
Diffstat (limited to 'src/core/sockfd.c')
-rw-r--r--src/core/sockfd.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/core/sockfd.c b/src/core/sockfd.c
index cedd7436..787a0783 100644
--- a/src/core/sockfd.c
+++ b/src/core/sockfd.c
@@ -63,6 +63,12 @@ sfd_listener_close(void *arg)
nni_mtx_unlock(&l->mtx);
}
+static void
+sfd_listener_stop(void *arg)
+{
+ sfd_listener_close(arg);
+}
+
static int
sfd_listener_listen(void *arg)
{
@@ -222,6 +228,7 @@ nni_sfd_listener_alloc(nng_stream_listener **lp, const nng_url *url)
l->ops.sl_free = sfd_listener_free;
l->ops.sl_close = sfd_listener_close;
+ l->ops.sl_stop = sfd_listener_stop;
l->ops.sl_listen = sfd_listener_listen;
l->ops.sl_accept = sfd_listener_accept;
l->ops.sl_get = sfd_listener_get;