diff options
| -rw-r--r-- | docs/man/nng_http_handler_set_data.3http.adoc | 14 | ||||
| -rw-r--r-- | docs/ref/migrate/nng1.md | 6 | ||||
| -rw-r--r-- | include/nng/supplemental/http/http.h | 2 | ||||
| -rw-r--r-- | src/supplemental/http/http_api.h | 2 | ||||
| -rw-r--r-- | src/supplemental/http/http_public.c | 5 | ||||
| -rw-r--r-- | src/supplemental/http/http_server.c | 32 | ||||
| -rw-r--r-- | src/supplemental/websocket/websocket.c | 4 |
7 files changed, 19 insertions, 46 deletions
diff --git a/docs/man/nng_http_handler_set_data.3http.adoc b/docs/man/nng_http_handler_set_data.3http.adoc index cb94adbc..94cb9b4c 100644 --- a/docs/man/nng_http_handler_set_data.3http.adoc +++ b/docs/man/nng_http_handler_set_data.3http.adoc @@ -1,6 +1,6 @@ = nng_http_handler_set_data(3http) // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This document is supplied under the terms of the MIT License, a @@ -20,7 +20,7 @@ nng_http_handler_set_data - set extra data for HTTP handler #include <nng/nng.h> #include <nng/supplemental/http/http.h> -int nng_http_handler_set_data(nng_http_handler *handler, void *data, +void nng_http_handler_set_data(nng_http_handler *handler, void *data, void (*dtor)(void *)); ---- @@ -36,16 +36,6 @@ then it will be called with _data_ as its argument. The intended use of this function is deallocate any resources associated with _data_. -== RETURN VALUES - -This function returns 0 on success, and non-zero otherwise. - -== ERRORS - -[horizontal] -`NNG_ENOMEM`:: Insufficient free memory to perform the operation. -`NNG_ENOTSUP`:: No support for HTTP in the library. - == SEE ALSO [.text-left] diff --git a/docs/ref/migrate/nng1.md b/docs/ref/migrate/nng1.md index 8186e5cb..4390de24 100644 --- a/docs/ref/migrate/nng1.md +++ b/docs/ref/migrate/nng1.md @@ -230,16 +230,20 @@ they may be silently truncated to the limit: - The fixed part of URI pathnames used with HTTP handlers is limited to 1024 bytes. The following API calls have changed so that they are `void` returns, and cannot fail. -They may silently truncate data, and the handler methods may not have any effect if the handler is already in use. +They may silently truncate data. - [`nng_http_req_set_method`] - [`nng_http_res_set_status`] - [`nng_http_handler_collect_body`] +- [`nng_http_handler_set_data`] - [`nng_http_handler_set_host`] - [`nng_http_handler_set_method`] - [`nng_http_handler_set_tree`] - [`nng_http_handler_set_tree_exclusive`] +The HTTP handler objects may not be modified once in use. Previously this would fail with `NNG_EBUSY`. +These checks are removed now, but debug builds will assert if an application tries to do so. + ## Security Descriptors (Windows Only) The `NNG_OPT_IPC_SECURITY_DESCRIPTOR` option is removed, and replaced diff --git a/include/nng/supplemental/http/http.h b/include/nng/supplemental/http/http.h index e94aa0b3..f00c63a9 100644 --- a/include/nng/supplemental/http/http.h +++ b/include/nng/supplemental/http/http.h @@ -392,7 +392,7 @@ NNG_DECL void nng_http_handler_set_tree_exclusive(nng_http_handler *); // a possible clean up routine. (The clean up is a custom de-allocator and // will be called with the supplied data as an argument, when the handler // is being de-allocated.) -NNG_DECL int nng_http_handler_set_data( +NNG_DECL void nng_http_handler_set_data( nng_http_handler *, void *, void (*)(void *)); // nng_http_handler_get_data returns the data that was previously stored. diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h index 47e46b53..5e2d52fa 100644 --- a/src/supplemental/http/http_api.h +++ b/src/supplemental/http/http_api.h @@ -338,7 +338,7 @@ extern void nni_http_handler_set_method(nni_http_handler *, const char *); // which will be available to the callback via nni_http_handler_get_data. // The callback is an optional destructor, and will be called with the // data as its argument, when the handler is being destroyed. -extern int nni_http_handler_set_data(nni_http_handler *, void *, nni_cb); +extern void nni_http_handler_set_data(nni_http_handler *, void *, nni_cb); // nni_http_handler_get_data returns the data that was previously stored // by nni_http_handler_set_data. diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index 1dccbdf6..49638b66 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -637,16 +637,15 @@ nng_http_handler_set_tree_exclusive(nng_http_handler *h) #endif } -int +void nng_http_handler_set_data(nng_http_handler *h, void *dat, void (*dtor)(void *)) { #ifdef NNG_SUPP_HTTP - return (nni_http_handler_set_data(h, dat, dtor)); + nni_http_handler_set_data(h, dat, dtor); #else NNI_ARG_UNUSED(h); NNI_ARG_UNUSED(dat); NNI_ARG_UNUSED(dtor); - return (NNG_ENOTSUP); #endif } diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index 38204ca5..82f11eac 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -154,15 +154,12 @@ nni_http_handler_collect_body(nni_http_handler *h, bool want, size_t maxbody) h->maxbody = maxbody; } -int +void nni_http_handler_set_data(nni_http_handler *h, void *data, nni_cb dtor) { - if (nni_atomic_get_bool(&h->busy)) { - return (NNG_EBUSY); - } + NNI_ASSERT(!nni_atomic_get_bool(&h->busy)); h->data = data; h->dtor = dtor; - return (0); } void * @@ -1448,11 +1445,7 @@ nni_http_handler_init_file_ctype(nni_http_handler **hpp, const char *uri, return (rv); } - if ((rv = nni_http_handler_set_data(h, hf, http_file_free)) != 0) { - http_file_free(hf); - nni_http_handler_fini(h); - return (rv); - } + nni_http_handler_set_data(h, hf, http_file_free); // We don't permit a body for getting a file. nni_http_handler_collect_body(h, true, 0); @@ -1624,12 +1617,7 @@ nni_http_handler_init_directory( // We don't permit a body for getting a file. nni_http_handler_collect_body(h, true, 0); nni_http_handler_set_tree_exclusive(h); - - if ((rv = nni_http_handler_set_data(h, hf, http_file_free)) != 0) { - http_file_free(hf); - nni_http_handler_fini(h); - return (rv); - } + nni_http_handler_set_data(h, hf, http_file_free); *hpp = h; return (0); @@ -1747,11 +1735,7 @@ nni_http_handler_init_redirect(nni_http_handler **hpp, const char *uri, nni_http_handler_set_method(h, NULL); - if ((rv = nni_http_handler_set_data(h, hr, http_redirect_free)) != 0) { - http_redirect_free(hr); - nni_http_handler_fini(h); - return (rv); - } + nni_http_handler_set_data(h, hr, http_redirect_free); // We don't need to collect the body at all, because the handler // just discards the content and closes the connection. @@ -1833,11 +1817,7 @@ nni_http_handler_init_static(nni_http_handler **hpp, const char *uri, return (rv); } - if ((rv = nni_http_handler_set_data(h, hs, http_static_free)) != 0) { - http_static_free(hs); - nni_http_handler_fini(h); - return (rv); - } + nni_http_handler_set_data(h, hs, http_static_free); // We don't permit a body for getting static data. nni_http_handler_collect_body(h, true, 0); diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index ba304149..b7afc938 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -2151,9 +2151,9 @@ nni_ws_listener_alloc(nng_stream_listener **wslp, const nng_url *url) } nni_http_handler_set_host(l->handler, host); + nni_http_handler_set_data(l->handler, l, 0); - if (((rv = nni_http_handler_set_data(l->handler, l, 0)) != 0) || - ((rv = nni_http_server_init(&l->server, url)) != 0)) { + if ((rv = nni_http_server_init(&l->server, url)) != 0) { ws_listener_free(l); return (rv); } |
