From 81f5d3c6268ff91ee9c36c4cb34f6f9bfd54740d Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 12 Dec 2024 17:55:48 -0800 Subject: 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. --- src/core/sockfd.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/core/sockfd.c') 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; -- cgit v1.2.3-70-g09d2