aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-22 12:41:44 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-22 12:41:44 -0800
commit113e3606bd1a763850db1afee336bb0d5d434317 (patch)
tree681bb2f8d71c399fbfe4502b8573ce9e3d9a8fe1 /src/supplemental
parent8c14ed19b5c72f060f31767e5bc4106054e41192 (diff)
downloadnng-113e3606bd1a763850db1afee336bb0d5d434317.tar.gz
nng-113e3606bd1a763850db1afee336bb0d5d434317.tar.bz2
nng-113e3606bd1a763850db1afee336bb0d5d434317.zip
http: nng_http_handler_set_data is now void return (API break)
Diffstat (limited to 'src/supplemental')
-rw-r--r--src/supplemental/http/http_api.h2
-rw-r--r--src/supplemental/http/http_public.c5
-rw-r--r--src/supplemental/http/http_server.c32
-rw-r--r--src/supplemental/websocket/websocket.c4
4 files changed, 11 insertions, 32 deletions
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);
}