From 301de3ac5c7cf8a5eaaf3c58157251db781841d6 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 24 May 2018 14:59:39 -0700 Subject: fixes #486 Revisit SOVERSION and VERSION fixes #485 Honor BUILD_SHARED_LIBS fixes #483 Don't expose private symbols in shared library fixes #481 Export CMake target This is a "large" commit involving changes that don't affect the code directly, but which have an impact on how we package and build our project. The most significant of these changes is that we now build only either a shared or a static library, depending on the setting of the BUILD_SHARED_LIBS option. We also suppress private symbols from being exposed when the underlying toolchain lets us do so. Minor updates to the way we version the ABI are used, and we now have a nice exported CMake project. To import this project in another, simply do find_package(nng) and you can add target_link_libraries(nng::nng) to your targets. CMake does the rest for you. --- demo/rest/CMakeLists.txt | 17 +++++++++++++++++ demo/rest/README.adoc | 24 ++++++++++++++++++++++-- demo/rest/server.c | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 demo/rest/CMakeLists.txt (limited to 'demo/rest') diff --git a/demo/rest/CMakeLists.txt b/demo/rest/CMakeLists.txt new file mode 100644 index 00000000..5466e3c7 --- /dev/null +++ b/demo/rest/CMakeLists.txt @@ -0,0 +1,17 @@ +# +# Copyright 2018 Capitar IT Group BV +# Copyright 2018 Staysail Systems, Inc. +# +# This software is supplied under the terms of the MIT License, a +# copy of which should be located in the distribution where this +# file was obtained (LICENSE.txt). A copy of the license may also be +# found online at https://opensource.org/licenses/MIT. + +cmake_minimum_required (VERSION 2.8.7) + +project(rest) + +find_package(nng CONFIG REQUIRED) + +add_executable(rest-server server.c) +target_link_libraries(rest-server nng::nng) diff --git a/demo/rest/README.adoc b/demo/rest/README.adoc index 6a363329..df3e30b0 100644 --- a/demo/rest/README.adoc +++ b/demo/rest/README.adoc @@ -3,7 +3,7 @@ This is a somewhat contrived demonstration, but may be useful in a pattern for solving real world problems. -There is a single "server" program, that does these: +There is a single "server" (rest-server) program, that does these: . REST API at /api/rest/rot13 - this API takes data from HTTP POST commands, and forwards them to an NNG REQ socket. When the REQ response comes, @@ -17,9 +17,29 @@ There is a single "server" program, that does these: [source, bash] ---- % env PORT=8888 # default -% ./server & +% ./rest-server & % curl -d ABC http://127.0.0.1:8888/api/rest/rot13; echo NOP % curl -d ABC http://127.0.0.1:8888/api/rest/rot13; echo ABC ---- + +== Compiling + +To build the program, we recommend CMake and Ninja-Build. + +[source, bash] +---- +% mkdir build +% cd build +% cmake -G Ninja .. +% ninja +---- + +Alternatively, you can go old-school. +Here's the simplest option for Linux: + +[source, bash] +---- +% cc server.c -o rest-server -I /usr/local/include -lnng +---- diff --git a/demo/rest/server.c b/demo/rest/server.c index 788fc8f1..72c24cb1 100644 --- a/demo/rest/server.c +++ b/demo/rest/server.c @@ -98,7 +98,7 @@ rest_free_job(rest_job *job) if (job->msg != NULL) { nng_msg_free(job->msg); } - if (job->ctx != 0) { + if (nng_ctx_id(job->ctx) != 0) { nng_ctx_close(job->ctx); } free(job); -- cgit v1.2.3-70-g09d2