diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-12 17:55:48 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-12 17:55:48 -0800 |
| commit | 81f5d3c6268ff91ee9c36c4cb34f6f9bfd54740d (patch) | |
| tree | f9f21aa66bd22cfd95ae0c4b8abe57036c8fce0d /src/core/stream.c | |
| parent | 371eedeeb6fafe628ae89b9ad2690fa3d6a57e8a (diff) | |
| download | nng-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/stream.c')
| -rw-r--r-- | src/core/stream.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/core/stream.c b/src/core/stream.c index ad026586..16e11eca 100644 --- a/src/core/stream.c +++ b/src/core/stream.c @@ -116,7 +116,17 @@ static struct { void nng_stream_close(nng_stream *s) { - s->s_close(s); + if (s != NULL) { + s->s_close(s); + } +} + +void +nng_stream_stop(nng_stream *s) +{ + if (s != NULL) { + s->s_stop(s); + } } void @@ -149,7 +159,17 @@ nni_stream_get( void nng_stream_dialer_close(nng_stream_dialer *d) { - d->sd_close(d); + if (d != NULL) { + d->sd_close(d); + } +} + +void +nng_stream_dialer_stop(nng_stream_dialer *d) +{ + if (d != NULL) { + d->sd_stop(d); + } } void @@ -226,8 +246,19 @@ nni_stream_dialer_set_tls(nng_stream_dialer *d, nng_tls_config *cfg) void nng_stream_listener_close(nng_stream_listener *l) { - l->sl_close(l); + if (l != NULL) { + l->sl_close(l); + } +} + +void +nng_stream_listener_stop(nng_stream_listener *l) +{ + if (l != NULL) { + l->sl_stop(l); + } } + void nng_stream_listener_free(nng_stream_listener *l) { |
