diff options
Diffstat (limited to 'demo')
| -rw-r--r-- | demo/async/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | demo/async/README.adoc | 9 | ||||
| -rw-r--r-- | demo/http_client/CMakeLists.txt | 18 | ||||
| -rw-r--r-- | demo/http_client/README.adoc | 12 | ||||
| -rw-r--r-- | demo/http_client/http_client.c | 1 | ||||
| -rw-r--r-- | demo/raw/CMakeLists.txt | 20 | ||||
| -rw-r--r-- | demo/raw/README.adoc | 35 | ||||
| -rw-r--r-- | demo/raw/raw.c (renamed from demo/raw/async.c) | 0 | ||||
| -rw-r--r-- | demo/reqrep/CMakeLists.txt | 17 | ||||
| -rw-r--r-- | demo/reqrep/README.adoc | 15 | ||||
| -rw-r--r-- | demo/rest/CMakeLists.txt | 17 | ||||
| -rw-r--r-- | demo/rest/README.adoc | 24 | ||||
| -rw-r--r-- | demo/rest/server.c | 2 |
13 files changed, 174 insertions, 20 deletions
diff --git a/demo/async/CMakeLists.txt b/demo/async/CMakeLists.txt new file mode 100644 index 00000000..614bcfc3 --- /dev/null +++ b/demo/async/CMakeLists.txt @@ -0,0 +1,24 @@ +# +# Copyright 2018 Capitar IT Group BV <info@capitar.com> +# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +# +# 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(nng-asyncdemo) + +set(PARALLEL 128 CACHE STRING "Parallelism (min 4, max 1000)") + +# Call this from your own project's makefile. +find_package(nng CONFIG REQUIRED) + +add_executable(server server.c) +target_link_libraries(server nng::nng) +target_compile_definitions(server PRIVATE -DPARALLEL=${PARALLEL}) + +add_executable(client client.c) +target_link_libraries(client nng::nng) diff --git a/demo/async/README.adoc b/demo/async/README.adoc index ec91c722..87c44cec 100644 --- a/demo/async/README.adoc +++ b/demo/async/README.adoc @@ -6,8 +6,11 @@ processing with minimal fuss. == Compiling -You can override the level of concurrency with the `PARALLEL` -define. This determines how many requests the server will accept +This is set up for configuration with CMake for ease of use. + +You can override the level of concurrency with the `PARALLEL` option. + +This determines how many requests the server will accept at a time, and keep outstanding. Note that for our toy implementation, we create this many "logical" flows of execution (contexts) (these are _NOT_ threads), where a request is followed by a reply. @@ -20,6 +23,8 @@ you can't have more than one client per descriptor. Contexts can be used on the client side to support many thousands of concurrent requests over even just a single TCP connection, however.) +You can also build this all by hand with Make or whatever. + On UNIX-style systems: [source, bash] diff --git a/demo/http_client/CMakeLists.txt b/demo/http_client/CMakeLists.txt new file mode 100644 index 00000000..3fe126f9 --- /dev/null +++ b/demo/http_client/CMakeLists.txt @@ -0,0 +1,18 @@ +# +# Copyright 2018 Capitar IT Group BV <info@capitar.com> +# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +# +# 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(http_client) + +# Call this from your own project's makefile. +find_package(nng CONFIG REQUIRED) + +add_executable(http_client http_client.c) +target_link_libraries(http_client nng::nng) diff --git a/demo/http_client/README.adoc b/demo/http_client/README.adoc index a0fb54e4..f8777557 100644 --- a/demo/http_client/README.adoc +++ b/demo/http_client/README.adoc @@ -30,6 +30,17 @@ Linux and macOS: % ${CC} ${CPPFLAGS} http_client.c -o http_client ${LDFLAGS} ---- +Alternatively, CMake can be used. Here's an example if you have +Ninja build handy (highly recommended): + +[source, bash] +---- +% mkdir build +% cd build +% cmake -G Ninja .. +% ninja +---- + == Running Make sure you specify the full URL (if the root page include @@ -39,4 +50,3 @@ the simple "/". The URL parser does not add it for you automatically.) ---- % ./http_client http://httpbin.org/ip ---- - diff --git a/demo/http_client/http_client.c b/demo/http_client/http_client.c index 522c1cd1..a00c842f 100644 --- a/demo/http_client/http_client.c +++ b/demo/http_client/http_client.c @@ -34,6 +34,7 @@ // #include <nng/nng.h> +#include <nng/supplemental/http/http.h> #include <stdio.h> #include <stdlib.h> diff --git a/demo/raw/CMakeLists.txt b/demo/raw/CMakeLists.txt new file mode 100644 index 00000000..15e481d5 --- /dev/null +++ b/demo/raw/CMakeLists.txt @@ -0,0 +1,20 @@ +# +# Copyright 2018 Capitar IT Group BV <info@capitar.com> +# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +# +# 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(raw) + +set(PARALLEL 128 CACHE STRING "Parallelism (min 4, max 1000)") + +find_package(nng CONFIG REQUIRED) + +add_executable(raw raw.c) +target_link_libraries(raw nng::nng) +target_compile_definitions(raw PRIVATE -DPARALLEL=${PARALLEL}) diff --git a/demo/raw/README.adoc b/demo/raw/README.adoc index 35290616..2190dc49 100644 --- a/demo/raw/README.adoc +++ b/demo/raw/README.adoc @@ -1,14 +1,15 @@ -= async += raw This is a simple asynchronous demo, that demonstrates use of the RAW -option with a server, along with async message handling, to obtain a +sockets with a server, along with async message handling, to obtain a very high level of asynchronous operation, suitable for use in a highly concurrent server application. == Compiling -You can override the level of concurrency with the `PARALLEL` -define. This determines how many requests the server will accept +You can override the level of concurrency with the `PARALLEL` option. + +This determines how many requests the server will accept at a time, and keep outstanding. Note that for our toy implementation, we create this many "logical" flows of execution (these are _NOT_ threads), where a request is followed by a reply. @@ -16,14 +17,24 @@ implementation, we create this many "logical" flows of execution The value of `PARALLEL` must be at least one, and may be as large as your memory will permit. (The default value is 32.) -On UNIX-style systems: +The best way to build is using cmake and Ninja build: + +[source, bash] +---- +% mkdir build +% cd build +% cmake -G Ninja .. +% ninja +---- + +You can also build the hard way. For example, on UNIX-style systems: [source, bash] ---- % export CPPFLAGS="-D PARALLEL=32 -I /usr/local/include" % export LDFLAGS="-L /usr/local/lib -lnng" % export CC="cc" -% ${CC} ${CPPFLAGS} async.c -o async ${LDFLAGS} +% ${CC} ${CPPFLAGS} raw.c -o raw ${LDFLAGS} ---- == Running @@ -42,12 +53,12 @@ In the following example, all of the clients should complete within ---- % export URL="tcp://127.0.0.1:55995" # start the server -% ./async $URL -s & +% ./raw $URL -s & # start a bunch of clients # Note that these all run concurrently! -% ./async $URL 2 & -% ./async $URL 2 & -% ./async $URL 2 & -% ./async $URL 2 & -% ./async $URL 2 & +% ./raw $URL 2 & +% ./raw $URL 2 & +% ./raw $URL 2 & +% ./raw $URL 2 & +% ./raw $URL 2 & ---- diff --git a/demo/raw/async.c b/demo/raw/raw.c index 0285d8d2..0285d8d2 100644 --- a/demo/raw/async.c +++ b/demo/raw/raw.c diff --git a/demo/reqrep/CMakeLists.txt b/demo/reqrep/CMakeLists.txt new file mode 100644 index 00000000..d6982446 --- /dev/null +++ b/demo/reqrep/CMakeLists.txt @@ -0,0 +1,17 @@ +# +# Copyright 2018 Capitar IT Group BV <info@capitar.com> +# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +# +# 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(reqrep) + +find_package(nng CONFIG REQUIRED) + +add_executable(reqrep reqrep.c) +target_link_libraries(reqrep nng::nng) diff --git a/demo/reqrep/README.adoc b/demo/reqrep/README.adoc index b66d694c..5bc3d043 100644 --- a/demo/reqrep/README.adoc +++ b/demo/reqrep/README.adoc @@ -19,8 +19,19 @@ compiled on 64-bit systems.) == Compiling -The following is an example typical of UNIX and similar systems like -Linux and macOS: +CMake with ninja-build is simplest: + +[source, bash] +---- +% mkdir build +% cd build +% cmake -G Ninja .. +% ninja +---- + +Or if you prefer a traditional approach, +the following is an example typical of UNIX and similar systems like +Linux and macOS may appeal: [source, bash] ---- 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 <info@capitar.com> +# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +# +# 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); |
