diff options
| author | Garrett D'Amore <garrett@damore.org> | 2025-01-01 15:27:25 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2025-01-01 15:27:25 -0800 |
| commit | 59f6d721c62898b58c8ed434a839c8ab3ad9ee01 (patch) | |
| tree | b2011a32c9eb6f7f98182d7dcfa400dd2d29d48d /demo/rest | |
| parent | 7be90706a18c84a63d5f13c7b1379215534c4da6 (diff) | |
| download | nng-59f6d721c62898b58c8ed434a839c8ab3ad9ee01.tar.gz nng-59f6d721c62898b58c8ed434a839c8ab3ad9ee01.tar.bz2 nng-59f6d721c62898b58c8ed434a839c8ab3ad9ee01.zip | |
demo: fix rest server (must initialize NNG library)
Diffstat (limited to 'demo/rest')
| -rw-r--r-- | demo/rest/server.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/demo/rest/server.c b/demo/rest/server.c index 1e1ccc96..96cdc79c 100644 --- a/demo/rest/server.c +++ b/demo/rest/server.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -147,6 +147,7 @@ rest_http_fatal(rest_job *job, const char *fmt, int rv) snprintf(buf, sizeof(buf), fmt, nng_strerror(rv)); nng_http_res_set_status(res, NNG_HTTP_STATUS_INTERNAL_SERVER_ERROR); nng_http_res_set_reason(res, buf); + nng_aio_set_output(aio, 0, res); nng_aio_finish(aio, 0); rest_recycle_job(job); @@ -277,7 +278,7 @@ rest_start(uint16_t port) // Allocate the handler - we use a dynamic handler for REST // using the function "rest_handle" declared above. - rv = nng_http_handler_alloc(&handler, url->u_path, rest_handle); + rv = nng_http_handler_alloc(&handler, nng_url_path(url), rest_handle); if (rv != 0) { fatal("nng_http_handler_alloc", rv); } @@ -353,6 +354,9 @@ main(int argc, char **argv) nng_thread *inproc_thr; uint16_t port = 0; + if ((rv = nng_init(NULL)) != 0) { + fatal("cannot init NNG", rv); + } rv = nng_thread_create(&inproc_thr, inproc_server, NULL); if (rv != 0) { fatal("cannot start inproc server", rv); @@ -366,4 +370,5 @@ main(int argc, char **argv) // This runs forever. The inproc_thr never exits, so we // just block behind its condition variable. nng_thread_destroy(inproc_thr); + nng_fini(); } |
