├── .clang-format ├── .codecov.yml ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── pull_request_template.md └── workflows │ ├── codeql-analysis.yml │ ├── coverage.yml │ ├── darwin.yml │ ├── freebsd.yml │ ├── linux.yml │ ├── mdbook.yml │ ├── omnios.yml │ ├── sanitizer.yml │ └── windows.yml ├── .gitignore ├── .gitmodules ├── .grcov.yml ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── LICENSE.txt ├── README.md ├── UKRAINE.md ├── cmake ├── CheckSanitizer.cmake ├── FindMbedTLS.cmake ├── FindwolfSSL.cmake ├── NNGHelpers.cmake ├── NNGOptions.cmake └── nng-config.cmake.in ├── demo ├── async │ ├── CMakeLists.txt │ ├── README.adoc │ ├── arun.sh │ ├── client.c │ ├── run.sh │ └── server.c ├── http_client │ ├── CMakeLists.txt │ ├── README.adoc │ └── http_client.c ├── pubsub_forwarder │ ├── CMakeLists.txt │ ├── README.adoc │ └── pubsub_forwarder.c ├── raw │ ├── CMakeLists.txt │ ├── README.adoc │ └── raw.c ├── reqrep │ ├── CMakeLists.txt │ ├── README.adoc │ └── reqrep.c ├── rest │ ├── CMakeLists.txt │ ├── README.adoc │ └── server.c └── stream │ ├── CMakeLists.txt │ ├── platform │ ├── posix │ │ └── server.c │ └── windows │ │ └── server.c │ └── stream.c ├── docs ├── .gitignore ├── BUILD_ANDROID.adoc ├── BUILD_CROSSCOMPILE.adoc ├── BUILD_IOS.adoc ├── BUILD_TLS.md ├── BUILD_ZEROTIER.adoc ├── CONTRIBUTING.adoc ├── LICENSE.adoc ├── RATIONALE.adoc ├── README.txt ├── book.toml ├── man │ ├── libnng.3.adoc │ ├── man3tls.desc │ ├── man3tls.sect │ ├── man7.desc │ ├── nng.7.adoc │ ├── nng_aio_finish.3.adoc │ ├── nng_aio_get_input.3.adoc │ ├── nng_aio_reset.3.adoc │ ├── nng_aio_set_output.3.adoc │ ├── nng_aio_start.3.adoc │ ├── nng_device.3.adoc │ ├── nng_dial.3.adoc │ ├── nng_dialer.5.adoc │ ├── nng_dialer_close.3.adoc │ ├── nng_dialer_create.3.adoc │ ├── nng_dialer_get.3.adoc │ ├── nng_dialer_id.3.adoc │ ├── nng_dialer_set.3.adoc │ ├── nng_dialer_start.3.adoc │ ├── nng_http_handler_free.3http.adoc │ ├── nng_http_server_add_handler.3http.adoc │ ├── nng_http_server_del_handler.3http.adoc │ ├── nng_http_server_get_addr.3http.adoc │ ├── nng_http_server_get_tls.3http.adoc │ ├── nng_http_server_hold.3http.adoc │ ├── nng_http_server_release.3http.adoc │ ├── nng_http_server_res_error.3http.adoc │ ├── nng_http_server_set_error_page.3http.adoc │ ├── nng_http_server_set_tls.3http.adoc │ ├── nng_http_server_start.3http.adoc │ ├── nng_http_server_stop.3http.adoc │ ├── nng_ipc_options.5.adoc │ ├── nng_listen.3.adoc │ ├── nng_listener.5.adoc │ ├── nng_listener_close.3.adoc │ ├── nng_listener_create.3.adoc │ ├── nng_listener_get.3.adoc │ ├── nng_listener_id.3.adoc │ ├── nng_listener_set.3.adoc │ ├── nng_listener_start.3.adoc │ ├── nng_options.5.adoc │ ├── nng_sockaddr.5.adoc │ ├── nng_sockaddr_abstract.5.adoc │ ├── nng_sockaddr_in.5.adoc │ ├── nng_sockaddr_in6.5.adoc │ ├── nng_sockaddr_inproc.5.adoc │ ├── nng_sockaddr_ipc.5.adoc │ ├── nng_str_sockaddr.3.adoc │ ├── nng_tcp.7.adoc │ ├── nng_tcp_options.5.adoc │ ├── nng_tls.7.adoc │ ├── nng_tls_config.5.adoc │ ├── nng_tls_config_alloc.3tls.adoc │ ├── nng_tls_config_auth_mode.3tls.adoc │ ├── nng_tls_config_ca_chain.3tls.adoc │ ├── nng_tls_config_ca_file.3tls.adoc │ ├── nng_tls_config_cert_key_file.3tls.adoc │ ├── nng_tls_config_free.3tls.adoc │ ├── nng_tls_config_hold.3tls.adoc │ ├── nng_tls_config_own_cert.3tls.adoc │ ├── nng_tls_config_psk.3tls.adoc │ ├── nng_tls_config_server_name.3tls.adoc │ ├── nng_tls_config_version.3tls.adoc │ ├── nng_tls_engine_description.3tls.adoc │ ├── nng_tls_engine_fips_mode.3tls.adoc │ ├── nng_tls_engine_name.3tls.adoc │ ├── nng_tls_options.5.adoc │ ├── nng_ws.7.adoc │ └── nngcat.1.adoc └── ref │ ├── SUMMARY.md │ ├── api │ ├── aio.md │ ├── args.md │ ├── ctx.md │ ├── errors.md │ ├── http.md │ ├── id_map.md │ ├── index.md │ ├── init.md │ ├── logging.md │ ├── memory.md │ ├── misc.md │ ├── msg.md │ ├── pipe.md │ ├── sock.md │ ├── stats.md │ ├── stream.md │ ├── synch.md │ ├── thread.md │ ├── time.md │ └── url.md │ ├── copyright.md │ ├── dedication.md │ ├── img │ └── staysail-bw-trans.svg │ ├── indexing.md │ ├── migrate │ ├── index.md │ ├── nanomsg.md │ └── nng1.md │ ├── preface.md │ ├── proto │ ├── bus.md │ ├── index.md │ ├── pair.md │ ├── pub.md │ ├── pull.md │ ├── push.md │ ├── rep.md │ ├── req.md │ ├── respondent.md │ ├── sub.md │ └── surveyor.md │ ├── tran │ ├── index.md │ ├── inproc.md │ ├── ipc.md │ ├── socket.md │ └── udp.md │ └── xref.md ├── etc ├── README.adoc ├── codecov.sh ├── coverage.sh ├── format-check.sh └── nng.sublime-project ├── include └── nng │ ├── args.h │ ├── http.h │ └── nng.h ├── src ├── CMakeLists.txt ├── core │ ├── CMakeLists.txt │ ├── aio.c │ ├── aio.h │ ├── aio_test.c │ ├── args_test.c │ ├── buf_size_test.c │ ├── defs.h │ ├── device.c │ ├── device.h │ ├── dialer.c │ ├── dialer.h │ ├── errors_test.c │ ├── file.c │ ├── file.h │ ├── id_test.c │ ├── idhash.c │ ├── idhash.h │ ├── idhash_test.c │ ├── init.c │ ├── init.h │ ├── init_test.c │ ├── list.c │ ├── list.h │ ├── list_test.c │ ├── listener.c │ ├── listener.h │ ├── lmq.c │ ├── lmq.h │ ├── log.c │ ├── log_test.c │ ├── message.c │ ├── message.h │ ├── message_test.c │ ├── msgqueue.c │ ├── msgqueue.h │ ├── nng_impl.h │ ├── options.c │ ├── options.h │ ├── panic.c │ ├── panic.h │ ├── pipe.c │ ├── pipe.h │ ├── platform.h │ ├── pollable.c │ ├── pollable.h │ ├── protocol.h │ ├── reap.c │ ├── reap.h │ ├── reconnect_test.c │ ├── refcnt.c │ ├── refcnt.h │ ├── sock_test.c │ ├── sockaddr.c │ ├── sockaddr_test.c │ ├── socket.c │ ├── socket.h │ ├── sockfd.c │ ├── sockfd.h │ ├── sockimpl.h │ ├── stats.c │ ├── stats.h │ ├── stats_test.c │ ├── stream.c │ ├── stream.h │ ├── strs.c │ ├── strs.h │ ├── synch_test.c │ ├── taskq.c │ ├── taskq.h │ ├── tcp.c │ ├── tcp.h │ ├── thread.c │ ├── thread.h │ ├── url.c │ ├── url.h │ └── url_test.c ├── nng.c ├── nng_legacy.c ├── platform │ ├── CMakeLists.txt │ ├── files_test.c │ ├── ipc_stream_test.c │ ├── platform_test.c │ ├── posix │ │ ├── CMakeLists.txt │ │ ├── posix_aio.h │ │ ├── posix_alloc.c │ │ ├── posix_atomic.c │ │ ├── posix_clock.c │ │ ├── posix_config.h │ │ ├── posix_debug.c │ │ ├── posix_file.c │ │ ├── posix_impl.h │ │ ├── posix_ipc.h │ │ ├── posix_ipcconn.c │ │ ├── posix_ipcdial.c │ │ ├── posix_ipclisten.c │ │ ├── posix_ipcwinsec_test.c │ │ ├── posix_peerid.c │ │ ├── posix_peerid.h │ │ ├── posix_pipe.c │ │ ├── posix_pollq.h │ │ ├── posix_pollq_epoll.c │ │ ├── posix_pollq_epoll.h │ │ ├── posix_pollq_kqueue.c │ │ ├── posix_pollq_kqueue.h │ │ ├── posix_pollq_poll.c │ │ ├── posix_pollq_poll.h │ │ ├── posix_pollq_port.c │ │ ├── posix_pollq_port.h │ │ ├── posix_pollq_select.c │ │ ├── posix_pollq_select.h │ │ ├── posix_rand_arc4random.c │ │ ├── posix_rand_getentropy.c │ │ ├── posix_rand_getrandom.c │ │ ├── posix_rand_urandom.c │ │ ├── posix_resolv_gai.c │ │ ├── posix_sockaddr.c │ │ ├── posix_socketpair.c │ │ ├── posix_sockfd.c │ │ ├── posix_tcp.h │ │ ├── posix_tcpconn.c │ │ ├── posix_tcpdial.c │ │ ├── posix_tcplisten.c │ │ ├── posix_thread.c │ │ └── posix_udp.c │ ├── resolver_test.c │ ├── tcp_stream_test.c │ ├── udp_test.c │ └── windows │ │ ├── CMakeLists.txt │ │ ├── win_clock.c │ │ ├── win_debug.c │ │ ├── win_file.c │ │ ├── win_impl.h │ │ ├── win_io.c │ │ ├── win_ipc.h │ │ ├── win_ipc_sec_test.c │ │ ├── win_ipcconn.c │ │ ├── win_ipcdial.c │ │ ├── win_ipclisten.c │ │ ├── win_pipe.c │ │ ├── win_rand.c │ │ ├── win_resolv.c │ │ ├── win_sockaddr.c │ │ ├── win_socketpair.c │ │ ├── win_tcp.c │ │ ├── win_tcp.h │ │ ├── win_tcpconn.c │ │ ├── win_tcpdial.c │ │ ├── win_tcplisten.c │ │ ├── win_thread.c │ │ └── win_udp.c ├── sp │ ├── CMakeLists.txt │ ├── device_test.c │ ├── multistress_test.c │ ├── nonblock_test.c │ ├── pipe_test.c │ ├── protocol.c │ ├── protocol │ │ ├── CMakeLists.txt │ │ ├── bus0 │ │ │ ├── CMakeLists.txt │ │ │ ├── bus.c │ │ │ └── bus_test.c │ │ ├── pair0 │ │ │ ├── CMakeLists.txt │ │ │ ├── pair.c │ │ │ └── pair0_test.c │ │ ├── pair1 │ │ │ ├── CMakeLists.txt │ │ │ ├── pair.c │ │ │ ├── pair1_poly.c │ │ │ ├── pair1_poly_test.c │ │ │ └── pair1_test.c │ │ ├── pipeline0 │ │ │ ├── CMakeLists.txt │ │ │ ├── pull.c │ │ │ ├── pull_test.c │ │ │ ├── push.c │ │ │ └── push_test.c │ │ ├── pubsub0 │ │ │ ├── CMakeLists.txt │ │ │ ├── pub.c │ │ │ ├── pub_test.c │ │ │ ├── sub.c │ │ │ ├── sub_test.c │ │ │ ├── xsub.c │ │ │ └── xsub_test.c │ │ ├── reqrep0 │ │ │ ├── CMakeLists.txt │ │ │ ├── rep.c │ │ │ ├── rep_test.c │ │ │ ├── req.c │ │ │ ├── req_test.c │ │ │ ├── reqstress_test.c │ │ │ ├── xrep.c │ │ │ ├── xrep_test.c │ │ │ ├── xreq.c │ │ │ └── xreq_test.c │ │ └── survey0 │ │ │ ├── CMakeLists.txt │ │ │ ├── respond.c │ │ │ ├── respond_test.c │ │ │ ├── survey.c │ │ │ ├── survey_test.c │ │ │ ├── xrespond.c │ │ │ ├── xrespond_test.c │ │ │ ├── xsurvey.c │ │ │ └── xsurvey_test.c │ ├── reconnect_stress_test.c │ ├── scalability_test.c │ ├── transport.c │ ├── transport.h │ └── transport │ │ ├── CMakeLists.txt │ │ ├── dtls │ │ ├── CMakeLists.txt │ │ ├── dtls.c │ │ └── dtls_tran_test.c │ │ ├── inproc │ │ ├── CMakeLists.txt │ │ ├── inproc.c │ │ └── inproc_test.c │ │ ├── ipc │ │ ├── CMakeLists.txt │ │ ├── ipc.c │ │ └── ipc_test.c │ │ ├── socket │ │ ├── CMakeLists.txt │ │ ├── sockfd.c │ │ └── sockfd_test.c │ │ ├── tcp │ │ ├── CMakeLists.txt │ │ ├── tcp.c │ │ └── tcp_test.c │ │ ├── tls │ │ ├── CMakeLists.txt │ │ ├── tls.c │ │ └── tls_tran_test.c │ │ ├── udp │ │ ├── CMakeLists.txt │ │ ├── udp.c │ │ └── udp_tran_test.c │ │ └── ws │ │ ├── CMakeLists.txt │ │ ├── README.adoc │ │ ├── websocket.c │ │ ├── ws_test.c │ │ └── wss_test.c ├── supplemental │ ├── CMakeLists.txt │ ├── README.adoc │ ├── http │ │ ├── CMakeLists.txt │ │ ├── http_api.h │ │ ├── http_chunk.c │ │ ├── http_client.c │ │ ├── http_conn.c │ │ ├── http_msg.c │ │ ├── http_msg.h │ │ ├── http_public.c │ │ ├── http_schemes.c │ │ ├── http_server.c │ │ └── http_server_test.c │ ├── tls │ │ ├── CMakeLists.txt │ │ ├── mbedtls │ │ │ ├── CMakeLists.txt │ │ │ └── mbedtls.c │ │ ├── tls_api.h │ │ ├── tls_common.c │ │ ├── tls_common.h │ │ ├── tls_dialer.c │ │ ├── tls_engine.h │ │ ├── tls_listener.c │ │ ├── tls_stream.c │ │ ├── tls_stream.h │ │ ├── tls_stubs.c │ │ ├── tls_test.c │ │ └── wolfssl │ │ │ ├── CMakeLists.txt │ │ │ └── wolfssl.c │ └── websocket │ │ ├── CMakeLists.txt │ │ ├── base64.c │ │ ├── base64.h │ │ ├── base64_test.c │ │ ├── sha1.c │ │ ├── sha1.h │ │ ├── sha1_test.c │ │ ├── stub.c │ │ ├── websocket.c │ │ ├── websocket.h │ │ ├── websocket_test.c │ │ └── wssfile_test.c ├── testing │ ├── CMakeLists.txt │ ├── acutest.h │ ├── certs.c │ ├── marry.c │ ├── nuts.h │ ├── streams.c │ └── util.c └── tools │ ├── CMakeLists.txt │ ├── nngcat │ ├── CMakeLists.txt │ ├── nngcat.c │ ├── nngcat_ambiguous_test.sh │ ├── nngcat_async_test.sh │ ├── nngcat_dup_proto_test.sh │ ├── nngcat_help_test.sh │ ├── nngcat_incompat_test.sh │ ├── nngcat_need_proto_test.sh │ ├── nngcat_pubsub_test.sh │ ├── nngcat_recvmaxsz_test.sh │ ├── nngcat_stdin_pipe_test.sh │ └── nngcat_unlimited_test.sh │ └── perf │ ├── CMakeLists.txt │ ├── perf.c │ └── pubdrop.c └── tests ├── CMakeLists.txt ├── README.adoc ├── convey.c ├── convey.h ├── cplusplus_pair.cc └── httpclient.c /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: WebKit 2 | UseTab: ForIndentation 3 | IndentWidth: 8 4 | ColumnLimit: 79 5 | AlignConsecutiveAssignments: true 6 | AlignConsecutiveDeclarations: true 7 | AlignTrailingComments: true 8 | AlignEscapedNewlines: Left 9 | PointerAlignment: Right 10 | DerivePointerAlignment: false 11 | ForEachMacros: ['NNI_LIST_FOREACH'] 12 | AlwaysBreakAfterReturnType: TopLevelDefinitions 13 | SpaceAfterCStyleCast: true 14 | AllowShortFunctionsOnASingleLine: Inline 15 | BreakBeforeBinaryOperators: None 16 | TabWidth: 8 17 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "tests" 3 | - "src/testing" 4 | - "perf" 5 | - "**/*_test.c" 6 | coverage: 7 | range: 50..95 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh text eol=lf 2 | 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | github: gdamore 3 | patreon: gedamore 4 | custom: [ "https://staysail.tech/support/" ] 5 | custom: [ "https://leanpub.com/nngref2e" ] 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Expected behavior** 14 | A clear and concise description of what you expected to happen. 15 | 16 | **Actual Behavior** 17 | Describe what occurred. 18 | 19 | **To Reproduce** 20 | If possible include actual reproduction test code here. 21 | Minimal C test cases are perferred. 22 | 23 | ** Environment Details ** 24 | - NNG version 25 | - Operating system and version 26 | - Compiler and language used 27 | - Shared or static library 28 | 29 | **Additional context** 30 | Add any other context about the problem here. 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | fixes # 2 | 3 | 4 | 5 | Note that the above format should be used in your git commit comments. 6 | You agree that by submitting a PR, you have read and agreed to our 7 | contributing guidelines. 8 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: coverage 2 | on: 3 | push: 4 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 5 | jobs: 6 | linux-coverage: 7 | name: linux 8 | runs-on: [ubuntu-latest] 9 | steps: 10 | - name: Check out code 11 | uses: actions/checkout@v4 12 | 13 | - name: Install mbedTLS 14 | run: sudo apt-get install libmbedtls-dev 15 | 16 | - name: Install ninja 17 | run: sudo apt-get install ninja-build 18 | 19 | - name: Configure 20 | run: mkdir build && cd build && cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DNNG_ENABLE_COVERAGE=ON -DNNG_ENABLE_TLS=ON .. 21 | 22 | - name: build 23 | run: cd build && ninja 24 | 25 | - name: Test 26 | run: cd build && ctest --output-on-failure 27 | 28 | - name: Upload report 29 | uses: codecov/codecov-action@v4 30 | with: 31 | token: ${{ secrets.CODECOV_TOKEN }} 32 | codecov_yml_path: ./.codecov.yml 33 | 34 | darwin-coverage: 35 | name: darwin 36 | runs-on: [macos-latest] 37 | steps: 38 | - name: Check out code 39 | uses: actions/checkout@v1 40 | 41 | - name: Install mbedTLS 42 | run: brew install mbedtls 43 | 44 | - name: Install ninja 45 | run: brew install ninja 46 | 47 | - name: Install lcov 48 | run: brew install lcov 49 | 50 | - name: Configure 51 | run: mkdir build && cd build && cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DNNG_ENABLE_COVERAGE=ON -DNNG_ENABLE_TLS=ON .. 52 | 53 | - name: build 54 | run: cd build && ninja 55 | 56 | - name: Test 57 | run: cd build && ctest --output-on-failure 58 | 59 | - name: Preprocess 60 | run: cd build && lcov -c -d . -o lcov.info 61 | 62 | - name: Upload report 63 | uses: codecov/codecov-action@v4 64 | with: 65 | token: ${{ secrets.CODECOV_TOKEN }} 66 | yml: ./.codecov.yml 67 | -------------------------------------------------------------------------------- /.github/workflows/darwin.yml: -------------------------------------------------------------------------------- 1 | name: darwin 2 | on: 3 | push: 4 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 5 | pull_request: 6 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 7 | jobs: 8 | build: 9 | name: build 10 | runs-on: [macos-latest] 11 | steps: 12 | - name: Check out code 13 | uses: actions/checkout@v4 14 | 15 | - name: Install Mbed TLS 16 | run: brew install mbedtls 17 | 18 | - name: Install ninja 19 | run: brew install ninja 20 | 21 | - name: Configure 22 | run: mkdir build && cd build && cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DNNG_ENABLE_TLS=ON .. 23 | 24 | - name: build 25 | run: cd build && ninja 26 | 27 | - name: Test 28 | run: cd build && ctest --output-on-failure 29 | -------------------------------------------------------------------------------- /.github/workflows/freebsd.yml: -------------------------------------------------------------------------------- 1 | name: freebsd 2 | 3 | on: 4 | push: 5 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 6 | pull_request: 7 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | name: NNG test on FreeBSD via Qemu 13 | env: 14 | NNG_UDP_PASS_RATE: 10 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Test NNG in FreeBSD 18 | id: test 19 | uses: vmactions/freebsd-vm@v1 20 | with: 21 | usesh: true 22 | envs: NNG_UDP_PASS_RATE 23 | prepare: | 24 | pkg install -y lang/gcc 25 | pkg install -y devel/cmake 26 | pkg install -y devel/ninja 27 | run: | 28 | mkdir build 29 | cd build 30 | cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja -DNNG_TOOLS=OFF .. 31 | ninja 32 | ctest --output-on-failure 33 | -------------------------------------------------------------------------------- /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | name: linux 2 | on: 3 | push: 4 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 5 | pull_request: 6 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 7 | jobs: 8 | build: 9 | strategy: 10 | matrix: 11 | tls: 12 | - engine: mbed 13 | pkg: libmbedtls-dev 14 | dir: build.mbed 15 | - engine: wolf 16 | pkg: libwolfssl-dev 17 | dir: build.wolf 18 | pollq: 19 | - poller: auto 20 | - poller: epoll 21 | - poller: select 22 | - poller: poll 23 | name: build 24 | runs-on: [ubuntu-24.04] 25 | steps: 26 | - name: Check out code 27 | uses: actions/checkout@v4 28 | 29 | - name: Install ninja 30 | run: sudo apt-get install ninja-build 31 | 32 | - name: Install TLS engine 33 | run: sudo apt-get install ${{ matrix.tls.pkg }} 34 | 35 | - name: Configure 36 | run: mkdir ${{ matrix.tls.dir }} && cd ${{ matrix.tls.dir }} && cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -D NNG_ENABLE_TLS=ON -DNNG_POLLQ_POLLER=${{ matrix.pollq.poller }} -DNNG_TLS_ENGINE=${{ matrix.tls.engine }} .. 37 | 38 | - name: Build 39 | run: cd ${{ matrix.tls.dir }} && ninja 40 | 41 | - name: Test 42 | run: cd ${{ matrix.tls.dir }} && ctest --output-on-failure 43 | -------------------------------------------------------------------------------- /.github/workflows/mdbook.yml: -------------------------------------------------------------------------------- 1 | name: mdbook 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - "docs/**" 9 | - ".github/workflows/mdbook.yml" 10 | pull_request: 11 | paths: 12 | - "docs/**" 13 | - ".github/workflows/mdbook.yml" 14 | 15 | jobs: 16 | deploy: 17 | runs-on: ubuntu-latest 18 | concurrency: 19 | group: ${{ github.workflow }}-${{ github.ref }} 20 | steps: 21 | - uses: actions/checkout@v4 22 | 23 | - name: Setup mdBook 24 | uses: peaceiris/actions-mdbook@v2 25 | with: 26 | # mdbook-version: '0.4.10' 27 | mdbook-version: "latest" 28 | 29 | - run: cargo install mdbook-alerts 30 | - run: cargo install mdbook-indexing 31 | - run: cargo install mdbook-footnote 32 | - run: cargo install mdbook-pagetoc 33 | - run: mdbook build -d ./book docs 34 | 35 | - name: Deploy 36 | uses: peaceiris/actions-gh-pages@v4 37 | if: ${{ github.ref == 'refs/heads/main' }} 38 | with: 39 | github_token: ${{ secrets.GITHUB_TOKEN }} 40 | publish_dir: ./docs/book 41 | destination_dir: ./ref 42 | enable_jekyll: true 43 | -------------------------------------------------------------------------------- /.github/workflows/omnios.yml: -------------------------------------------------------------------------------- 1 | name: omnios 2 | 3 | on: 4 | push: 5 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 6 | pull_request: 7 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | name: NNG test on OmniOS via Qemu 13 | env: 14 | NNG_UDP_PASS_RATE: 10 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Test NNG in OmniOS 18 | id: test 19 | uses: vmactions/omnios-vm@v1 20 | with: 21 | usesh: true 22 | sync: rsync 23 | copyback: false 24 | envs: NNG_UDP_PASS_RATE 25 | prepare: | 26 | pkg install develeper/clang-19 27 | pkg install developer/ninja 28 | pkg install developer/cmake 29 | run: | 30 | mkdir build 31 | cd build 32 | cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja -DNNG_TOOLS=OFF .. 33 | ninja 34 | ctest --output-on-failure 35 | -------------------------------------------------------------------------------- /.github/workflows/sanitizer.yml: -------------------------------------------------------------------------------- 1 | name: sanitize 2 | on: 3 | push: 4 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 5 | pull_request: 6 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 7 | jobs: 8 | sanitize: 9 | env: 10 | CC: clang 11 | CXX: clang++ 12 | CTEST_OUTPUT_ON_FAILURE: 1 13 | runs-on: ${{ matrix.os }} 14 | strategy: 15 | matrix: 16 | sanitizer: [address, undefined, thread] 17 | os: [ubuntu-latest] 18 | 19 | steps: 20 | - uses: actions/checkout@v1 21 | 22 | - name: Install mbedTLS 23 | run: sudo apt-get install libmbedtls-dev 24 | 25 | - name: Install ninja 26 | run: sudo apt-get install ninja-build 27 | 28 | - name: Configure 29 | run: | 30 | mkdir build 31 | cd build 32 | cmake -G Ninja -DNNG_SANITIZER=${{ matrix.sanitizer }} -DCMAKE_BUILD_TYPE=Debug -DNNG_ENABLE_TLS=ON -DNNG_TOOLS=OFF .. 33 | - name: Build 34 | run: | 35 | cd build 36 | ninja 37 | - name: Test 38 | run: | 39 | cd build 40 | ninja test 41 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | name: windows 2 | on: 3 | push: 4 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 5 | pull_request: 6 | paths-ignore: ["docs/**", "**.adoc", "**.md"] 7 | jobs: 8 | build: 9 | name: build 10 | runs-on: [windows-latest] 11 | steps: 12 | - name: Check out code 13 | uses: actions/checkout@v4 14 | 15 | - name: vcpkg build 16 | id: vcpkg 17 | uses: johnwason/vcpkg-action@v6 18 | with: 19 | pkgs: mbedtls 20 | triplet: x64-windows 21 | token: ${{ github.token }} 22 | github-binarycache: true 23 | 24 | - name: Configure 25 | # TLS on Windows is not good because vcpkg is *old* mbedTLS 2.28, and we don't pass some newer tests. 26 | # We should explore testing WolfSSL here instead. 27 | run: cmake ${{ steps.vcpkg.outputs.vcpkg-cmake-config }} -B build -DCMAKE_BUILD_TYPE=Debug 28 | 29 | - name: Build 30 | run: cmake --build build 31 | 32 | - name: Test 33 | run: | 34 | cd build 35 | ctest -C Debug --output-on-failure 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | build.* 3 | .cache 4 | .vs 5 | .vscode/.cmaketools.json 6 | .vscode 7 | .idea 8 | .DS_Store 9 | etc/nng.sublime-workspace 10 | cmake-build-* 11 | docs/**/*.html 12 | compile_commands.txt 13 | compile_flags.txt 14 | .zed 15 | .nova 16 | *~ 17 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanomsg/nng/5d4baea78c69b62116dbebb3b2710cfd341a19b7/.gitmodules -------------------------------------------------------------------------------- /.grcov.yml: -------------------------------------------------------------------------------- 1 | branch: true 2 | ignore-not-existing: true 3 | filter: covered 4 | output-type: lcov 5 | output-file: lcov.info -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright 2021 Staysail Systems, Inc. 4 | Copyright 2018 Capitar IT Group BV 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom 11 | the Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 | IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /cmake/CheckSanitizer.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2019 Staysail Systems, Inc. 3 | # Copyright 2017 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | macro (CheckSanitizer) 12 | 13 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU") 14 | set(NNG_SAN_LIST none address leak memory thread undefined) 15 | elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") 16 | set(NNG_SAN_LIST none address leak memory thread undefined) 17 | elseif (CMAKE_C_COMPILER_ID STREQUAL "AppleClang") 18 | set(NNG_SAN_LIST none address thread undefined) 19 | else () 20 | set(NNG_SAN_LIST none) 21 | endif () 22 | set (NNG_SANITIZER none CACHE STRING "Sanitizer to use (clang or gcc).") 23 | set_property(CACHE NNG_SANITIZER PROPERTY STRINGS ${NNG_SAN_LIST}) 24 | mark_as_advanced (NNG_SANITIZER) 25 | 26 | if (NOT NNG_SANITIZER STREQUAL "none") 27 | set (NNG_C_FLAG_SANITIZER "-fsanitize=${NNG_SANITIZER}") 28 | message(STATUS "Enabling sanitizer: ${NNG_C_FLAG_SANITIZER}") 29 | endif() 30 | endmacro () 31 | -------------------------------------------------------------------------------- /cmake/nng-config.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright 2023 Staysail Systems, Inc. 2 | # 3 | # This software is supplied under the terms of the MIT License, a 4 | # copy of which should be located in the distribution where this 5 | # file was obtained (LICENSE.txt). A copy of the license may also be 6 | # found online at https://opensource.org/licenses/MIT. 7 | 8 | 9 | @PACKAGE_INIT@ 10 | 11 | set(NNG_MAJOR_VERSION "@NNG_MAJOR_VERSION@") 12 | set(NNG_MINOR_VERSION "@NNG_MINOR_VERSION@") 13 | set(NNG_PATCH_VERSION "@NNG_PATCH_VERSION@") 14 | 15 | set_and_check(NNG_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIRS@") 16 | 17 | include("${CMAKE_CURRENT_LIST_DIR}/nng-targets.cmake") 18 | 19 | # Make sure we find packages for our dependencies 20 | foreach(_PKG IN ITEMS @NNG_PKGS@) 21 | find_package(${_PKG} REQUIRED) 22 | endforeach () 23 | 24 | set(NNG_LIBRARY nng::nng) 25 | 26 | check_required_components(@PROJECT_NAME@) 27 | -------------------------------------------------------------------------------- /demo/async/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | 10 | # This CMakeLists file assumes you have INSTALLED NNG. 11 | # It does not work from the NNG source tree directly. 12 | 13 | cmake_minimum_required (VERSION 3.15) 14 | 15 | project(nng-asyncdemo) 16 | 17 | set(PARALLEL 128 CACHE STRING "Parallelism (min 4, max 1000)") 18 | 19 | # Call this from your own project's makefile. 20 | find_package(nng CONFIG REQUIRED) 21 | 22 | add_executable(server server.c) 23 | target_link_libraries(server nng::nng) 24 | target_compile_definitions(server PRIVATE NNG_ELIDE_DEPRECATED PARALLEL=${PARALLEL}) 25 | 26 | add_executable(client client.c) 27 | target_link_libraries(client nng::nng) 28 | target_compile_definitions(client PRIVATE NNG_ELIDE_DEPRECATED) 29 | -------------------------------------------------------------------------------- /demo/async/README.adoc: -------------------------------------------------------------------------------- 1 | = async 2 | 3 | This is a simple asynchronous demo, that demonstrates use of the contexts 4 | and asynchronous message handling and operations, to obtain highly concurrent 5 | processing with minimal fuss. 6 | 7 | == Compiling 8 | 9 | This is set up for configuration with CMake for ease of use. 10 | 11 | You can override the level of concurrency with the `PARALLEL` option. 12 | 13 | This determines how many requests the server will accept 14 | at a time, and keep outstanding. Note that for our toy implementation, 15 | we create this many "logical" flows of execution (contexts) (these are 16 | _NOT_ threads), where a request is followed by a reply. 17 | 18 | The value of `PARALLEL` must be at least one, and may be as large 19 | as your memory will permit. (The default value is 128.) Probably 20 | you want the value to be small enough to ensure that you have enough 21 | file descriptors. (You can create more contexts than this, but generally 22 | you can't have more than one client per descriptor. Contexts can be used 23 | on the client side to support many thousands of concurrent requests over 24 | even just a single TCP connection, however.) 25 | 26 | You can also build this all by hand with Make or whatever. 27 | 28 | On UNIX-style systems: 29 | 30 | [source, bash] 31 | ---- 32 | % export CPPFLAGS="-D PARALLEL=32 -I /usr/local/include" 33 | % export LDFLAGS="-L /usr/local/lib -lnng" 34 | % export CC="cc" 35 | % ${CC} ${CPPFLAGS} server.c -o server ${LDFLAGS} 36 | % ${CC} ${CPPFLAGS} client.c -o client ${LDFLAGS} 37 | ---- 38 | 39 | == Running 40 | 41 | The easiest thing is to simply use the `run.sh` script, which 42 | sends COUNT (10) random jobs to the server in parallel. 43 | 44 | You can of course run the client and server manually instead. 45 | 46 | The server takes the address (url) as its only argument. 47 | 48 | The client takes the address (url), followed by the number of 49 | milliseconds the server should "wait" before responding (to simulate 50 | an expensive operation.) 51 | -------------------------------------------------------------------------------- /demo/async/arun.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ######################################################################## 3 | ### Start asynchronous clients that can 4 | ### wait for asynchronous server to start 5 | ######################################################################## 6 | 7 | ### Usage: ./arun.sh [client#] 8 | ### - client# => do not start server until just before this client 9 | 10 | ### Socket file; client count 11 | ADDR=ipc:///tmp/async_demo 12 | COUNT=10 13 | 14 | ### Client # to match when server should be started; clear server PID 15 | SERVER_ORDINAL=$1 16 | unset SERVER_PID 17 | 18 | ### Create CLIENT_PID as an array 19 | typeset -a CLIENT_PID 20 | i=0 21 | while (( i < COUNT )) 22 | do 23 | i=$(( i + 1 )) 24 | 25 | ### Start server before the matching client 26 | if [ "$SERVER_ORDINAL" == "$i" ] ; then 27 | ./server $ADDR & 28 | SERVER_PID=$! 29 | echo Started server before client $i 30 | trap "kill $SERVER_PID" 0 31 | fi 32 | 33 | ### Start start client with NONBLOCK envvar set 34 | ### so client will wait for socket to be open on nng_dial 35 | rnd=$(( RANDOM % 1000 + 500 )) 36 | echo "Starting client $i: server will reply after $rnd msec" 37 | NONBLOCK= ./client $ADDR $rnd & 38 | ### Add this client's PID to client PID array 39 | eval CLIENT_PID[$i]=$! 40 | done 41 | 42 | ### Start server if not yet started 43 | [ "$SERVER_PID" ] || \ 44 | { 45 | ./server $ADDR & 46 | SERVER_PID=$! 47 | echo Starting server after last client - SERVER_PID=$SERVER_PID 48 | trap "kill $SERVER_PID" 0 49 | } 50 | 51 | ### Wait for clients to complete 52 | i=0 53 | while (( i < COUNT )) 54 | do 55 | i=$(( i + 1 )) 56 | wait ${CLIENT_PID[$i]} 57 | done 58 | ### Kill server 59 | kill $SERVER_PID 60 | -------------------------------------------------------------------------------- /demo/async/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ADDR=ipc:///tmp/async_demo 4 | COUNT=10 5 | 6 | ./server $ADDR & 7 | SERVER_PID=$! 8 | trap "kill $SERVER_PID" 0 9 | typeset -a CLIENT_PID 10 | i=0 11 | sleep 1 12 | while (( i < COUNT )) 13 | do 14 | i=$(( i + 1 )) 15 | rnd=$(( RANDOM % 1000 + 500 )) 16 | echo "Starting client $i: server replies after $rnd msec" 17 | ./client $ADDR $rnd & 18 | eval CLIENT_PID[$i]=$! 19 | done 20 | 21 | i=0 22 | while (( i < COUNT )) 23 | do 24 | i=$(( i + 1 )) 25 | wait ${CLIENT_PID[$i]} 26 | done 27 | kill $SERVER_PID 28 | -------------------------------------------------------------------------------- /demo/http_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | 10 | # This CMakeLists file assumes you have INSTALLED NNG. 11 | # It does not work from the NNG source tree directly. 12 | 13 | cmake_minimum_required (VERSION 3.15) 14 | 15 | project(http_client) 16 | 17 | # Call this from your own project's makefile. 18 | find_package(nng CONFIG REQUIRED) 19 | 20 | add_executable(http_client http_client.c) 21 | target_link_libraries(http_client nng::nng) 22 | target_compile_definitions(http_client PRIVATE NNG_ELIDE_DEPRECATED) 23 | -------------------------------------------------------------------------------- /demo/http_client/README.adoc: -------------------------------------------------------------------------------- 1 | = http_client 2 | 3 | This is a very simple HTTP client. It only performs HTTP GET 4 | operations, and does not follow HTTP redirects. Think of it as 5 | a trivialized version of cURL. It is super simple, taking the 6 | URL on the command line, and emitting the results to stdout. 7 | 8 | For clarity, we are eliding TLS support. 9 | 10 | It may not work on all systems, but it should work anywhere that 11 | both the standard C library and nng itself are available. 12 | 13 | We check for errors, but no effort is made to clean up resources, 14 | since this program just exits. In longer running programs or libraries, 15 | callers should take care to clean up things that they allocate. 16 | 17 | Unfortunately many famous sites use redirects (usually to HTTPS 18 | sites), so it's not a very useful replacement for cURL. 19 | 20 | == Compiling 21 | 22 | The following is an example typical of UNIX and similar systems like 23 | Linux and macOS: 24 | 25 | [source, bash] 26 | ---- 27 | % export CPPFLAGS="-I /usr/local/include" 28 | % export LDFLAGS="-L /usr/local/lib -lnng" 29 | % export CC="cc" 30 | % ${CC} ${CPPFLAGS} http_client.c -o http_client ${LDFLAGS} 31 | ---- 32 | 33 | Alternatively, CMake can be used. Here's an example if you have 34 | Ninja build handy (highly recommended): 35 | 36 | [source, bash] 37 | ---- 38 | % mkdir build 39 | % cd build 40 | % cmake -G Ninja .. 41 | % ninja 42 | ---- 43 | 44 | == Running 45 | 46 | Make sure you specify the full URL (if the root page include 47 | the simple "/". The URL parser does not add it for you automatically.) 48 | 49 | [source, bash] 50 | ---- 51 | % ./http_client http://httpbin.org/ip 52 | ---- 53 | -------------------------------------------------------------------------------- /demo/pubsub_forwarder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This software is supplied under the terms of the MIT License, a 2 | # copy of which should be located in the distribution where this 3 | # file was obtained (LICENSE.txt). A copy of the license may also be 4 | # found online at https://opensource.org/licenses/MIT. 5 | 6 | # This CMakeLists file assumes you have INSTALLED NNG. 7 | # It does not work from the NNG source tree directly. 8 | 9 | cmake_minimum_required(VERSION 3.15) 10 | project(pubsub_forwarder C) 11 | 12 | # Find the nng library 13 | find_package(nng CONFIG REQUIRED) 14 | 15 | # Add the executable target 16 | add_executable(pubsub_forwarder pubsub_forwarder.c) 17 | 18 | target_compile_options(pubsub_forwarder PRIVATE -Wall -Wextra -Wpedantic -Werror -O2) 19 | 20 | # Link against the nng library 21 | target_link_libraries(pubsub_forwarder PRIVATE nng::nng) 22 | -------------------------------------------------------------------------------- /demo/pubsub_forwarder/README.adoc: -------------------------------------------------------------------------------- 1 | = PubSub Forwarder 2 | 3 | This is a trivial example of a forwarder/proxy for the pub/sub pattern. 4 | 5 | The concept is as follows: the forwarder will listen for connections on 6 | both a front-end port and a back-end port. The front-end will act as a 7 | subscriber so that publishers can publish to it. The back-end will act 8 | as a publisher so that subscribers can subscribe to it. The front-end 9 | then forwards to the back end. 10 | 11 | == Compiling 12 | 13 | CMake with ninja-build is simplest: 14 | 15 | [source, bash] 16 | ---- 17 | cmake -GNinja -B build 18 | cd build 19 | ninja 20 | ---- 21 | 22 | Or if you prefer a traditional approach, 23 | the following is an example typical of UNIX and similar systems like 24 | Linux and macOS may appeal: 25 | 26 | [source, bash] 27 | ---- 28 | export CPPFLAGS="-I /usr/local/include" 29 | export LDFLAGS="-L /usr/local/lib -lnng" 30 | export CC="cc" 31 | ${CC} ${CPPFLAGS} pubsub_forwarder.c -o pubsub_forwarder ${LDFLAGS} 32 | ---- 33 | 34 | == Running 35 | 36 | An example setup for running this example would involve the following: 37 | 38 | . Step 1: Run this example binary (in the background or a terminal, etc) 39 | . Step 2: In a new terminal, run the following 40 | 41 | [source, bash] 42 | ---- 43 | nngcat --sub --dial "tcp://localhost:3328" --quoted 44 | ---- 45 | 46 | . Step 3: In a second terminal, run the same command again to give us two subscribers 47 | 48 | [source, bash] 49 | ---- 50 | nngcat --sub --dial "tcp://localhost:3328" --quoted 51 | ---- 52 | 53 | 54 | . In a third terminal, run the following to publish a counter 55 | 56 | [source, bash] 57 | ---- 58 | for n in $(seq 0 99); do nngcat --pub --dial "tcp://localhost:3327" --data "$n"; done 59 | ---- 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /demo/raw/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | 10 | # This CMakeLists file assumes you have INSTALLED NNG. 11 | # It does not work from the NNG source tree directly. 12 | 13 | cmake_minimum_required (VERSION 3.15) 14 | 15 | project(raw) 16 | 17 | set(PARALLEL 128 CACHE STRING "Parallelism (min 4, max 1000)") 18 | 19 | find_package(nng CONFIG REQUIRED) 20 | 21 | add_executable(raw raw.c) 22 | target_link_libraries(raw nng::nng) 23 | target_compile_definitions(raw PRIVATE NNG_ELIDE_DEPRECATED PARALLEL=${PARALLEL}) 24 | -------------------------------------------------------------------------------- /demo/raw/README.adoc: -------------------------------------------------------------------------------- 1 | = raw 2 | 3 | This is a simple asynchronous demo, that demonstrates use of the RAW 4 | sockets with a server, along with async message handling, to obtain a 5 | very high level of asynchronous operation, suitable for use in a highly 6 | concurrent server application. 7 | 8 | == Compiling 9 | 10 | You can override the level of concurrency with the `PARALLEL` option. 11 | 12 | This determines how many requests the server will accept 13 | at a time, and keep outstanding. Note that for our toy 14 | implementation, we create this many "logical" flows of execution 15 | (these are _NOT_ threads), where a request is followed by a reply. 16 | 17 | The value of `PARALLEL` must be at least one, and may be as large 18 | as your memory will permit. (The default value is 32.) 19 | 20 | The best way to build is using cmake and Ninja build: 21 | 22 | [source, bash] 23 | ---- 24 | % mkdir build 25 | % cd build 26 | % cmake -G Ninja .. 27 | % ninja 28 | ---- 29 | 30 | You can also build the hard way. For example, on UNIX-style systems: 31 | 32 | [source, bash] 33 | ---- 34 | % export CPPFLAGS="-D PARALLEL=32 -I /usr/local/include" 35 | % export LDFLAGS="-L /usr/local/lib -lnng" 36 | % export CC="cc" 37 | % ${CC} ${CPPFLAGS} raw.c -o raw ${LDFLAGS} 38 | ---- 39 | 40 | == Running 41 | 42 | To run the server, use the arguments `__url__ -s`. 43 | 44 | To run the client, use the arguments `__url__ __msec__`. 45 | 46 | The _msec_ is a "delay" time that server will wait before responding. 47 | We have these delays so simulate long running work. 48 | 49 | In the following example, all of the clients should complete within 50 | 2 seconds. (Assuming `PARALLEL` is defined to be large enough.) 51 | 52 | [source,bash] 53 | ---- 54 | % export URL="tcp://127.0.0.1:55995" 55 | # start the server 56 | % ./raw $URL -s & 57 | # start a bunch of clients 58 | # Note that these all run concurrently! 59 | % ./raw $URL 2 & 60 | % ./raw $URL 2 & 61 | % ./raw $URL 2 & 62 | % ./raw $URL 2 & 63 | % ./raw $URL 2 & 64 | ---- 65 | -------------------------------------------------------------------------------- /demo/reqrep/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | 10 | # This CMakeLists file assumes you have INSTALLED NNG. 11 | # It does not work from the NNG source tree directly. 12 | 13 | cmake_minimum_required (VERSION 3.15) 14 | 15 | project(reqrep) 16 | 17 | find_package(nng CONFIG REQUIRED) 18 | 19 | add_executable(reqrep reqrep.c) 20 | target_link_libraries(reqrep nng::nng) 21 | target_compile_definitions(reqrep PRIVATE NNG_ELIDE_DEPRECATED) 22 | -------------------------------------------------------------------------------- /demo/reqrep/README.adoc: -------------------------------------------------------------------------------- 1 | = reqrep 2 | 3 | This is a very simple RPC service using the REQ/REP method. 4 | It is derived in part from Tim Dysinger's 5 | http://nanomsg.org/gettingstarted/[Getting Started With Nanomsg] 6 | examples, but we have updated for _nng_, and converted to use binary 7 | frames across the wire instead of string data. 8 | 9 | The protocol is simple: 10 | 11 | * Client will send a 64-bit command (network byte order, i.e. big endian). 12 | * Server sends a 64-bit response (also network byte order.) 13 | 14 | The only command is "DATE", which has value 0x1. The value returned is 15 | a UNIX timestamp (seconds since Jan 1, 1970.) 16 | 17 | (We used 64-bit values for simplicity, and to avoid the Y2038 bug when 18 | compiled on 64-bit systems.) 19 | 20 | == Compiling 21 | 22 | CMake with ninja-build is simplest: 23 | 24 | [source, bash] 25 | ---- 26 | % mkdir build 27 | % cd build 28 | % cmake -G Ninja .. 29 | % ninja 30 | ---- 31 | 32 | Or if you prefer a traditional approach, 33 | the following is an example typical of UNIX and similar systems like 34 | Linux and macOS may appeal: 35 | 36 | [source, bash] 37 | ---- 38 | % export CPPFLAGS="-I /usr/local/include" 39 | % export LDFLAGS="-L /usr/local/lib -lnng" 40 | % export CC="cc" 41 | % ${CC} ${CPPFLAGS} reqrep.c -o reqrep ${LDFLAGS} 42 | ---- 43 | 44 | == Running 45 | 46 | You can run either the client or the server, and use whatever legal 47 | _nng_ URL you like: 48 | 49 | [source, bash] 50 | ---- 51 | % ./reqrep server tcp://127.0.0.1:8899 & 52 | % ./reqrep client tcp://127.0.0.1:8899 53 | CLIENT: SENDING DATE REQUEST 54 | SERVER: RECEIVED DATE REQUEST 55 | SERVER: SENDING DATE: Thu Feb 8 10:26:18 2018 56 | CLIENT: RECEIVED DATE: Thu Feb 8 10:26:18 2018 57 | ---- 58 | 59 | 60 | -------------------------------------------------------------------------------- /demo/rest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | 10 | # This CMakeLists file assumes you have INSTALLED NNG. 11 | # It does not work from the NNG source tree directly. 12 | 13 | cmake_minimum_required (VERSION 3.15) 14 | 15 | project(rest) 16 | 17 | find_package(nng CONFIG REQUIRED) 18 | 19 | add_executable(rest-server server.c) 20 | target_link_libraries(rest-server nng::nng) 21 | target_compile_definitions(rest-server PRIVATE NNG_ELIDE_DEPRECATED) 22 | -------------------------------------------------------------------------------- /demo/rest/README.adoc: -------------------------------------------------------------------------------- 1 | = REST API Gateway demo 2 | 3 | This is a somewhat contrived demonstration, but may be useful 4 | in a pattern for solving real world problems. 5 | 6 | There is a single "server" (rest-server) program, that does these: 7 | 8 | . REST API at /api/rest/rot13 - this API takes data from HTTP POST commands, 9 | and forwards them to an NNG REQ socket. When the REQ response comes, 10 | the reply is redirected back to the server. (For the purposes of the 11 | demonstration, our server just performs ROT13 on input.) 12 | 13 | . REP server (implemented in the same program using inproc, for demonstration 14 | purposes. In a real world scenario this might instead go to another 15 | process on another computer.) 16 | 17 | [source, bash] 18 | ---- 19 | % env PORT=8888 # default 20 | % ./rest-server & 21 | % curl -d ABC http://127.0.0.1:8888/api/rest/rot13; echo 22 | NOP 23 | % curl -d NOP http://127.0.0.1:8888/api/rest/rot13; echo 24 | ABC 25 | ---- 26 | 27 | == Compiling 28 | 29 | To build the program, we recommend CMake and Ninja-Build. 30 | 31 | [source, bash] 32 | ---- 33 | % mkdir build 34 | % cd build 35 | % cmake -G Ninja .. 36 | % ninja 37 | ---- 38 | 39 | Alternatively, you can go old-school. 40 | Here's the simplest option for Linux: 41 | 42 | [source, bash] 43 | ---- 44 | % cc server.c -o rest-server -I /usr/local/include -lnng 45 | ---- 46 | -------------------------------------------------------------------------------- /demo/stream/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2020 Hugo Lindström 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | 9 | cmake_minimum_required (VERSION 3.15) 10 | 11 | project(stream) 12 | 13 | find_package(nng CONFIG REQUIRED) 14 | 15 | add_executable(${PROJECT_NAME}) 16 | 17 | target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/stream.c) 18 | 19 | if (CMAKE_SYSTEM_NAME MATCHES "Linux") 20 | target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/platform/posix/server.c) 21 | endif() 22 | 23 | if (CMAKE_SYSTEM_NAME MATCHES "Windows") 24 | target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/server.c) 25 | endif() 26 | 27 | target_link_libraries(stream nng::nng) 28 | -------------------------------------------------------------------------------- /demo/stream/platform/posix/server.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Hugo Lindström 2 | 3 | // This software is supplied under the terms of the MIT License, a 4 | // copy of which should be located in the distribution where this 5 | // file was obtained (LICENSE.txt). A copy of the license may also be 6 | // found online at https://opensource.org/licenses/MIT. 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | void 16 | error(const char *msg) 17 | { 18 | perror(msg); 19 | exit(1); 20 | } 21 | 22 | int 23 | server(int portno) 24 | { 25 | int sockfd, newsockfd; 26 | socklen_t clilen; 27 | struct sockaddr_in serv_addr, cli_addr; 28 | int n; 29 | sockfd = socket(AF_INET, SOCK_STREAM, 0); 30 | if (sockfd < 0) { 31 | error("ERROR opening socket"); 32 | } 33 | bzero((char *) &serv_addr, sizeof(serv_addr)); 34 | serv_addr.sin_family = AF_INET; 35 | serv_addr.sin_addr.s_addr = INADDR_ANY; 36 | serv_addr.sin_port = htons(portno); 37 | if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 38 | 0) { 39 | error("ERROR on binding"); 40 | } 41 | listen(sockfd, 5); 42 | clilen = sizeof(cli_addr); 43 | newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); 44 | if (newsockfd < 0) { 45 | error("ERROR on accept"); 46 | } 47 | n = write(newsockfd, "Hello Client!", 13); 48 | if (n < 0) 49 | error("ERROR writing to socket"); 50 | close(newsockfd); 51 | close(sockfd); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | book 2 | -------------------------------------------------------------------------------- /docs/BUILD_IOS.adoc: -------------------------------------------------------------------------------- 1 | ifdef::env-github[] 2 | :note-caption: :information_source: 3 | endif::[] 4 | 5 | = Building for iOS (and tvOS, watchOS) 6 | 7 | NOTE: This work has had only minimal validation. As always, _caveat emptor_. 8 | 9 | == Pre-Requisites 10 | 11 | macOS:: 12 | 13 | As far as we know, the only way to build iOS applications is on a 14 | macOS host system. 15 | 16 | Xcode:: 17 | 18 | You will need Xcode. We tested this with Xcode 9.3. 19 | 20 | CMake:: 21 | 22 | We tested this with CMake 3.9. Other versions may work. 23 | 24 | iOS cmake toolchain file:: 25 | 26 | At the time of this writing (May 28, 2018), the toolchain file 27 | located at https://github.com/leetal/ios-cmake is appears to work 28 | reasonably well. 29 | 30 | == Steps 31 | 32 | When building for iOS and similar targets, only static libraries may be built. 33 | (This is good for avoiding dependency nightmares anyway.) 34 | 35 | Using the above toolchain file, we can build for iOS using 36 | the CMake standard CMAKE_TOOLCHAIN_FILE macro, and using 37 | the IOS_PLATFORM macro to set the target. (See the iOS CMake 38 | toolchain README for valid options; we select "OS" for iOS.) 39 | 40 | The test suite and command line tools will automatically be removed 41 | from the build, since they aren't interesting or useful in cross-compile 42 | environment. (There is no way to run them.) 43 | 44 | If you have checked out this repository in $SRC, the following should work: 45 | 46 | [source, sh] 47 | ---- 48 | % cd $SRC 49 | % mkdir ios-build 50 | % cd ios-build 51 | % git clone https://github.com/leetal/ios-cmake 52 | % cmake -G Xcode \ 53 | -DCMAKE_TOOLCHAIN_FILE=`pwd`/ios-cmake/ios.toolchain.cmake \ 54 | -DIOS_PLATFORM=OS .. 55 | ---- 56 | 57 | Then you can build using Xcode, or simply use cmake to drive the build: 58 | 59 | [source, sh] 60 | ---- 61 | % cmake --build . 62 | ---- 63 | 64 | Extra effort may be required to enable the use of mbedTLS (NNG does not 65 | at the time of writing support Secure Transport. See issue #497 for status.) 66 | -------------------------------------------------------------------------------- /docs/LICENSE.adoc: -------------------------------------------------------------------------------- 1 | = The MIT License 2 | 3 | Copyright 2018 Staysail Systems, Inc. + 4 | Copyright 2018 Capitar IT Group BV 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom 11 | the Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 | IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /docs/README.txt: -------------------------------------------------------------------------------- 1 | This contains the nng documentation for API users. 2 | 3 | Historically, the documentation was written in asciidoc in the form of man pages. 4 | It is automatically formatted for display on the website. 5 | 6 | The man pages are in the "man" directory. The reason those are separate 7 | is that they get special treatment. Other documentation is located here. 8 | 9 | HOWEVER, we are converting the documentation to mdbook -- see ref/ as the top-level 10 | of the new tree for that. 11 | -------------------------------------------------------------------------------- /docs/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | authors = ["Garrett D'Amore"] 3 | language = "en" 4 | multilingual = false 5 | src = "ref" 6 | title = "NNG Reference Manual (DRAFT)" 7 | 8 | [output.html] 9 | smart-punctuation = true 10 | fold.enable = true 11 | fold.level = 2 12 | additional-css = ["theme/pagetoc.css"] 13 | additional-js = ["theme/pagetoc.js"] 14 | site-url = "/ref/" 15 | 16 | # [output.markdown] 17 | 18 | # [output.compress] 19 | # page.new_pages = true 20 | # page.spacing.line = 1.3 21 | # page.size = { x = 203.2, y = 254 } 22 | # font.regular = "IBMPlexSerif-Regular.ttf" 23 | # font.monospace = "IBMPlexMono" 24 | # font.bold = "IBMPlexSans-SemiBold.ttf" 25 | 26 | # [output.epub] 27 | # epub-version = 3 28 | 29 | [preprocessor.alerts] 30 | 31 | [preprocessor.indexing] 32 | 33 | 34 | # [preprocessor.inline-highlighting] 35 | # default-language = "c" 36 | 37 | [preprocessor.footnote] 38 | 39 | [preprocessor.pagetoc] 40 | -------------------------------------------------------------------------------- /docs/man/man3tls.desc: -------------------------------------------------------------------------------- 1 | This section documents supplemental TLS (Transport Layer Security) 2 | functions that are available. 3 | TLS support is available when using Scalability Protocols with 4 | the xref:nng_tls.7.adoc[TLS] transport, or when using WebSocket, either 5 | with the xref:nng_ws.7.adoc[WebSocket] transport for Scalability Protocols, 6 | or combined with other HTTP capabilities. 7 | 8 | These functions depend on library support that is not included directly 9 | with _NNG_ however, so their presence will depend on whether this 10 | additional support was present and enabled with _libnng_ was built. 11 | 12 | Currently, this extra support can be provided by the 13 | https://tls.mbed.org[mbedTLS library] or by external plug-ins. 14 | 15 | TIP: Contact https://staysail.tech[Staysail Systems, Inc.] for 16 | details about commercially available options, including support for 17 | FIPS 140-2 validated cryptography and TLS v1.3. 18 | -------------------------------------------------------------------------------- /docs/man/man3tls.sect: -------------------------------------------------------------------------------- 1 | Supplemental TLS Functions 2 | -------------------------------------------------------------------------------- /docs/man/man7.desc: -------------------------------------------------------------------------------- 1 | This sections documents various protocols and transports that are 2 | available in the distribution. 3 | 4 | (((protocol))) 5 | Protocols implement communication patterns, such as 6 | request/reply, publish/subscribe, and so forth. 7 | A given xref:nng_socket.5.adoc[socket] is created with exactly one protocol, and that 8 | protocol defines the key behavior of the socket. 9 | 10 | (((transport))) 11 | Conversely, transports are the underlying mechanisms by which messages 12 | are moved between participants, such as TCP/IP or UNIX domain IPC. 13 | A given xref:nng_socket.5.adoc[socket] may be using several transports at the same 14 | time. 15 | -------------------------------------------------------------------------------- /docs/man/nng_aio_finish.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_aio_finish(3) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_aio_finish - finish asynchronous I/O operation 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | void nng_aio_finish(nng_aio *aio, int err); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_aio_finish()` function marks operation associated with _aio_ as 28 | complete, with the status _err_. 29 | This will be the result returned by 30 | xref:nng_aio_result.3.adoc[`nng_aio_result()`]. 31 | 32 | This function causes the callback associated with the _aio_ to called. 33 | 34 | IMPORTANT: It is mandatory that operation providers call this function 35 | *exactly once* when they are finished with the operation. 36 | After calling this function they *must not* perform any further accesses 37 | to the _aio_. 38 | 39 | NOTE: This function is only for I/O providers (those actually performing 40 | the operation such as HTTP handler functions or transport providers); ordinary 41 | users of the _aio_ should not have any need for this function. 42 | 43 | == RETURN VALUES 44 | 45 | None. 46 | 47 | == ERRORS 48 | 49 | None. 50 | 51 | == SEE ALSO 52 | 53 | [.text-left] 54 | xref:nng_aio_reset.3.adoc[nng_aio_reset(3)], 55 | xref:nng_aio_cancel.3.adoc[nng_aio_cancel(3)], 56 | xref:nng_aio_start.3.adoc[nng_aio_start(3)], 57 | xref:nng_aio_result.3.adoc[nng_aio_result(3)], 58 | xref:nng_aio.5.adoc[nng_aio(5)], 59 | xref:nng.7.adoc[nng(7)] 60 | -------------------------------------------------------------------------------- /docs/man/nng_aio_get_input.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_aio_get_input(3) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_aio_get_input - return input parameter 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | void *nng_aio_get_input(nng_aio *aio, unsigned int index); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_aio_get_input()` function returns the value of the input parameter 28 | previously set at _index_ on _aio_ with the 29 | xref:nng_aio_set_input.3.adoc[`nng_aio_set_input()`] function. 30 | 31 | The valid values of _index_ range from zero (0) to three (3), as no operation 32 | currently defined can accept more than four parameters. 33 | (This limit could increase in the future.) 34 | If the index supplied is outside of this range, 35 | or of the input parameter was not previously set, then `NULL` is returned. 36 | 37 | == RETURN VALUES 38 | 39 | Value previously set, or `NULL`. 40 | 41 | == ERRORS 42 | 43 | None. 44 | 45 | == SEE ALSO 46 | 47 | [.text-left] 48 | xref:nng_aio_get_output.3.adoc[nng_aio_get_output(3)], 49 | xref:nng_aio_set_input.3.adoc[nng_aio_set_input(3)], 50 | xref:nng_aio_result.3.adoc[nng_aio_result(3)], 51 | xref:nng_aio.5.adoc[nng_aio(5)], 52 | xref:nng.7.adoc[nng(7)] 53 | -------------------------------------------------------------------------------- /docs/man/nng_aio_reset.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_aio_reset(3) 2 | // 3 | // Copyright 2024 Staysail Systems, Inc. 4 | // 5 | // This document is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | == NAME 12 | 13 | nng_aio_reset - reset asynchronous I/O operation 14 | 15 | == SYNOPSIS 16 | 17 | [source, c] 18 | ---- 19 | #include 20 | 21 | void nng_aio_reset(nng_aio *aio); 22 | ---- 23 | 24 | == DESCRIPTION 25 | 26 | The `nng_aio_reset()` is used by providers to reset certain fields in the _aio_. 27 | This should be done before performing any operations on _aio_. 28 | 29 | NOTE: This function is only for I/O providers (those actually performing 30 | the operation such as HTTP handler functions or transport providers); ordinary 31 | users of the _aio_ should not call this function. 32 | 33 | == SEE ALSO 34 | 35 | [.text-left] 36 | xref:nng_aio_cancel.3.adoc[nng_aio_cancel(3)], 37 | xref:nng_aio_start.3.adoc[nng_aio_start(3)], 38 | xref:nng_aio_finish.3.adoc[nng_aio_finish(3)], 39 | xref:nng_aio_result.3.adoc[nng_aio_result(3)], 40 | xref:nng_aio.5.adoc[nng_aio(5)], 41 | xref:nng.7.adoc[nng(7)] 42 | -------------------------------------------------------------------------------- /docs/man/nng_aio_set_output.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_aio_set_output(3) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_aio_set_output - set output result 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | void nng_aio_set_output(nng_aio *aio, unsigned int index, void *result); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_aio_set_output()` function sets the output result at _index_ 28 | to _result_ for the asynchronous operation associated with _aio_. 29 | 30 | The type and semantics of output results are determined by specific 31 | operations; the operation must supply appropriate output results when 32 | the operation completes successfully. 33 | 34 | The valid values of _index_ range from zero (0) to three (3), as no operation 35 | currently defined can return more than four results. 36 | (This limit could increase in the future.) 37 | 38 | NOTE: Note that attempts to set results with an _index_ greater than 39 | three (3) will be ignored. 40 | 41 | An output result set with this function may be retrieved later with 42 | the xref:nng_aio_get_output.3.adoc[`nng_aio_get_output()`] function. 43 | 44 | == RETURN VALUES 45 | 46 | None. 47 | 48 | == ERRORS 49 | 50 | None. 51 | 52 | == SEE ALSO 53 | 54 | [.text-left] 55 | xref:nng_aio_finish.3.adoc[nng_aio_finish(3)], 56 | xref:nng_aio_get_output.3.adoc[nng_aio_get_output(3)], 57 | xref:nng_aio_result.3.adoc[nng_aio_result(3)], 58 | xref:nng_aio.5.adoc[nng_aio(5)], 59 | xref:nng.7.adoc[nng(7)] 60 | -------------------------------------------------------------------------------- /docs/man/nng_dialer_close.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_dialer_close(3) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_dialer_close - close dialer 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | int nng_dialer_close(nng_dialer d); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_dialer_close()` function closes the dialer _d_. 28 | This also closes any xref:nng_pipe.5.adoc[`nng_pipe`] objects that have 29 | been created by the dialer. 30 | 31 | Once this function returns, the dialer _d_ and any of its resources 32 | are deallocated. 33 | Therefore it is an error to attempt to access _d_ after 34 | this function has returned. 35 | (Attempts to do so will result in `NNG_ECLOSED` errors.) 36 | 37 | Dialers are implicitly closed when the socket they are associated with is closed. 38 | 39 | == RETURN VALUES 40 | 41 | This function returns 0 on success, and non-zero otherwise. 42 | 43 | == ERRORS 44 | 45 | [horizontal] 46 | `NNG_ECLOSED`:: Parameter _d_ does not refer to an open dialer. 47 | 48 | == SEE ALSO 49 | 50 | [.text-left] 51 | xref:nng_socket_close.3.adoc[nng_socket_close(3)], 52 | xref:nng_dial.3.adoc[nng_dial(3)], 53 | xref:nng_dialer_create.3.adoc[nng_dialer_create(3)] 54 | xref:nng_strerror.3.adoc[nng_strerror(3)], 55 | xref:nng_dialer.5.adoc[nng_dialer(5)], 56 | xref:nng.7.adoc[nng(7)] 57 | -------------------------------------------------------------------------------- /docs/man/nng_dialer_id.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_dialer_id(3) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_dialer_id - return numeric dialer identifier 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | int nng_dialer_id(nng_dialer d); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_dialer_id()` function returns a positive identifier for the dialer _d_, 28 | if it is valid. 29 | Otherwise it returns `-1`. 30 | 31 | NOTE: A dialer is considered valid if it was ever created with the 32 | xref:nng_dialer_create.3.adoc[`nng_dialer_create()`] or 33 | xref:nng_dial.3.adoc[`nng_dial()`] functions. 34 | Dialers that are allocated on the stack or statically should be 35 | initialized with the macro 36 | xref:nng_ctx.5.adoc#NNG_DIALER_INITIALIZER[`NNG_DIALER_INITIALIZER`] to ensure that 37 | they cannot be confused with a valid dialer before they are created properly. 38 | 39 | == RETURN VALUES 40 | 41 | This function returns the positive value for the dialer identifier, or 42 | `-1` if the dialer is invalid. 43 | 44 | == ERRORS 45 | 46 | None. 47 | 48 | == SEE ALSO 49 | 50 | [.text-left] 51 | xref:nng_dialer.5.adoc[nng_dialer(5)], 52 | xref:nng.7.adoc[nng(7)] 53 | -------------------------------------------------------------------------------- /docs/man/nng_http_handler_free.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_handler_free(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_handler_free - free HTTP server handler 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | void nng_http_handler_free(nng_http_handler *h); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_http_handler_free()` function frees an allocated HTTP server handler. 29 | 30 | IMPORTANT: It is an error to free a handler that is registered with a server. 31 | Any handlers that are registered with servers are automatically freed 32 | when the server itself is deallocated. 33 | 34 | == RETURN VALUES 35 | 36 | None. 37 | 38 | == ERRORS 39 | 40 | None. 41 | 42 | == SEE ALSO 43 | 44 | [.text-left] 45 | xref:nng_http_handler_alloc.3http.adoc[nng_http_handler_alloc(3http)], 46 | xref:nng_http_server_add_handler.3http.adoc[nng_http_server_add_handler(3http)], 47 | xref:nng.7.adoc[nng(7)] 48 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_add_handler.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_add_handler(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_add_handler - add HTTP server handler 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | int nng_http_server_add_handler(nng_http_server *s, nng_http_handler *h); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_http_server_add_handler()` adds the handler _h_ to the server 29 | instance _s_. 30 | 31 | If another handler is already added to the server that would conflict 32 | with handler _h_, then the operation will fail with `NNG_EADDRINUSE`. 33 | 34 | If a handler is added to a server, and the server is subsequently 35 | deallocated, the handler and any of its resources will also be deallocated. 36 | 37 | Handlers that are added to a server may be subsequently removed using the 38 | xref:nng_http_server_del_handler.3http.adoc[`nng_http_server_del_handler()`] function. 39 | 40 | == RETURN VALUES 41 | 42 | This function returns 0 on success, and non-zero otherwise. 43 | 44 | == ERRORS 45 | 46 | [horizontal] 47 | `NNG_EADDRINUSE`:: Handler conflicts with another handler. 48 | `NNG_ENOMEM`:: Insufficient free memory exists. 49 | `NNG_ENOTSUP`:: HTTP not supported. 50 | 51 | == SEE ALSO 52 | 53 | 54 | [.text-left] 55 | xref:nng_http_handler_alloc.3http.adoc[nng_http_handler_alloc(3http)], 56 | xref:nng_http_server_del_handler.3http.adoc[nng_http_server_del_handler(3http)], 57 | xref:nng_http_server_hold.3http.adoc[nng_http_server_hold(3http)], 58 | xref:nng_strerror.3.adoc[nng_strerror(3)], 59 | xref:nng.7.adoc[nng(7)] 60 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_del_handler.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_del_handler(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_del_handler - delete HTTP server handler 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | int nng_http_server_del_handler(nng_http_server *s, nng_http_handler *h); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_http_server_del_handler()` removes the handler _h_ from the server 29 | instance _s_. 30 | 31 | Once a handler has been deleted from a server, it is the responsibility 32 | of the caller to dispose of the handler, or add it to another server instance. 33 | 34 | == RETURN VALUES 35 | 36 | This function returns 0 on success, and non-zero otherwise. 37 | 38 | == ERRORS 39 | 40 | [horizontal] 41 | `NNG_ENOENT`:: Handler is not registered with server. 42 | `NNG_ENOTSUP`:: HTTP not supported. 43 | 44 | == SEE ALSO 45 | 46 | [.text-left] 47 | xref:nng_http_handler_free.3http.adoc[nng_http_handler_free(3http)], 48 | xref:nng_http_server_add_handler.3http.adoc[nng_http_server_add_handler(3http)], 49 | xref:nng_strerror.3.adoc[nng_strerror(3)], 50 | xref:nng.7.adoc[nng(7)] 51 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_get_addr.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_get_addr(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_get_addr - get HTTP server address 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | int nng_http_server_get_addr(nng_http_server *server, nng_sockaddr *sap); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | `nng_http_server_get_addr()`:: 29 | This function is used to retrieve an xref:nng_sockaddr.5.adoc[`nng_sockaddr`] 30 | into the value referenced by _sap_ for the server _server_. 31 | 32 | == RETURN VALUES 33 | 34 | This function returns 0 on success, and non-zero otherwise. 35 | 36 | == ERRORS 37 | 38 | `NNG_EINVAL`:: Either _server_ or _sap_ parameter is NULL. 39 | `NNG_ENOTSUP`:: HTTP not supported. 40 | 41 | 42 | == SEE ALSO 43 | 44 | [.text-left] 45 | xref:nng_sockaddr.5.adoc[nng_sockaddr(5)], 46 | xref:nng.7.adoc[nng(7)] 47 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_get_tls.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_get_tls(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_get_tls - get HTTP server TLS configuration 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | int nng_http_server_get_tls(nng_http_server *s, nng_tls_config **cfgp); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_http_server_get_tls()` obtains the TLS configuration of server _s_ and 29 | saves a pointer to it in the address referenced by _cfgp_. 30 | 31 | The object will be returned with an extra hold (see 32 | xref:nng_tls_config_hold.3tls.adoc[`nng_tls_config_hold()`]) 33 | placed on it on behalf of the caller. 34 | The caller should free this hold by calling 35 | xref:nng_tls_config_free.3tls.adoc[`nng_tls_config_free()`] with it is done 36 | with the TLS configuration. 37 | 38 | == RETURN VALUES 39 | 40 | This function returns 0 on success, and non-zero otherwise. 41 | 42 | == ERRORS 43 | 44 | [horizontal] 45 | `NNG_EINVAL`:: TLS not configured on server. 46 | `NNG_ENOMEM`:: Insufficient free memory exists. 47 | `NNG_ENOTSUP`:: Either HTTP or TLS not supported. 48 | 49 | == SEE ALSO 50 | 51 | [.text-left] 52 | xref:nng_http_server_hold.3http.adoc[nng_http_server_hold(3http)], 53 | xref:nng_http_server_set_tls.3http.adoc[nng_http_server_set_tls(3http)], 54 | xref:nng_http_server_start.3http.adoc[nng_http_server_start(3http)], 55 | xref:nng_tls_config_alloc.3tls.adoc[nng_tls_config_alloc(3tls)], 56 | xref:nng_tls_config_free.3tls.adoc[nng_tls_config_free(3tls)], 57 | xref:nng_tls_config_hold.3tls.adoc[nng_tls_config_hold(3tls)], 58 | xref:nng_strerror.3.adoc[nng_strerror(3)], 59 | xref:nng.7.adoc[nng(7)] 60 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_release.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_release(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_release - release HTTP server instance 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | void nng_http_server_release(nng_http_server *server); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_http_server_release()` releases an instance of an HTTP _server_ 29 | that was previously held with 30 | xref:nng_http_server_hold.3http.adoc[`nng_http_server_hold()`]. 31 | 32 | This effectively drops the reference count on the server instance. When 33 | the reference count drops to zero, then the _server_ and all resources 34 | associated with it (e.g. HTTP handlers, connections, etc.) are deallocated. 35 | (If the server is "running" when this occurs, then the server is stopped.) 36 | 37 | IMPORTANT: It is an error to release an instance of a server that has 38 | not previously been held, or to attempt to release an instance more 39 | times than it has been held. 40 | 41 | == RETURN VALUES 42 | 43 | None. 44 | 45 | == ERRORS 46 | 47 | None. 48 | 49 | == SEE ALSO 50 | 51 | [.text-left] 52 | xref:nng_http_server_hold.3http.adoc[nng_http_server_hold(3http)], 53 | xref:nng_http_server_stop.3http.adoc[nng_http_server_stop(3http)], 54 | xref:nng.7.adoc[nng(7)] 55 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_res_error.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_res_error(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_res_error - use HTTP server error page 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | int nng_http_server_res_error(nng_http_server *server, 24 | nng_http_res *response); 25 | ---- 26 | 27 | == DESCRIPTION 28 | 29 | The `nng_http_server_res_error()` sets the body of _response_ 30 | to _server_'s error page, which may have been customized using the 31 | xref:nng_http_server_set_error_file.3http.adoc[`nng_http_server_error_file()`] 32 | or 33 | xref:nng_http_server_set_error_page.3http.adoc[`nng_http_server_error_page()`] 34 | functions. 35 | 36 | The status code of the _response_ should have already been set by calling 37 | xref:nng_http_res_set_status.3http.adoc[`nng_http_res_set_status()`]. 38 | 39 | Any content body previously set for _response_ will be overridden by 40 | this function. 41 | 42 | == RETURN VALUES 43 | 44 | This function returns 0 on success, and non-zero otherwise. 45 | 46 | == ERRORS 47 | 48 | [horizontal] 49 | `NNG_ENOMEM`:: Insufficient free memory exists. 50 | `NNG_ENOTSUP`:: HTTP not supported. 51 | 52 | == SEE ALSO 53 | 54 | [.text-left] 55 | xref:nng_http_server_hold.3http.adoc[nng_http_server_hold(3http)], 56 | xref:nng_http_server_set_error_file.3http.adoc[nng_http_server_set_error_file(3http)], 57 | xref:nng_http_server_set_error_page.3http.adoc[nng_http_server_set_error_page(3http)], 58 | xref:nng_strerror.3.adoc[nng_strerror(3)], 59 | xref:nng.7.adoc[nng(7)] 60 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_set_tls.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_set_tls(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_set_tls - set HTTP server TLS configuration 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | int nng_http_server_set_tls(nng_http_server *s, nng_tls_config *cfg); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_http_server_set_tls()` sets the TLS configuration of server _s_ to 29 | _cfg_. 30 | 31 | This change overwrites any previous TLS configuration. 32 | 33 | IMPORTANT: This also invalidates any previously obtained values from 34 | xref:nng_http_server_get_tls.3http.adoc[`nng_http_server_get_tls()`]. 35 | 36 | If the server is already running (i.e. it has been started with 37 | xref:nng_http_server_start.3http.adoc[`nng_http_server_start()`]) then this will 38 | fail with `NNG_EBUSY`. 39 | 40 | TIP: Generally, the _cfg_ must have a configured private key, set with 41 | xref:nng_tls_config_own_cert.3tls.adoc[`nng_tls_config_own_cert()`] or similar. 42 | 43 | == RETURN VALUES 44 | 45 | This function returns 0 on success, and non-zero otherwise. 46 | 47 | == ERRORS 48 | 49 | [horizontal] 50 | `NNG_EBUSY`:: Server instance is running. 51 | `NNG_ENOMEM`:: Insufficient free memory exists. 52 | `NNG_ENOTSUP`:: Either HTTP or TLS not supported. 53 | 54 | == SEE ALSO 55 | 56 | [.text-left] 57 | xref:nng_http_server_get_tls.3http.adoc[nng_http_server_get_tls(3http)], 58 | xref:nng_http_server_hold.3http.adoc[nng_http_server_hold(3http)], 59 | xref:nng_http_server_start.3http.adoc[nng_http_server_start(3http)], 60 | xref:nng_tls_config_alloc.3tls.adoc[nng_tls_config_alloc(3tls)], 61 | xref:nng_strerror.3.adoc[nng_strerror(3)], 62 | xref:nng.7.adoc[nng(7)] 63 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_start.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_start(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_start - start HTTP server 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | int nng_http_server_start(nng_http_server *server); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_http_server_start()` starts the HTTP server instance _server_. 29 | This causes it to bind to the appropriate TCP port, and start accepting 30 | connections and handling HTTP requests. 31 | 32 | == RETURN VALUES 33 | 34 | This function returns 0 on success, and non-zero otherwise. 35 | 36 | == ERRORS 37 | 38 | [horizontal] 39 | `NNG_EADDRINUSE`:: The TCP port is unavailable. 40 | `NNG_EADDRINVAL`:: The server is configured with an invalid address. 41 | `NNG_ENOMEM`:: Insufficient free memory exists. 42 | `NNG_ENOTSUP`:: HTTP not supported. 43 | 44 | == SEE ALSO 45 | 46 | [.text-left] 47 | xref:nng_http_server_hold.3http.adoc[nng_http_server_hold(3http)], 48 | xref:nng_http_server_release.3http.adoc[nng_http_server_release(3http)], 49 | xref:nng_http_server_stop.3http.adoc[nng_http_server_stop(3http)], 50 | xref:nng_url_parse.3.adoc[nng_url_parse(3)] 51 | xref:nng_strerror.3.adoc[nng_strerror(3)], 52 | xref:nng.7.adoc[nng(7)] 53 | -------------------------------------------------------------------------------- /docs/man/nng_http_server_stop.3http.adoc: -------------------------------------------------------------------------------- 1 | = nng_http_server_stop(3http) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_http_server_stop - stop HTTP server 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | void nng_http_server_stop(nng_http_server *server); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_http_server_stop()` undoes the effect of 29 | xref:nng_http_server_start.3http.adoc[`nng_http_server_start()`]. 30 | 31 | Each call by 32 | xref:nng_http_server_start.3http.adoc[`nng_http_server_start()`] acts as reference 33 | count, and should be matched by a call to `nng_http_server_stop()`. 34 | When the reference count drops to zero, then the server is actually stopped, 35 | and existing open connections to it are closed. 36 | 37 | This function does not wait for the connections to close. 38 | 39 | NOTE: Once the server instance is actually stopped, it cannot be started again, 40 | and any future calls to xref:nng_http_server_hold.3http.adoc[`nng_http_server_hold()`] 41 | will return a new instance of the server. 42 | It is expected that the caller will follow this function call with a call to 43 | xref:nng_http_server_release.3http.adoc[`nng_http_server_release()`]. 44 | 45 | 46 | == RETURN VALUES 47 | 48 | None. 49 | 50 | == ERRORS 51 | 52 | None. 53 | 54 | == SEE ALSO 55 | 56 | [.text-left] 57 | xref:nng_http_server_hold.3http.adoc[nng_http_server_hold(3http)], 58 | xref:nng_http_server_release.3http.adoc[nng_http_server_release(3http)], 59 | xref:nng_http_server_start.3http.adoc[nng_http_server_start(3http)], 60 | xref:nng.7.adoc[nng(7)] 61 | -------------------------------------------------------------------------------- /docs/man/nng_listener_close.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_listener_close(3) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_listener_close - close listener 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | int nng_listener_close(nng_listener l); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_listener_close()` function closes the listener _l_. 28 | This also closes any pipes that have been created by the listener. 29 | 30 | Once this function returns, the listener _l_ and any of its resources 31 | are deallocated. 32 | Therefore it is an error to attempt to access _l_ 33 | after this function has returned. 34 | (Attempts to do so will result in `NNG_ECLOSED` errors.) 35 | 36 | Listeners are implicitly closed when the socket they are associated with 37 | is closed. 38 | 39 | == RETURN VALUES 40 | 41 | This function returns 0 on success, and non-zero otherwise. 42 | 43 | == ERRORS 44 | 45 | [horizontal] 46 | `NNG_ECLOSED`:: Parameter _l_ does not refer to an open listener. 47 | 48 | == SEE ALSO 49 | 50 | [.text-left] 51 | xref:nng_socket_close.3.adoc[nng_socket_close(3)], 52 | xref:nng_listen.3.adoc[nng_listen(3)], 53 | xref:nng_listener_create.3.adoc[nng_listener_create(3)] 54 | xref:nng_strerror.3.adoc[nng_strerror(3)], 55 | xref:nng_listener.5.adoc[nng_listener(5)], 56 | xref:nng.7.adoc[nng(7)] 57 | -------------------------------------------------------------------------------- /docs/man/nng_listener_id.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_listener_id(3) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_listener_id - return numeric listener identifier 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | int nng_listener_id(nng_listener l); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_listener_id()` function returns a positive identifier for the 28 | listener _l_, if it is valid. 29 | Otherwise it returns `-1`. 30 | 31 | NOTE: A listener is considered valid if it was ever created with the 32 | xref:nng_listener_create.3.adoc[`nng_listener_create()`] or 33 | xref:nng_listen.3.adoc[`nng_listen()`] functions. 34 | listeners that are allocated on the stack or statically should be 35 | initialized with the macro 36 | xref:nng_ctx.5.adoc#NNG_LISTENER_INITIALIZER[`NNG_LISTENER_INITIALIZER`] to ensure that 37 | they cannot be confused with a valid listener before they are created properly. 38 | 39 | == RETURN VALUES 40 | 41 | This function returns the positive value for the listener identifier, or 42 | `-1` if the listener is invalid. 43 | 44 | == ERRORS 45 | 46 | None. 47 | 48 | == SEE ALSO 49 | 50 | [.text-left] 51 | xref:nng_listener.5.adoc[nng_listener(5)], 52 | xref:nng.7.adoc[nng(7)] 53 | -------------------------------------------------------------------------------- /docs/man/nng_listener_start.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_listener_start(3) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_listener_start - start listener 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | int nng_listener_start(nng_listener l, int flags); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_listener_start()` function starts the listener _l_. 28 | 29 | This causes the listener to bind to the address it was created with, 30 | and to start accepting connections from remote 31 | dialers. 32 | Each new connection results in an xref:nng_pipe.5.adoc[`nng_pipe`] object, 33 | which will be attached to the listener's socket. 34 | 35 | The _flags_ argument is ignored, but reserved for future use. 36 | 37 | Once a listener has started, it is generally not possible to change 38 | its configuration. 39 | 40 | == RETURN VALUES 41 | 42 | This function returns 0 on success, and non-zero otherwise. 43 | 44 | == ERRORS 45 | 46 | [horizontal] 47 | `NNG_ECLOSED`:: Parameter _l_ does not refer to an open listener. 48 | `NNG_ESTATE`:: The listener _l_ is already started. 49 | 50 | == SEE ALSO 51 | 52 | [.text-left] 53 | xref:nng_listen.3.adoc[nng_listen(3)], 54 | xref:nng_listener_create.3.adoc[nng_listener_create(3)] 55 | xref:nng_listener.5.adoc[nng_listener(5)], 56 | xref:nng_strerror.3.adoc[nng_strerror(3)], 57 | xref:nng.7.adoc[nng(7)] 58 | -------------------------------------------------------------------------------- /docs/man/nng_sockaddr_inproc.5.adoc: -------------------------------------------------------------------------------- 1 | = nng_sockaddr_inproc(5) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_sockaddr_inproc - inproc socket address 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | enum sockaddr_family { 23 | NNG_AF_INPROC = 1, 24 | }; 25 | 26 | typedef struct { 27 | uint16_t sa_family; 28 | uint16_t sa_name[128]; 29 | } nng_sockaddr_inproc; 30 | ---- 31 | 32 | == DESCRIPTION 33 | 34 | (((socket, address, inproc))) 35 | An `nng_sockaddr_inproc` is the flavor of xref:nng_sockaddr.5.adoc[`nng_sockaddr`] 36 | used to represent addresses associated with intra-process communication 37 | using the xref:nng_inproc.7.adoc[_inproc_] transport. 38 | 39 | The following structure members are present: 40 | 41 | `sa_family`:: 42 | This field will always have the value ((`NNG_AF_INPROC`)). 43 | 44 | `sa_name`:: 45 | This field holds an arbitrary C string, which is the name of the address. 46 | The string must be `NUL` terminated, but no other restrictions exist. 47 | 48 | TIP: In order to ensure maximum compatibility, applications should avoid 49 | hard coding the size of the `sa_name` member explicitly, but use the 50 | `sizeof` operator to determine its actual size at compile time. 51 | Furthermore, the size is guaranteed to be at least 128. 52 | 53 | == SEE ALSO 54 | 55 | [.text-left] 56 | xref:nng_sockaddr.5.adoc[nng_sockaddr(5)], 57 | xref:nng_inproc.7.adoc[nng_inproc(7)] 58 | xref:nng.7.adoc[nng(7)] 59 | -------------------------------------------------------------------------------- /docs/man/nng_str_sockaddr.3.adoc: -------------------------------------------------------------------------------- 1 | = nng_str_sockaddr(3) 2 | // 3 | // Copyright 2024 Staysail Systems, Inc. 4 | // 5 | // This document is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | == NAME 12 | 13 | 14 | nng_str_sockaddr - get string representation of socket address 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | #define NNG_MAXADDRSTRLEN (NNG_MAXADDRLEN+16) 23 | const char *nng_str_sockaddr(const nng_sockaddr *sa, char *buf, size_t bufsz) 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_str_sockaddr()` is used to provide a displayable representation 29 | for the socket address _sa_. 30 | The content will be stored the location provided by _buf_, and will be 31 | formatted to fit within _bufsz_ bytes, truncating if necessary. 32 | 33 | As long as _bufsz_ is greater than zero, the result will be properly 34 | zero-terminated in the usual fashion. 35 | 36 | The `NNG_MAXADDRSTRLEN` can be used to provide a buffer large enough to hold most socket addresses. 37 | It is possible for applications to use very much larger socket addresses (using very long paths 38 | for IPC or inproc), but such addresses are not generally compatible with other implementations, 39 | and will be truncated here. 40 | 41 | == RETURN VALUES 42 | 43 | This function returns the _buf_ argument. 44 | 45 | == ERRORS 46 | 47 | None. 48 | 49 | == SEE ALSO 50 | 51 | [.text-left] 52 | xref:nng_sockaddr.5.adoc[nng_sockaddr(5)] 53 | -------------------------------------------------------------------------------- /docs/man/nng_tls_config.5.adoc: -------------------------------------------------------------------------------- 1 | = nng_tls_config(5) 2 | // 3 | // Copyright 2020 Staysail Systems, Inc. 4 | // Copyright 2019 Devolutions 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_tls_config - TLS configuration object 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | 22 | typedef struct nng_tls_config nng_tls_config; 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | An `nng_tls_config` represents a single ((TLS configuration)) object, which 28 | can be used to configure TLS servers and clients. 29 | 30 | Configuration data includes details such as certificate chains used for 31 | validation of remote peers, local key and certificate material, server 32 | names, and so forth. 33 | Additionally, a configuration can be used either in client mode, or in 34 | server mode. 35 | 36 | Configuration objects may be shared, and are reference counted. 37 | However once a configuration is used, it enters a read-only state that 38 | precludes further modifications to the configuration. 39 | 40 | Messages are allocated using the 41 | xref:nng_tls_config_alloc.3tls.adoc[`nng_tls_config_alloc()`] 42 | function, and are deallocated using the 43 | xref:nng_tls_config_free.3tls.adoc[`nng_tls_config_free()`] 44 | function. 45 | 46 | == SEE ALSO 47 | 48 | [.text-left] 49 | xref:nng_tls_config_alloc.3tls.adoc[nng_tls_config_alloc(3tls)], 50 | xref:nng_tls_config_auth_mode.3tls.adoc[nng_tls_config_auth_mode(3tls)], 51 | xref:nng_tls_config_ca_chain.3tls.adoc[nng_tls_config_ca_chain(3tls)], 52 | xref:nng_tls_config_own_cert.3tls.adoc[nng_tls_config_own_cert(3tls)], 53 | xref:nng_tls_config_free.3tls.adoc[nng_tls_config_free(3tls)], 54 | xref:nng_tls_config_hold.3tls.adoc[nng_tls_config_hold(3tls)], 55 | xref:nng_tls_config_server_name.3tls.adoc[nng_tls_config_server_name(3tls)], 56 | xref:nng.7.adoc[nng(7)] 57 | -------------------------------------------------------------------------------- /docs/man/nng_tls_config_free.3tls.adoc: -------------------------------------------------------------------------------- 1 | = nng_tls_config_free(3tls) 2 | // 3 | // Copyright 2018 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_tls_config_free - deallocate a TLS configuration object 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | void nng_tls_config_free(nng_tls_config *cfg); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_tls_config_free()` decrements the reference count on the 29 | TLS configuration object pointed to by _cfg_, and if the resulting 30 | reference count is zero, then deallocates the configuration object. 31 | 32 | == RETURN VALUES 33 | 34 | None. 35 | 36 | == ERRORS 37 | 38 | None. 39 | 40 | == SEE ALSO 41 | 42 | [.text-left] 43 | xref:nng_tls_config_alloc.3tls.adoc[nng_tls_config_alloc(3tls)], 44 | xref:nng.7.adoc[nng(7)] 45 | -------------------------------------------------------------------------------- /docs/man/nng_tls_config_hold.3tls.adoc: -------------------------------------------------------------------------------- 1 | = nng_tls_config_hold(3tls) 2 | // 3 | // Copyright 2019 Staysail Systems, Inc. 4 | // 5 | // This document is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | == NAME 12 | 13 | nng_tls_config_hold - hold TLS configuration object 14 | 15 | == SYNOPSIS 16 | 17 | [source, c] 18 | ---- 19 | #include 20 | #include 21 | 22 | void nng_tls_config_alloc(nng_tls_config *cfg); 23 | ---- 24 | 25 | == DESCRIPTION 26 | 27 | The `nng_tls_config_hold()` increments the reference count on 28 | the configuration object named by _cfg_, thereby preventing it 29 | from being freed while in use. 30 | 31 | The hold can be released by calling 32 | xref:nng_tls_config_free.3tls.adoc[`nng_tls_config_free()`]. 33 | 34 | Multiple holds can be placed on a configuration object; the object 35 | will not be freed until the last hold is released. 36 | 37 | == RETURN VALUES 38 | 39 | None. 40 | 41 | == ERRORS 42 | 43 | None. 44 | 45 | == SEE ALSO 46 | 47 | [.text-left] 48 | xref:nng_tls_config_alloc.3tls.adoc[nng_tls_config_alloc(3tls)], 49 | xref:nng_tls_config_free.3tls.adoc[nng_tls_config_free(3tls)], 50 | xref:nng.7.adoc[nng(7)] 51 | -------------------------------------------------------------------------------- /docs/man/nng_tls_config_server_name.3tls.adoc: -------------------------------------------------------------------------------- 1 | = nng_tls_config_server_name(3tls) 2 | // 3 | // Copyright 2020 Staysail Systems, Inc. 4 | // Copyright 2018 Capitar IT Group BV 5 | // 6 | // This document is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | == NAME 13 | 14 | nng_tls_config_server_name - configure remote server name 15 | 16 | == SYNOPSIS 17 | 18 | [source, c] 19 | ---- 20 | #include 21 | #include 22 | 23 | int nng_tls_config_server_name(nng_tls_config *cfg, const char *name); 24 | ---- 25 | 26 | == DESCRIPTION 27 | 28 | The `nng_tls_config_server_name()` function configures the remote server name 29 | to be used by a client when connection to a server. 30 | The supplied _name_ is used when comparing the identity in the 31 | server's certificate. 32 | Furthermore, when ((Server Name Indication)) (SNI) is used, the _name_ may 33 | be sent to the server as a hint to tell it which of several possible 34 | certificates should be used. 35 | 36 | TIP: This function is only useful in configuring client behavior. 37 | 38 | == RETURN VALUES 39 | 40 | This function returns 0 on success, and non-zero otherwise. 41 | 42 | == ERRORS 43 | 44 | [horizontal] 45 | `NNG_ENOMEM`:: Insufficient memory is available. 46 | `NNG_EBUSY`:: The configuration _cfg_ is already in use, and cannot be modified. 47 | 48 | == SEE ALSO 49 | 50 | [.text-left] 51 | xref:nng_strerror.3.adoc[nng_strerror(3)], 52 | xref:nng_tls_config_alloc.3tls.adoc[nng_tls_config_alloc(3tls)], 53 | xref:nng_tls_config_auth_mode.3tls.adoc[nng_tls_config_auth_mode(3tls)], 54 | xref:nng.7.adoc[nng(7)] 55 | -------------------------------------------------------------------------------- /docs/man/nng_tls_engine_description.3tls.adoc: -------------------------------------------------------------------------------- 1 | = nng_tls_engine_description(3tls) 2 | // 3 | // Copyright 2020 Staysail Systems, Inc. 4 | // 5 | // This document is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | == NAME 12 | 13 | nng_tls_engine_description - TLS engine description 14 | 15 | == SYNOPSIS 16 | 17 | [source,c] 18 | ---- 19 | #include 20 | 21 | const char *nng_tls_engine_description(void); 22 | ---- 23 | 24 | == DESCRIPTION 25 | 26 | The `nng_tls_engine_description()` returns a short description for the current 27 | xref:nng_tls_engine.5.adoc[TLS engine]. 28 | If no engine is registered, then the empty string ("") is returned. 29 | This is principally useful for diagnostic purposes. 30 | 31 | == RETURN VALUES 32 | 33 | The description of the engine of the engine. 34 | 35 | == ERRORS 36 | 37 | None. 38 | 39 | == SEE ALSO 40 | 41 | [.text-left] 42 | xref:nng_tls_engine_name.3tls.adoc[nng_tls_engine_name(3tls)], 43 | xref:nng_tls_engine.5.adoc[nng_tls_engine(5)], 44 | xref:nng.7.adoc[nng(7)] 45 | -------------------------------------------------------------------------------- /docs/man/nng_tls_engine_fips_mode.3tls.adoc: -------------------------------------------------------------------------------- 1 | = nng_tls_engine_fips_mode(3tls) 2 | // 3 | // Copyright 2020 Staysail Systems, Inc. 4 | // 5 | // This document is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | == NAME 12 | 13 | nng_tls_engine_fips_mode - TLS FIPS 140-2 mode indicator 14 | 15 | == SYNOPSIS 16 | 17 | [source,c] 18 | ---- 19 | #include 20 | 21 | bool nng_tls_engine_fips_mode(void); 22 | ---- 23 | 24 | == DESCRIPTION 25 | 26 | The `nng_tls_engine_fips_mode()` returns `true` if the 27 | xref:nng_tls_engine.5.adoc[TLS engine] is operating in FIPS 140-2 mode, 28 | and `false` otherwise. 29 | 30 | TIP: FIPS 140-2 references a United States standard for the use 31 | of cryptography in information processing systems. 32 | 33 | TIP: The default TLS engine does not support FIPS 140-2 mode, and 34 | will always return false. Alternative implementations with such 35 | support may be available from commercial suppliers. 36 | 37 | NOTE: Generally the FIPS 140-2 mode cannot be changed after program startup. 38 | 39 | == RETURN VALUES 40 | 41 | True if the TLS engine is in FIPS 140-2 mode, false otherwise. 42 | 43 | == ERRORS 44 | 45 | None. 46 | 47 | == SEE ALSO 48 | 49 | [.text-left] 50 | xref:nng_tls_engine.5.adoc[nng_tls_engine(5)], 51 | xref:nng.7.adoc[nng(7)] 52 | -------------------------------------------------------------------------------- /docs/man/nng_tls_engine_name.3tls.adoc: -------------------------------------------------------------------------------- 1 | = nng_tls_engine_name(3tls) 2 | // 3 | // Copyright 2020 Staysail Systems, Inc. 4 | // 5 | // This document is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | == NAME 12 | 13 | nng_tls_engine_name - TLS engine name 14 | 15 | == SYNOPSIS 16 | 17 | [source,c] 18 | ---- 19 | #include 20 | 21 | const char *nng_tls_engine_name(void); 22 | ---- 23 | 24 | == DESCRIPTION 25 | 26 | The `nng_tls_engine_name()` returns a short name for the current 27 | xref:nng_tls_engine.5.adoc[TLS engine]. 28 | If no engine is registered, then the special name "none" is returned. 29 | 30 | == RETURN VALUES 31 | 32 | The name of the engine. 33 | 34 | == ERRORS 35 | 36 | None. 37 | 38 | == SEE ALSO 39 | 40 | [.text-left] 41 | xref:nng_tls_engine_description.3tls.adoc[nng_tls_engine_description(3tls)], 42 | xref:nng_tls_engine.5.adoc[nng_tls_engine(5)] 43 | xref:nng.7.adoc[nng(7)] 44 | -------------------------------------------------------------------------------- /docs/ref/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | [Copyright](./copyright.md) 4 | [Dedication](./dedication.md) 5 | [Preface](./preface.md) 6 | 7 | - [API Reference](./api/index.md) 8 | 9 | - [Initialization](./api/init.md) 10 | 11 | - [Messages](./api/msg.md) 12 | 13 | - [Sockets](./api/sock.md) 14 | 15 | - [Contexts](./api/ctx.md) 16 | 17 | - [Pipes](./api/pipe.md) 18 | 19 | - [Memory](./api/memory.md) 20 | 21 | - [Time](./api/time.md) 22 | 23 | - [URLs](./api/url.md) 24 | 25 | - [Asynchronous I/O](./api/aio.md) 26 | 27 | - [Synchronization](./api/synch.md) 28 | 29 | - [Threads](./api/thread.md) 30 | 31 | - [Logging](./api/logging.md) 32 | 33 | - [Statistics](./api/stats.md) 34 | 35 | - [Errors](./api/errors.md) 36 | 37 | - [Streams](./api/stream.md) 38 | 39 | - [HTTP](./api/http.md) 40 | 41 | - [Miscellaneous](./api/misc.md) 42 | 43 | - [ID Map](./api/id_map.md) 44 | 45 | - [Arguments Parser](./api/args.md) 46 | 47 | - [Protocols](./proto/index.md) 48 | 49 | - [BUS Protocol](./proto/bus.md) 50 | - [PAIR Protocol](./proto/pair.md) 51 | - [PUB Protocol](./proto/pub.md) 52 | - [PULL Protocol](./proto/pull.md) 53 | - [PUSH Protocol](./proto/push.md) 54 | - [REP Protocol](./proto/rep.md) 55 | - [REQ Protocol](./proto/req.md) 56 | - [RESPONDENT Protocol](./proto/respondent.md) 57 | - [SUB Protocol](./proto/sub.md) 58 | - [SURVEYOR Protocol](./proto/surveyor.md) 59 | 60 | - [Transports](./tran/index.md) 61 | 62 | - [Intra-Process Transport](./tran/inproc.md) 63 | - [Inter-Process Transport](./tran/ipc.md) 64 | - [BSD Socket (Experimental)](./tran/socket.md) 65 | - [UDP Transport (Experimental)](./tran/udp.md) 66 | 67 | - [Migration Guides](./migrate/index.md) 68 | 69 | - [Migrating from NNG 1.x](./migrate/nng1.md) 70 | - [Migrating from libnanomsg](./migrate/nanomsg.md) 71 | 72 | [Index](./indexing.md) 73 | -------------------------------------------------------------------------------- /docs/ref/api/index.md: -------------------------------------------------------------------------------- 1 | # API Reference 2 | 3 | This section is a reference guide for the _NNG_ programming interfaces. 4 | It is meant to serve as a reference, rather than as a tutorial. 5 | 6 | The material here is organized by major areas of functionality. 7 | 8 | Note that unless indicated otherwise, consumers of these interfaces must 9 | include the `nng/nng.h` header file like so: 10 | 11 | ```c 12 | #include 13 | ``` 14 | 15 | ## Sections 16 | 17 | - [Initialization](init.md) 18 | - [Messages](msg.md) 19 | - [Sockets](sock.md) 20 | - [Contexts](ctx.md) 21 | - [Pipes](pipe.md) 22 | - [Memory](memory.md) 23 | - [Time](time.md) 24 | - [URLs](url.md) 25 | - [Synchronization](synch.md) 26 | - [Threads](thr.md) 27 | - [Logging](logging.md) 28 | - [Statistics](stats.md) 29 | - [HTTP](http.md) 30 | - [Miscellaneous](misc.md) 31 | - [Errors](errors.md) 32 | - [ID Map](id_map.md) 33 | - [Command Options](cmd_opts.md) 34 | -------------------------------------------------------------------------------- /docs/ref/dedication.md: -------------------------------------------------------------------------------- 1 | # Dedication 2 | 3 | --- _For Jenichka_ 4 | 5 | _The sun always shines when you are home._ 6 | -------------------------------------------------------------------------------- /docs/ref/indexing.md: -------------------------------------------------------------------------------- 1 | # Index 2 | -------------------------------------------------------------------------------- /docs/ref/migrate/index.md: -------------------------------------------------------------------------------- 1 | # Migration Guides 2 | 3 | This section provides some guides to aid in migrating software from 4 | earlier versions _NNG_ or _libnanomsg_. 5 | 6 | - [Migrating from NNG 1.x](./migrate/nng1.md) 7 | - [Migrating from libnanomsg](./migrate/nanomsg.md) 8 | -------------------------------------------------------------------------------- /docs/ref/proto/index.md: -------------------------------------------------------------------------------- 1 | # Protocols 2 | 3 | {{hi:protocol}} 4 | The Scalability Protocols are a principally a collection of common networking 5 | patterns found in applications. 6 | 7 | The following patterns are included: 8 | 9 | ## Request - Reply 10 | 11 | The {{i:request/reply pattern}} is made up of the [_REQ_][req] and [_REP_][rep] protocols. 12 | This most often used when implementing RPC-like services, where 13 | a given request is matched by a single reply. 14 | 15 | ## Pipeline 16 | 17 | The {{i:pipeline pattern}} is made up of the [_PUSH_][push] and [_PULL_][pull] 18 | protocols. 19 | 20 | In this pattern communication is {{i:half-duplex}}, in that one side sends 21 | data and another side receives. 22 | 23 | This pattern is also characterized by its ability to solve distribution 24 | problems, and the fact that it has {{i:back-pressure}}, providing a measure 25 | of {{i:flow control}} to data production and consumption. 26 | 27 | ## Publish - Subscribe 28 | 29 | ## Bus 30 | 31 | ## Pair 32 | 33 | [bus]: bus.md 34 | [pair]: pair.md 35 | [push]: push.md 36 | [pull]: pull.md 37 | [req]: req.md 38 | [rep]: rep.md 39 | [sub]: sub.md 40 | [pub]: pub.md 41 | [respondent]: respondent.md 42 | [surveyor]: surveyor.md 43 | -------------------------------------------------------------------------------- /docs/ref/proto/pub.md: -------------------------------------------------------------------------------- 1 | # PUB Protocol 2 | 3 | The {{i:*PUB* protocol}}{{hi:*PUB*}} is one half of a {{i:publisher}}/subscriber pattern. 4 | In this pattern, a publisher sends data, which is broadcast to all 5 | subscribers. 6 | The subscribing applications only see the data to which 7 | they have subscribed. 8 | 9 | The _PUB_ protocol is the publisher side, and the 10 | [_SUB_](sub.md) protocol is the subscriber side. 11 | 12 | > [!NOTE] 13 | > In this implementation, the publisher delivers all messages to all 14 | > subscribers. 15 | > The subscribers maintain their own subscriptions, and filter them locally. 16 | > Thus, this pattern should not be used in an attempt to reduce bandwidth 17 | > consumption. 18 | 19 | The topics that subscribers subscribe to is just the first part of 20 | the message body. 21 | Applications should construct their messages accordingly. 22 | 23 | ## Socket Operations 24 | 25 | The [`nng_pub0_open`][nng_pub_open] functions create a publisher socket. 26 | This socket may be used to send messages, but is unable to receive them. 27 | Attempts to receive messages will result in `NNG_ENOTSUP`. 28 | 29 | ## Protocol Versions 30 | 31 | Only version 0 of this protocol is supported. 32 | (At the time of writing, no other versions of this protocol have been defined.) 33 | 34 | ## Protocol Options 35 | 36 | The _PUB_ protocol has no protocol-specific options. 37 | 38 | ## Protocol Headers 39 | 40 | The _PUB_ protocol has no protocol-specific headers. 41 | 42 | [nng_pub_open]: TODO.md 43 | -------------------------------------------------------------------------------- /docs/ref/proto/pull.md: -------------------------------------------------------------------------------- 1 | # PULL protocol 2 | 3 | The {{i:*PULL* protocol}}{{hi:*PULL*}} is one half of a 4 | {{i:pipeline pattern}}. 5 | The other half is the [_PUSH_][push] protocol. 6 | 7 | In the pipeline pattern, pushers distribute messages to pullers. 8 | Each message sent 9 | by a pusher will be sent to one of its peer pullers, 10 | chosen in a round-robin fashion 11 | from the set of connected peers available for receiving. 12 | This property makes this pattern useful in {{i:load-balancing}} scenarios. 13 | 14 | ### Socket Operations 15 | 16 | The [`nng_pull0_open`][nng_pull_open] functions create a 17 | _PULL_ socket. 18 | This socket may be used to receive messages, but is unable to send them. 19 | Attempts to send messages will result in `NNG_ENOTSUP`. 20 | 21 | When receiving messages, the _PULL_ protocol accepts messages as 22 | they arrive from peers. 23 | If two peers both have a message ready, the 24 | order in which messages are handled is undefined. 25 | 26 | ### Protocol Versions 27 | 28 | Only version 0 of this protocol is supported. 29 | (At the time of writing, no other versions of this protocol have been defined.) 30 | 31 | ### Protocol Options 32 | 33 | The _PULL_ protocol has no protocol-specific options. 34 | 35 | ### Protocol Headers 36 | 37 | The _PULL_ protocol has no protocol-specific headers. 38 | 39 | [nng_pull_open]: TODO.md 40 | [push]: ./push.md 41 | -------------------------------------------------------------------------------- /docs/ref/proto/sub.md: -------------------------------------------------------------------------------- 1 | # SUB protocol 2 | 3 | The {{i:*SUB* protocol}}{{hi:*SUB*}} is one half of a publisher/{{i:subscriber}} pattern. 4 | In this pattern, a publisher sends data, which is broadcast to all subscribers. 5 | The subscribing applications only see the data to which they have subscribed. 6 | 7 | The _SUB_ protocol is the subscriber side, and the 8 | [_PUB_][pub] protocol is the publisher side. 9 | 10 | > [!NOTE] 11 | > The publisher delivers all messages to all subscribers. 12 | > The subscribers maintain their own subscriptions, and filter them locally. 13 | > Thus, this pattern should not be used in an attempt to 14 | > reduce bandwidth consumption. 15 | 16 | The topics that subscribers subscribe to is compared to the leading bytes of 17 | the message body. 18 | Applications should construct their messages accordingly. 19 | 20 | ### Socket Operations 21 | 22 | The [`nng_sub0_open`][nng_sub_open] functions create a _SUB_ socket. 23 | This socket may be used to receive messages, but is unable to send them. 24 | Attempts to send messages will result in `NNG_ENOTSUP`. 25 | 26 | ### Protocol Versions 27 | 28 | Only version 0 of this protocol is supported. 29 | (At the time of writing, no other versions of this protocol have been defined.) 30 | 31 | ### Protocol Options 32 | 33 | The following protocol-specific option is available. 34 | 35 | - {{i:`NNG_OPT_SUB_PREFNEW`}}: \ 36 | (`bool`) \ 37 | \ 38 | This read/write option specifies the behavior of the subscriber when the queue is full. 39 | When `true` (the default), the subscriber will make room in the queue by removing the oldest message. 40 | When `false`, the subscriber will reject messages if the message queue does not have room. 41 | 42 | ### Protocol Headers 43 | 44 | The _SUB_ protocol has no protocol-specific headers. 45 | 46 | [nng_sub_open]: TODO.md 47 | [nng_socket_set]: TODO.md 48 | [pub]: ./pub.md 49 | -------------------------------------------------------------------------------- /docs/ref/tran/index.md: -------------------------------------------------------------------------------- 1 | # Transports 2 | 3 | This section documents transports for Scalabity Protocols implemented by NNG. 4 | 5 | - [BSD Socket](socket.md) 6 | - [Intra-Process Transport](inproc.md) 7 | - [UDP](udp.md) 8 | -------------------------------------------------------------------------------- /docs/ref/tran/inproc.md: -------------------------------------------------------------------------------- 1 | # INPROC Transport 2 | 3 | The {{i:*inproc* transport}}{{hi:*inproc*}}{{i:intra-process}} provides communication support between 4 | sockets within the same process. 5 | This may be used as an alternative 6 | to slower transports when data must be moved within the same process. 7 | 8 | This transport tries hard to avoid copying data, and thus is very 9 | light-weight. 10 | 11 | ## URL Format 12 | 13 | This transport uses URLs using the scheme {{i:`inproc://`}}, followed by 14 | an arbitrary string of text, terminated by a `NUL` byte. 15 | 16 | Multiple URLs can be used within the 17 | same application, and they will not interfere with one another. 18 | 19 | Two applications may also use the same URL without interfering with each other. 20 | They will however be unable to communicate with each other using that URL. 21 | 22 | ## Socket Address 23 | 24 | When using an [`nng_sockaddr`] structure, the actual structure is of type [`nng_sockaddr_inproc`]. 25 | 26 | ## Transport Options 27 | 28 | The _inproc_ transport has no special options. 29 | 30 | > [!NOTE] 31 | > While _inproc_ accepts the option `NNG_OPT_RECVMAXSZ` for 32 | > compatibility, the value of the option is ignored with no enforcement. 33 | > As _inproc_ peers are in the same address space, they are implicitly 34 | > trusted, so the protection afforded by `NNG_OPT_RECVMAXSZ` is unnecessary. 35 | 36 | ## Mixing Implementations 37 | 38 | When mixing the _NNG_ library with other implementations of these 39 | protocols in the same process (such as the _mangos_ 40 | or _libnanomsg_ implementations), it will not be possible to utilize 41 | the _inproc_ transport to communicate across this boundary. 42 | 43 | This limitation also extends to using different instances of the _NNG_ 44 | library within the same process. 45 | 46 | {{#include ../xref.md}} 47 | -------------------------------------------------------------------------------- /etc/README.adoc: -------------------------------------------------------------------------------- 1 | = About This Directory 2 | 3 | This directory contains support files that I use for developing this 4 | project. 5 | 6 | == Coding Style 7 | 8 | A clang-format configuration file is included in the project, you should 9 | use that. (clang format requires that the style file live at the top of 10 | of the project tree, not somewhere else, such as this etc directory.) The 11 | format rules are probably inappropriate for the test/ subdirectory, as 12 | the Convey framework has a style all it's own. 13 | 14 | The style is based loosely on WebKit, but is really modified -- someday 15 | if clang-format ever learns about BSD KNF I'll probably switch to that. 16 | 17 | == Sublime Text 18 | 19 | I've also arranged for Sublime text to understand that .h is C, not C++ (this 20 | is important!) 21 | 22 | Having said that, these days I do most development on this project using CLion 23 | from JetBrains. 24 | 25 | == ISO Standard C 99 26 | 27 | This project uses C99. You may need to have modern compilers and 28 | a modern SDK. (Famously Windows Visual Studio releases older than 29 | 2015 will either work poorly, or not at all.) 30 | 31 | == Naming Conventions 32 | 33 | We use nng_ (and NNG_) for symbols that are intended to be exported to consumers. 34 | These symbols form part of our public API. 35 | 36 | We use nni_ and NNI_ for symbols that are *NOT* part of our public API and 37 | should not be used by users. 38 | 39 | Statics may have any non-conflicting name. 40 | 41 | Note that for the most part we try to avoid exposing structures directly to 42 | users so that they don't get baked into binaries -- preferring instead to 43 | dynamically allocate and give back an opaque pointer to the API. Any 44 | exceptions to this case need to be VERY carefully reviewed to make sure 45 | that the thing is unlikely to change (in any way whatsoever) in the future, 46 | or that adequate provisions for versioning have been made. 47 | -------------------------------------------------------------------------------- /etc/codecov.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2017 Garrett D'Amore 4 | # Copyright 2017 Capitar IT Group BV 5 | # 6 | # This software is supplied under the terms of the MIT License, a 7 | # copy of which should be located in the distribution where this 8 | # file was obtained (LICENSE.txt). A copy of the license may also be 9 | # found online at https://opensource.org/licenses/MIT. 10 | 11 | if [ "${COVERAGE}" != ON ] 12 | then 13 | echo "Code coverage not enabled." 14 | exit 0 15 | fi 16 | 17 | GCOV=${GCOV:-gcov} 18 | 19 | bash <(curl -s https://codecov.io/bash) -x gcov || echo "Codecov did not collect coverage" 20 | echo 0 21 | -------------------------------------------------------------------------------- /etc/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2017 Garrett D'Amore 4 | # Copyright 2017 Capitar IT Group BV 5 | # 6 | # This software is supplied under the terms of the MIT License, a 7 | # copy of which should be located in the distribution where this 8 | # file was obtained (LICENSE.txt). A copy of the license may also be 9 | # found online at https://opensource.org/licenses/MIT. 10 | 11 | if [ "${COVERAGE}" != ON ] 12 | then 13 | echo "Code coverage not enabled." 14 | exit 0 15 | fi 16 | 17 | GCOV=${GCOV:-gcov} 18 | 19 | # capture all coverage info 20 | lcov --gcov-tool ${GCOV} --directory . --capture --output-file coverage.info || exit 1 21 | 22 | # filter out system information (C++ templates & inlines) 23 | lcov --remove coverage.info '/usr/*' --output-file coverage.info || exit 1 24 | 25 | # filter out the *test* program data 26 | lcov --remove coverage.info '*/tests/*' --output-file coverage.info || exit 1 27 | 28 | # emit debug stats. 29 | lcov --list coverage.info 30 | 31 | rm coverage.info 32 | 33 | echo 0 34 | -------------------------------------------------------------------------------- /etc/nng.sublime-project: -------------------------------------------------------------------------------- 1 | { 2 | "folders": 3 | [ 4 | { 5 | "path": ".." 6 | } 7 | ], 8 | "settings": 9 | { 10 | "tab_size": 8, 11 | "translate_tabs_to_spaces": false, 12 | "ClangFormat": { 13 | "style": "File", 14 | "format_on_save": true 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/core/buf_size_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #include 12 | 13 | void 14 | test_buffer_options(void) 15 | { 16 | nng_socket s1; 17 | int val; 18 | char *opt; 19 | 20 | char *cases[] = { 21 | NNG_OPT_RECVBUF, 22 | NNG_OPT_SENDBUF, 23 | NULL, 24 | }; 25 | 26 | NUTS_PASS(nng_pair1_open(&s1)); 27 | for (int i = 0; (opt = cases[i]) != NULL; i++) { 28 | 29 | NUTS_CASE(opt); 30 | 31 | // Can set a valid size 32 | NUTS_PASS(nng_socket_set_int(s1, opt, 1234)); 33 | NUTS_PASS(nng_socket_get_int(s1, opt, &val)); 34 | NUTS_TRUE(val == 1234); 35 | 36 | // Can't set a negative size 37 | NUTS_FAIL(nng_socket_set_int(s1, opt, -5), NNG_EINVAL); 38 | 39 | // Buffer sizes are limited to sane levels 40 | NUTS_FAIL(nng_socket_set_int(s1, opt, 0x100000), NNG_EINVAL); 41 | } 42 | NUTS_CLOSE(s1); 43 | } 44 | 45 | NUTS_TESTS = { 46 | { "buffer options", test_buffer_options }, 47 | { NULL, NULL }, 48 | }; 49 | -------------------------------------------------------------------------------- /src/core/device.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2021 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #ifndef CORE_DEVICE_H 11 | #define CORE_DEVICE_H 12 | 13 | // Device takes messages from one side, and forwards them to the other. 14 | // It works in both directions. Arguably we should build versions of this 15 | // that are unidirectional, and we could extend this API with user-defined 16 | // filtering functions. 17 | extern void nni_device(nni_aio *aio, nni_sock *, nni_sock *); 18 | 19 | #endif // CORE_DEVICE_H 20 | -------------------------------------------------------------------------------- /src/core/dialer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2018 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef CORE_DIALER_H 13 | #define CORE_DIALER_H 14 | 15 | #include "defs.h" 16 | #include "stats.h" 17 | 18 | extern int nni_dialer_find(nni_dialer **, uint32_t); 19 | extern int nni_dialer_hold(nni_dialer *); 20 | extern void nni_dialer_rele(nni_dialer *); 21 | extern uint32_t nni_dialer_id(nni_dialer *); 22 | extern int nni_dialer_create(nni_dialer **, nni_sock *, const char *); 23 | extern int nni_dialer_create_url(nni_dialer **, nni_sock *, const nng_url *); 24 | extern void nni_dialer_close(nni_dialer *); 25 | extern int nni_dialer_start(nni_dialer *, unsigned); 26 | extern nni_sock *nni_dialer_sock(nni_dialer *); 27 | 28 | extern int nni_dialer_setopt( 29 | nni_dialer *, const char *, const void *, size_t, nni_type); 30 | extern int nni_dialer_getopt( 31 | nni_dialer *, const char *, void *, size_t *, nni_type); 32 | extern int nni_dialer_get_tls(nni_dialer *, nng_tls_config **); 33 | extern int nni_dialer_set_tls(nni_dialer *, nng_tls_config *); 34 | extern nng_url *nni_dialer_url(nni_dialer *); 35 | extern void nni_dialer_add_stat(nni_dialer *, nni_stat_item *); 36 | extern void nni_dialer_bump_error(nni_dialer *, int); 37 | 38 | #endif // CORE_DIALER_H 39 | -------------------------------------------------------------------------------- /src/core/errors_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | static void 16 | test_known_errors(void) 17 | { 18 | NUTS_MATCH(nng_strerror(0), "Hunky dory"); 19 | NUTS_MATCH(nng_strerror(NNG_ECLOSED), "Object closed"); 20 | NUTS_MATCH(nng_strerror(NNG_ETIMEDOUT), "Timed out"); 21 | NUTS_MATCH(nng_strerror(NNG_ESTOPPED), "Operation stopped"); 22 | } 23 | 24 | static void 25 | test_unknown_errors(void) 26 | { 27 | for (unsigned i = 1; i < 0x1000000; i = i * 2 + 100) { 28 | NUTS_TRUE(nng_strerror(i) != NULL); 29 | } 30 | } 31 | 32 | static void 33 | test_system_errors(void) 34 | { 35 | NUTS_MATCH(nng_strerror(NNG_ESYSERR + ENOENT), strerror(ENOENT)); 36 | NUTS_MATCH(nng_strerror(NNG_ESYSERR + EINVAL), strerror(EINVAL)); 37 | } 38 | 39 | NUTS_TESTS = { 40 | { "known errors", test_known_errors }, 41 | { "unknown errors", test_unknown_errors }, 42 | { "system errors", test_system_errors }, 43 | { NULL, NULL }, 44 | }; 45 | -------------------------------------------------------------------------------- /src/core/init.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2017 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef CORE_INIT_H 12 | #define CORE_INIT_H 13 | 14 | #include "nng/nng.h" 15 | 16 | // subsystems can call this to obtain a parameter value. 17 | nng_init_params *nni_init_get_params(void); 18 | 19 | #endif // CORE_INIT_H 20 | -------------------------------------------------------------------------------- /src/core/listener.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2018 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef CORE_LISTENER_H 13 | #define CORE_LISTENER_H 14 | 15 | #include "core/defs.h" 16 | #include "core/stats.h" 17 | 18 | extern int nni_listener_find(nni_listener **, uint32_t); 19 | extern int nni_listener_hold(nni_listener *); 20 | extern void nni_listener_rele(nni_listener *); 21 | extern uint32_t nni_listener_id(nni_listener *); 22 | extern int nni_listener_create(nni_listener **, nni_sock *, const char *); 23 | extern int nni_listener_create_url( 24 | nni_listener **, nni_sock *, const nng_url *); 25 | extern void nni_listener_close(nni_listener *); 26 | extern int nni_listener_start(nni_listener *, int); 27 | extern nni_sock *nni_listener_sock(nni_listener *); 28 | 29 | extern int nni_listener_setopt( 30 | nni_listener *, const char *, const void *, size_t, nni_type); 31 | extern int nni_listener_getopt( 32 | nni_listener *, const char *, void *, size_t *, nni_type); 33 | extern int nni_listener_get_tls(nni_listener *, nng_tls_config **); 34 | extern int nni_listener_set_tls(nni_listener *, nng_tls_config *); 35 | extern nng_err nni_listener_set_security_descriptor(nni_listener *, void *); 36 | extern nng_url *nni_listener_url(nni_listener *); 37 | extern void nni_listener_add_stat(nni_listener *, nni_stat_item *); 38 | extern void nni_listener_bump_error(nni_listener *, int); 39 | 40 | #endif // CORE_LISTENER_H 41 | -------------------------------------------------------------------------------- /src/core/lmq.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #ifndef CORE_LMQ_H 11 | #define CORE_LMQ_H 12 | 13 | #include "core/defs.h" 14 | 15 | // nni_lmq is a very lightweight message queue. Defining it this way allows 16 | // us to share some common code. Locking must be supplied by the caller. 17 | // For performance reasons, this is allocated inline. 18 | typedef struct nni_lmq { 19 | size_t lmq_cap; 20 | size_t lmq_alloc; // alloc is cap, rounded up to power of 2 21 | size_t lmq_mask; 22 | size_t lmq_len; 23 | size_t lmq_get; 24 | size_t lmq_put; 25 | nng_msg **lmq_msgs; 26 | nng_msg *lmq_buf[2]; // default minimal buffer 27 | } nni_lmq; 28 | 29 | extern void nni_lmq_init(nni_lmq *, size_t); 30 | extern void nni_lmq_fini(nni_lmq *); 31 | extern void nni_lmq_flush(nni_lmq *); 32 | extern size_t nni_lmq_len(nni_lmq *); 33 | extern size_t nni_lmq_cap(nni_lmq *); 34 | extern int nni_lmq_put(nni_lmq *lmq, nng_msg *msg); 35 | extern int nni_lmq_get(nni_lmq *lmq, nng_msg **mp); 36 | extern int nni_lmq_resize(nni_lmq *, size_t); 37 | extern bool nni_lmq_full(nni_lmq *); 38 | extern bool nni_lmq_empty(nni_lmq *); 39 | 40 | #endif // CORE_LMQ_H 41 | -------------------------------------------------------------------------------- /src/core/nng_impl.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2023 Staysail Systems, Inc. 3 | // Copyright 2017 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | #ifndef CORE_NNG_IMPL_H 11 | #define CORE_NNG_IMPL_H 12 | 13 | #include "nng/nng.h" 14 | 15 | // Internal implementation things for NNG, common definitions, etc. 16 | // All internal modules wind up including this file to avoid having 17 | // to figure out which header(s) to include. 18 | // 19 | // Hopefully it should be clear by the name that this file and its contents 20 | // are *NOT* for use outside of this library. 21 | // 22 | // Symbols that are private to the library begin with the nni_ prefix, whereas 23 | // those starting with nng_ are intended for external consumption. The latter 24 | // symbols should be found in the toplevel nng.h header. 25 | #include "core/defs.h" 26 | 27 | #include "core/platform.h" 28 | 29 | #include "core/aio.h" 30 | #include "core/device.h" 31 | #include "core/file.h" 32 | #include "core/idhash.h" 33 | #include "core/init.h" 34 | #include "core/list.h" 35 | #include "core/lmq.h" 36 | #include "core/message.h" 37 | #include "core/msgqueue.h" 38 | #include "core/options.h" 39 | #include "core/panic.h" 40 | #include "core/pollable.h" 41 | #include "core/protocol.h" 42 | #include "core/reap.h" 43 | #include "core/refcnt.h" 44 | #include "core/stats.h" 45 | #include "core/stream.h" 46 | #include "core/strs.h" 47 | #include "core/taskq.h" 48 | #include "core/thread.h" 49 | #include "core/url.h" 50 | 51 | // transport needs to come after url 52 | #include "sp/transport.h" 53 | 54 | // These have to come after the others - particularly transport.h 55 | 56 | #include "core/dialer.h" 57 | #include "core/listener.h" 58 | #include "core/pipe.h" 59 | #include "core/socket.h" 60 | 61 | #endif // CORE_NNG_IMPL_H 62 | -------------------------------------------------------------------------------- /src/core/panic.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2018 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef NNG_HAVE_BACKTRACE 17 | #include 18 | #endif 19 | 20 | #include "core/nng_impl.h" 21 | 22 | // Panic handling. 23 | void 24 | nni_show_backtrace(void) 25 | { 26 | #ifdef NNG_HAVE_BACKTRACE 27 | void *frames[50]; 28 | int nframes; 29 | 30 | nframes = backtrace(frames, sizeof(frames) / sizeof(frames[0])); 31 | if (nframes > 1) { 32 | char **lines = backtrace_symbols(frames, nframes); 33 | if (lines == NULL) { 34 | return; 35 | } 36 | for (int i = 1; i < nframes; i++) { 37 | nni_println(lines[i]); 38 | } 39 | } 40 | #endif 41 | } 42 | 43 | // nni_panic shows a panic message, a possible stack bracktrace, then aborts 44 | // the process/program. This should only be called when a condition arises 45 | // that should not be possible, e.g. a programming assertion failure. It should 46 | // not be called in situations such as ENOMEM, as nni_panic is fairly rude 47 | // to any application it may be called from within. 48 | void 49 | nni_panic(const char *fmt, ...) 50 | { 51 | char buf[100]; 52 | char fbuf[93]; // 7 bytes of "panic: " 53 | va_list va; 54 | 55 | va_start(va, fmt); 56 | (void) vsnprintf(fbuf, sizeof(fbuf), fmt, va); 57 | va_end(va); 58 | 59 | (void) snprintf(buf, sizeof(buf), "panic: %s", fbuf); 60 | 61 | nni_println(buf); 62 | nni_println("This message is indicative of a BUG."); 63 | nni_println("Report this at https://github.com/nanomsg/nng/issues"); 64 | 65 | nni_show_backtrace(); 66 | nni_plat_abort(); 67 | } 68 | 69 | void 70 | nni_println(const char *msg) 71 | { 72 | nni_plat_printf("%s\n", msg); 73 | } 74 | -------------------------------------------------------------------------------- /src/core/panic.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2016 Garrett D'Amore 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #ifndef CORE_PANIC_H 11 | #define CORE_PANIC_H 12 | 13 | // nni_panic is used to terminate the process with prejudice, and 14 | // should only be called in the face of a critical programming error, 15 | // or other situation where it would be unsafe to attempt to continue. 16 | // As this crashes the program, it should never be used when factors outside 17 | // the program can cause it, such as receiving protocol errors, or running 18 | // out of memory. Its better in those cases to return an error to the 19 | // program and let the caller handle the error situation. 20 | extern void nni_panic(const char *, ...); 21 | 22 | // nni_println is used to print output to a debug console. This should only 23 | // be used in the most dire of circumstances -- such as during an assertion 24 | // failure that is going to cause the program to crash. After the string is 25 | // emitted, a new line character is emitted, so the string should not 26 | // include one. 27 | extern void nni_println(const char *); 28 | 29 | #endif // CORE_PANIC_H 30 | -------------------------------------------------------------------------------- /src/core/pollable.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #ifndef CORE_POLLABLE_H 11 | #define CORE_POLLABLE_H 12 | 13 | #include "defs.h" 14 | #include "list.h" 15 | #include "platform.h" 16 | 17 | typedef struct nni_pollable nni_pollable; 18 | 19 | extern void nni_pollable_raise(nni_pollable *); 20 | extern void nni_pollable_clear(nni_pollable *); 21 | extern nng_err nni_pollable_getfd(nni_pollable *, int *); 22 | 23 | // nni_pollable implementation details are private. Only here for inlining. 24 | // We have joined the write and read file descriptors into a single 25 | // atomic 64, so we can update them together (and we can use cas to be sure 26 | // that such updates are always safe.) 27 | struct nni_pollable { 28 | nni_atomic_u64 p_fds; 29 | nni_atomic_bool p_raised; 30 | }; 31 | 32 | extern void nni_pollable_init(nni_pollable *); 33 | extern void nni_pollable_fini(nni_pollable *); 34 | 35 | #endif // CORE_POLLABLE_H 36 | -------------------------------------------------------------------------------- /src/core/refcnt.c: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Staysail Systems, Inc. 2 | // 3 | // This software is supplied under the terms of the MIT License, a 4 | // copy of which should be located in the distribution where this 5 | // file was obtained (LICENSE.txt). A copy of the license may also be 6 | // found online at https://opensource.org/licenses/MIT. 7 | // 8 | 9 | #include 10 | 11 | void 12 | nni_refcnt_init( 13 | nni_refcnt *rc, unsigned value, void *data, void (*fini)(void *)) 14 | { 15 | nni_atomic_init(&rc->rc_cnt); 16 | nni_atomic_set(&rc->rc_cnt, value); 17 | rc->rc_data = data; 18 | rc->rc_fini = fini; 19 | } 20 | 21 | void 22 | nni_refcnt_hold(nni_refcnt *rc) 23 | { 24 | nni_atomic_inc(&rc->rc_cnt); 25 | } 26 | 27 | void 28 | nni_refcnt_rele(nni_refcnt *rc) 29 | { 30 | if (nni_atomic_dec_nv(&rc->rc_cnt) == 0) { 31 | rc->rc_fini(rc->rc_data); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/core/refcnt.h: -------------------------------------------------------------------------------- 1 | // Copyright 2025 Staysail Systems, Inc. 2 | // 3 | // This software is supplied under the terms of the MIT License, a 4 | // copy of which should be located in the distribution where this 5 | // file was obtained (LICENSE.txt). A copy of the license may also be 6 | // found online at https://opensource.org/licenses/MIT. 7 | // 8 | 9 | #ifndef CORE_REFCNT_H 10 | #define CORE_REFCNT_H 11 | 12 | #include "defs.h" 13 | #include "platform.h" 14 | 15 | typedef struct { 16 | nni_atomic_int rc_cnt; 17 | void (*rc_fini)(void *); 18 | void *rc_data; 19 | } nni_refcnt; 20 | 21 | extern void nni_refcnt_init( 22 | nni_refcnt *rc, unsigned value, void *v, void (*fini)(void *)); 23 | extern void nni_refcnt_hold(nni_refcnt *rc); 24 | extern void nni_refcnt_rele(nni_refcnt *rc); 25 | 26 | #endif // CORE_REFCNT_H 27 | -------------------------------------------------------------------------------- /src/core/sockfd.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #ifndef CORE_FDC_H 11 | #define CORE_FDC_H 12 | 13 | #include "core/nng_impl.h" 14 | 15 | // the nni_sfd_conn struct is provided by platform code to wrap 16 | // an arbitrary byte stream file descriptor (UNIX) or handle (Windows) 17 | // with a nng_stream. 18 | typedef struct nni_sfd_conn nni_sfd_conn; 19 | extern nng_err nni_sfd_conn_alloc(nni_sfd_conn **cp, int fd); 20 | extern nng_err nni_sfd_dialer_alloc(nng_stream_dialer **, const nng_url *); 21 | extern nng_err nni_sfd_listener_alloc(nng_stream_listener **, const nng_url *); 22 | 23 | // this is used to close a file descriptor, in case we cannot 24 | // create a connection (or if the listener is closed before the 25 | // connection is accepted.) 26 | extern void nni_sfd_close_fd(int fd); 27 | 28 | #endif // CORE_FDC_H 29 | -------------------------------------------------------------------------------- /src/core/strs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2017 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef CORE_STRS_H 12 | #define CORE_STRS_H 13 | 14 | // Safe string functions, in case the platform misses these. 15 | 16 | #include "defs.h" 17 | 18 | extern char *nni_strdup(const char *); 19 | extern void nni_strfree(char *); 20 | extern size_t nni_strlcpy(char *, const char *, size_t); 21 | extern size_t nni_strnlen(const char *, size_t); 22 | extern char *nni_strcasestr(const char *, const char *); 23 | extern int nni_strncasecmp(const char *, const char *, size_t); 24 | extern int nni_strcasecmp(const char *, const char *); 25 | extern int nni_asprintf(char **, const char *, ...); 26 | 27 | #endif // CORE_STRS_H 28 | -------------------------------------------------------------------------------- /src/core/tcp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #ifndef CORE_TCP_H 11 | #define CORE_TCP_H 12 | 13 | #include "core/nng_impl.h" 14 | 15 | // These are interfaces we use for TCP internally. These are not exposed 16 | // to the public API. 17 | 18 | extern nng_err nni_tcp_dialer_alloc(nng_stream_dialer **, const nng_url *); 19 | extern nng_err nni_tcp_listener_alloc(nng_stream_listener **, const nng_url *); 20 | 21 | #endif // CORE_TCP_H 22 | -------------------------------------------------------------------------------- /src/core/url.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef CORE_URL_H 12 | #define CORE_URL_H 13 | 14 | #include "core/defs.h" 15 | 16 | struct nng_url { 17 | const char *u_scheme; // never NULL 18 | const char *u_userinfo; // will be NULL if not specified 19 | char *u_hostname; // name only, will be "" if not specified 20 | uint32_t u_port; // port, may be zero for schemes that do not use 21 | char *u_path; // path, will be "" if not specified 22 | char *u_query; // without '?', will be NULL if not specified 23 | char *u_fragment; // without '#', will be NULL if not specified 24 | // these members are private 25 | char *u_buffer; 26 | size_t u_bufsz; 27 | char u_static[NNG_MAXADDRLEN]; // Most URLs fit within this 28 | }; 29 | 30 | extern uint16_t nni_url_default_port(const char *); 31 | extern nng_err nni_url_asprintf(char **, const nng_url *); 32 | extern nng_err nni_url_asprintf_port(char **, const nng_url *, int); 33 | extern size_t nni_url_decode(uint8_t *, const char *, size_t); 34 | extern nng_err nni_url_to_address(nng_sockaddr *, const nng_url *); 35 | extern nng_err nni_url_parse_inline(nng_url *, const char *); 36 | extern nng_err nni_url_clone_inline(nng_url *, const nng_url *); 37 | extern void nni_url_fini(nng_url *); 38 | extern nng_err nni_url_canonify_uri(char *); 39 | 40 | #endif // CORE_URL_H 41 | -------------------------------------------------------------------------------- /src/nng_legacy.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #ifndef NNG_ELIDE_DEPRECATED 11 | #include "core/nng_impl.h" 12 | 13 | #endif // NNG_ELIDE_DEPRECATED 14 | -------------------------------------------------------------------------------- /src/platform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2024 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # Platforms. 11 | nng_directory(platform) 12 | 13 | add_subdirectory(posix) 14 | add_subdirectory(windows) 15 | 16 | nng_test(files_test) 17 | nng_test(ipc_stream_test) 18 | nng_test(platform_test) 19 | nng_test(resolver_test) 20 | nng_test(tcp_stream_test) 21 | nng_test(udp_test) 22 | -------------------------------------------------------------------------------- /src/platform/posix/posix_alloc.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2016 Garrett D'Amore 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #include "core/nng_impl.h" 11 | 12 | #ifdef NNG_PLATFORM_POSIX 13 | 14 | #include 15 | 16 | // POSIX memory allocation. This is pretty much standard C. 17 | void * 18 | nni_alloc(size_t sz) 19 | { 20 | return (sz > 0 ? malloc(sz) : NULL); 21 | } 22 | 23 | void * 24 | nni_zalloc(size_t sz) 25 | { 26 | return (sz > 0 ? calloc(1, sz) : NULL); 27 | } 28 | 29 | void 30 | nni_free(void *ptr, size_t size) 31 | { 32 | NNI_ARG_UNUSED(size); 33 | free(ptr); 34 | } 35 | 36 | #endif // NNG_PLATFORM_POSIX 37 | -------------------------------------------------------------------------------- /src/platform/posix/posix_ipc.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2019 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef PLATFORM_POSIX_IPC_H 13 | #define PLATFORM_POSIX_IPC_H 14 | 15 | #include "core/nng_impl.h" 16 | #include "core/stream.h" 17 | 18 | #ifdef NNG_PLATFORM_POSIX 19 | #include "posix_aio.h" 20 | 21 | #include // For mode_t 22 | 23 | struct nni_ipc_conn { 24 | nng_stream stream; 25 | nni_posix_pfd pfd; 26 | nni_list readq; 27 | nni_list writeq; 28 | bool closed; 29 | nni_mtx mtx; 30 | nni_aio *dial_aio; 31 | nni_ipc_dialer *dialer; 32 | nng_sockaddr sa; 33 | nni_reap_node reap; 34 | }; 35 | 36 | struct nni_ipc_dialer { 37 | nng_stream_dialer sd; 38 | nni_list connq; // pending connections 39 | bool closed; 40 | nni_mtx mtx; 41 | nng_sockaddr sa; 42 | nni_refcnt ref; 43 | #ifdef NNG_TEST_LIB 44 | bool no_connect; // don't actually connect, for testing cancellation, 45 | #endif 46 | }; 47 | 48 | extern int nni_posix_ipc_alloc( 49 | nni_ipc_conn **, nni_sockaddr *, nni_ipc_dialer *, int); 50 | extern void nni_posix_ipc_dialer_rele(nni_ipc_dialer *); 51 | extern void nni_posix_ipc_dialer_cb(void *arg, unsigned events); 52 | 53 | #endif // NNG_PLATFORM_POSIX 54 | 55 | #endif // PLATFORM_POSIX_IPC_H 56 | -------------------------------------------------------------------------------- /src/platform/posix/posix_ipcwinsec_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | #include 11 | #include 12 | 13 | void 14 | test_ipc_win_sec(void) 15 | { 16 | char address[64]; 17 | nng_stream_listener *l; 18 | int x; 19 | 20 | nuts_scratch_addr("ipc", sizeof(address), address); 21 | NUTS_PASS(nng_stream_listener_alloc(&l, address)); 22 | NUTS_FAIL( 23 | nng_stream_listener_set_security_descriptor(l, &x), NNG_ENOTSUP); 24 | nng_stream_listener_free(l); 25 | } 26 | 27 | NUTS_TESTS = { 28 | { "ipc security descriptor", test_ipc_win_sec }, 29 | { NULL, NULL }, 30 | }; 31 | -------------------------------------------------------------------------------- /src/platform/posix/posix_peerid.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #ifndef PLATFORM_POSIX_PEERID_H 11 | #define PLATFORM_POSIX_PEERID_H 12 | 13 | // This file defines structures we will use for emulating asynchronous I/O 14 | // on POSIX. POSIX lacks the support for callback based asynchronous I/O 15 | // that we have on Windows, although it has a non-widely support aio layer 16 | // that is not very performant on many systems. So we emulate this using 17 | // one of several possible different backends. 18 | 19 | #include "core/nng_impl.h" 20 | #include 21 | 22 | int nni_posix_peerid(int fd, int *euid, int *egid, int *prid, int *znid); 23 | 24 | #endif // PLATFORM_POSIX_PEERID_H 25 | -------------------------------------------------------------------------------- /src/platform/posix/posix_pollq.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef PLATFORM_POSIX_POLLQ_H 12 | #define PLATFORM_POSIX_POLLQ_H 13 | 14 | #ifdef NNG_PLATFORM_POSIX 15 | 16 | // This file defines structures we will use for emulating asynchronous I/O 17 | // on POSIX. POSIX lacks the support for callback based asynchronous I/O 18 | // that we have on Windows, although it has a non-widely support aio layer 19 | // that is not very performant on many systems. So we emulate this using 20 | // one of several possible different backends. 21 | 22 | #include "core/nng_impl.h" 23 | 24 | typedef struct nni_posix_pfd nni_posix_pfd; 25 | typedef void (*nni_posix_pfd_cb)(void *, unsigned); 26 | 27 | #if defined(NNG_POLLQ_KQUEUE) 28 | #include "posix_pollq_kqueue.h" 29 | #elif defined(NNG_POLLQ_PORTS) 30 | #include "posix_pollq_port.h" 31 | #elif defined(NNG_POLLQ_EPOLL) 32 | #include "posix_pollq_epoll.h" 33 | #elif defined(NNG_POLLQ_POLL) 34 | #include "posix_pollq_poll.h" 35 | #elif defined(NNG_POLLQ_SELECT) 36 | #include "posix_pollq_select.h" 37 | #else 38 | #error "No suitable poller defined" 39 | #endif 40 | 41 | extern void nni_posix_pfd_init(nni_posix_pfd *, int, nni_posix_pfd_cb, void *); 42 | extern void nni_posix_pfd_fini(nni_posix_pfd *); 43 | extern void nni_posix_pfd_stop(nni_posix_pfd *); 44 | extern int nni_posix_pfd_arm(nni_posix_pfd *, unsigned); 45 | extern int nni_posix_pfd_fd(nni_posix_pfd *); 46 | extern void nni_posix_pfd_close(nni_posix_pfd *); 47 | 48 | #endif // NNG_PLATFORM_POSIX 49 | 50 | #endif // PLATFORM_POSIX_POLLQ_H 51 | -------------------------------------------------------------------------------- /src/platform/posix/posix_pollq_epoll.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef PLATFORM_POSIX_POLLQ_EPOLL_H 12 | #define PLATFORM_POSIX_POLLQ_EPOLL_H 13 | 14 | #include 15 | 16 | // nni_posix_pfd is the handle used by the poller. It's internals are private 17 | // to the poller. 18 | struct nni_posix_pfd { 19 | nni_list_node node; 20 | struct nni_posix_pollq *pq; 21 | int fd; 22 | nni_posix_pfd_cb cb; 23 | void *arg; 24 | nni_atomic_int events; 25 | bool added; 26 | nni_atomic_flag stopped; 27 | nni_atomic_flag closing; 28 | }; 29 | 30 | #define NNI_POLL_IN ((unsigned) POLLIN) 31 | #define NNI_POLL_OUT ((unsigned) POLLOUT) 32 | #define NNI_POLL_HUP ((unsigned) POLLHUP) 33 | #define NNI_POLL_ERR ((unsigned) POLLERR) 34 | #define NNI_POLL_INVAL ((unsigned) POLLNVAL) 35 | 36 | #endif // PLATFORM_POSIX_POLLQ_EPOLL_H 37 | -------------------------------------------------------------------------------- /src/platform/posix/posix_pollq_kqueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef PLATFORM_POSIX_POLLQ_KQUEUE_H 12 | #define PLATFORM_POSIX_POLLQ_KQUEUE_H 13 | 14 | // nni_posix_pfd is the handle used by the poller. It's internals are private 15 | // to the poller. 16 | struct nni_posix_pfd { 17 | nni_list_node node; // linkage into the reap list 18 | struct nni_posix_pollq *pq; // associated pollq 19 | int fd; // file descriptor to poll 20 | void *arg; // user data 21 | nni_posix_pfd_cb cb; // user callback on event 22 | nni_atomic_flag closed; 23 | nni_atomic_flag stopped; 24 | bool reaped; 25 | nni_atomic_int events; 26 | nni_cv cv; // signaled when poller has unregistered 27 | }; 28 | 29 | #define NNI_POLL_IN (0x0001) 30 | #define NNI_POLL_OUT (0x0010) 31 | #define NNI_POLL_HUP (0x0004) 32 | #define NNI_POLL_ERR (0x0008) 33 | #define NNI_POLL_INVAL (0x0020) 34 | 35 | #endif // PLATFORM_POSIX_POLLQ_KQUEUE_H 36 | -------------------------------------------------------------------------------- /src/platform/posix/posix_pollq_poll.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef PLATFORM_POSIX_POLLQ_POLL_H 12 | #define PLATFORM_POSIX_POLLQ_POLL_H 13 | 14 | #include 15 | 16 | // nni_posix_pfd is the handle used by the poller. It's internals are private 17 | // to the poller. 18 | struct nni_posix_pfd { 19 | struct nni_posix_pollq *pq; 20 | int fd; 21 | nni_list_node node; 22 | nni_list_node reap; 23 | nni_atomic_int events; 24 | nni_posix_pfd_cb cb; 25 | void *arg; 26 | bool reaped; 27 | }; 28 | 29 | #define NNI_POLL_IN ((unsigned) POLLIN) 30 | #define NNI_POLL_OUT ((unsigned) POLLOUT) 31 | #define NNI_POLL_HUP ((unsigned) POLLHUP) 32 | #define NNI_POLL_ERR ((unsigned) POLLERR) 33 | #define NNI_POLL_INVAL ((unsigned) POLLNVAL) 34 | 35 | #endif // PLATFORM_POSIX_POLLQ_POLL_H 36 | -------------------------------------------------------------------------------- /src/platform/posix/posix_pollq_port.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef PLATFORM_POSIX_POLLQ_PORT_H 12 | #define PLATFORM_POSIX_POLLQ_PORT_H 13 | 14 | #include 15 | 16 | typedef struct nni_posix_pollq nni_posix_pollq; 17 | 18 | // nni_posix_pfd is the handle used by the poller. It's internals are private 19 | // to the poller. 20 | struct nni_posix_pfd { 21 | nni_posix_pollq *pq; 22 | int fd; 23 | nni_atomic_int events; 24 | bool closed; 25 | nni_posix_pfd_cb cb; 26 | void *data; 27 | }; 28 | 29 | #define NNI_POLL_IN ((unsigned) POLLIN) 30 | #define NNI_POLL_OUT ((unsigned) POLLOUT) 31 | #define NNI_POLL_HUP ((unsigned) POLLHUP) 32 | #define NNI_POLL_ERR ((unsigned) POLLERR) 33 | #define NNI_POLL_INVAL ((unsigned) POLLNVAL) 34 | 35 | #endif // PLATFORM_POSIX_POLLQ_PORT_H 36 | -------------------------------------------------------------------------------- /src/platform/posix/posix_pollq_select.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef PLATFORM_POSIX_POLLQ_SELECT_H 12 | #define PLATFORM_POSIX_POLLQ_SELECT_H 13 | 14 | // nni_posix_pfd is the handle used by the poller. It's internals are private 15 | // to the poller. 16 | struct nni_posix_pfd { 17 | struct nni_posix_pollq *pq; 18 | int fd; 19 | nni_cv cv; 20 | nni_mtx mtx; 21 | unsigned events; 22 | nni_posix_pfd_cb cb; 23 | void *arg; 24 | bool reap; 25 | bool stopped; 26 | }; 27 | 28 | #define NNI_POLL_IN (0x0001) 29 | #define NNI_POLL_OUT (0x0010) 30 | #define NNI_POLL_HUP (0x0004) 31 | #define NNI_POLL_ERR (0x0008) 32 | #define NNI_POLL_INVAL (0x0020) 33 | 34 | #endif // PLATFORM_POSIX_POLLQ_SELECT_H 35 | -------------------------------------------------------------------------------- /src/platform/posix/posix_rand_arc4random.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | // arc4random is the preferred source of cryptographic random numbers 11 | // on any platform where it is found. 12 | #include 13 | 14 | #include "core/nng_impl.h" 15 | 16 | #ifdef NNG_HAVE_ARC4RANDOM 17 | 18 | uint32_t 19 | nni_random(void) 20 | { 21 | return (arc4random()); 22 | } 23 | 24 | #endif -------------------------------------------------------------------------------- /src/platform/posix/posix_rand_getentropy.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | // getrandom is not as nice as arc4random, but on platforms where it 11 | // exists and arc4random does not, we should use it. 12 | // 13 | // getrandom will block only if the urandom device is not seeded yet. 14 | // That can only happen during very early boot (earlier than we should 15 | // normally be running. This is the only time it can fail with correct 16 | // arguments, and then only if it is interrupted with a signal. 17 | 18 | #include 19 | #include 20 | #include 21 | #ifdef NNG_HAVE_SYS_RANDOM 22 | #include 23 | #endif 24 | 25 | #include "core/panic.h" 26 | 27 | #ifdef NNG_HAVE_GETENTROPY 28 | 29 | uint32_t 30 | nni_random(void) 31 | { 32 | uint32_t val; 33 | if (getentropy(&val, sizeof(val)) != 0) { 34 | nni_panic("getentropy failed"); 35 | } 36 | return (val); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/platform/posix/posix_rand_getrandom.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | // getrandom is not as nice as arc4random, but on platforms where it 11 | // exists and arc4random does not, we should use it. 12 | // 13 | // getrandom will block only if the urandom device is not seeded yet. 14 | // That can only happen during very early boot (earlier than we should 15 | // normally be running. This is the only time it can fail with correct 16 | // arguments, and then only if it is interrupted with a signal. 17 | 18 | #include 19 | #include 20 | 21 | #include "core/nng_impl.h" 22 | 23 | #ifdef NNG_HAVE_GETRANDOM 24 | 25 | uint32_t 26 | nni_random(void) 27 | { 28 | uint32_t val; 29 | 30 | // Documentation claims that as long as we are not using 31 | // GRND_RANDOM and buflen < 256, this should never fail. 32 | // The exception here is that we could fail if for some 33 | // reason we got a signal while blocked at very early boot 34 | // (i.e. /dev/urandom was not yet seeded). 35 | if (getrandom(&val, sizeof(val), 0) != sizeof(val)) { 36 | nni_panic("getrandom failed"); 37 | } 38 | return (val); 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/platform/posix/posix_rand_urandom.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "core/nng_impl.h" 18 | 19 | // The historic /dev/urandom device. This is not as a good as 20 | // a system call, since file descriptor attacks are possible, and it may 21 | // need special permissions. Modern advice is to always use /dev/urandom 22 | // unless you have very particular reasons for doing otherwise. 23 | // If you're in this code base, you're probably on either an ancient OS, 24 | // or one of the off-beat ones that hasn't updated for support with 25 | // arc4random or getrandom. 26 | 27 | // We could use ISAAC or something like that to seed it only once, 28 | // but instead we just keep our file descriptor open. This will have 29 | // the apparent effect of leaking these file descriptors across fork. 30 | 31 | static int urandom_fd = -1; 32 | static pthread_mutex_t urandom_lock = PTHREAD_MUTEX_INITIALIZER; 33 | 34 | #ifndef O_CLOEXEC 35 | #define O_CLOEXEC 0u 36 | #endif 37 | 38 | uint32_t 39 | nni_random(void) 40 | { 41 | int fd; 42 | uint32_t val; 43 | 44 | (void) pthread_mutex_lock(&urandom_lock); 45 | if ((fd = urandom_fd) == -1) { 46 | if ((fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC)) < 0) { 47 | (void) pthread_mutex_unlock(&urandom_lock); 48 | nni_panic("failed to open /dev/urandom"); 49 | } 50 | urandom_fd = fd; 51 | } 52 | (void) pthread_mutex_unlock(&urandom_lock); 53 | 54 | if (read(fd, &val, sizeof(val)) != sizeof(val)) { 55 | nni_panic("failed reading /dev/urandom"); 56 | } 57 | return (val); 58 | } -------------------------------------------------------------------------------- /src/platform/posix/posix_socketpair.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #include "core/nng_impl.h" 11 | 12 | #ifdef NNG_HAVE_SOCKETPAIR 13 | // This provides an implementation of socketpair(), which is supposed 14 | // to be present on XPG6 and newer. This trivial implementation 15 | // only supports SOCK_STREAM over AF_UNIX. Which is sufficient for 16 | // most purposes. The fds array should point to an int[2]. 17 | #include 18 | #include 19 | 20 | nng_err 21 | nni_socket_pair(int fds[2]) 22 | { 23 | int rv; 24 | rv = socketpair(PF_UNIX, SOCK_STREAM, 0, fds); 25 | if (rv != 0) { 26 | return (nni_plat_errno(errno)); 27 | } 28 | 29 | #ifdef SO_NOSIGPIPE 30 | int set = 1; 31 | setsockopt( 32 | fds[0], SOL_SOCKET, SO_NOSIGPIPE, (void *) &set, sizeof(int)); 33 | setsockopt( 34 | fds[1], SOL_SOCKET, SO_NOSIGPIPE, (void *) &set, sizeof(int)); 35 | #endif 36 | 37 | return (0); 38 | } 39 | #else 40 | nng_err 41 | nni_socket_pair(int fds[2]) 42 | { 43 | return (NNG_ENOTSUP); 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /src/platform/posix/posix_tcp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2018 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef PLATFORM_POSIX_TCP_H 13 | #define PLATFORM_POSIX_TCP_H 14 | 15 | #include "core/nng_impl.h" 16 | 17 | #include "platform/posix/posix_aio.h" 18 | 19 | struct nni_tcp_conn { 20 | nng_stream stream; 21 | nni_posix_pfd pfd; 22 | nni_list readq; 23 | nni_list writeq; 24 | bool closed; 25 | nni_mtx mtx; 26 | nni_aio *dial_aio; 27 | nni_tcp_dialer *dialer; 28 | nni_reap_node reap; 29 | }; 30 | 31 | extern int nni_posix_tcp_alloc(nni_tcp_conn **, nni_tcp_dialer *, int); 32 | extern void nni_posix_tcp_start(nni_tcp_conn *, int, int); 33 | extern void nni_posix_tcp_dialer_rele(nni_tcp_dialer *); 34 | extern void nni_posix_tcp_dial_cb(void *, unsigned); 35 | 36 | #endif // PLATFORM_POSIX_TCP_H 37 | -------------------------------------------------------------------------------- /src/platform/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2024 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # Windows. 11 | 12 | # We cannot use nng_sources_if because these tests don't go into 13 | # the static library unless they also go into the dynamic. 14 | if (NNG_PLATFORM_WINDOWS) 15 | nng_check_sym(InitializeConditionVariable windows.h NNG_HAVE_CONDVAR) 16 | nng_check_sym(timespec_get time.h NNG_HAVE_TIMESPEC_GET) 17 | nng_check_sym(snprintf stdio.h NNG_HAVE_SNPRINTF) 18 | if (NOT NNG_HAVE_CONDVAR OR NOT NNG_HAVE_SNPRINTF OR NOT NNG_HAVE_TIMESPEC_GET) 19 | message(FATAL_ERROR 20 | "Modern Windows API support is missing. " 21 | "Versions of Windows prior to Vista are not supported. " 22 | "Further, the legacy MinGW environments are not supported. " 23 | "Ensure you have at least Windows Vista or newer, and are " 24 | "using either Visual Studio 2013 or compatible compiler, " 25 | "and are also using the universal C runtime (UCRT).") 26 | endif () 27 | nng_link_libraries(ws2_32 mswsock advapi32) 28 | 29 | nng_sources( 30 | win_impl.h 31 | win_ipc.h 32 | win_tcp.h 33 | win_clock.c 34 | win_debug.c 35 | win_file.c 36 | win_io.c 37 | win_ipcconn.c 38 | win_ipcdial.c 39 | win_ipclisten.c 40 | win_pipe.c 41 | win_rand.c 42 | win_resolv.c 43 | win_sockaddr.c 44 | win_socketpair.c 45 | win_tcp.c 46 | win_tcpconn.c 47 | win_tcpdial.c 48 | win_tcplisten.c 49 | win_thread.c 50 | win_udp.c 51 | ) 52 | 53 | nng_test(win_ipc_sec_test) 54 | 55 | endif () 56 | -------------------------------------------------------------------------------- /src/platform/windows/win_clock.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Garrett D'Amore 3 | // Copyright 2017 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #include "core/nng_impl.h" 12 | 13 | #include 14 | 15 | #ifdef NNG_PLATFORM_WINDOWS 16 | 17 | nni_time 18 | nni_clock(void) 19 | { 20 | // We are limited by the system clock, but that is ok. 21 | return (GetTickCount64()); 22 | } 23 | 24 | int 25 | nni_time_get(uint64_t *seconds, uint32_t *nanoseconds) 26 | { 27 | struct timespec ts; 28 | if (timespec_get(&ts, TIME_UTC) == TIME_UTC) { 29 | *seconds = ts.tv_sec; 30 | *nanoseconds = ts.tv_nsec; 31 | return (0); 32 | } 33 | return (nni_win_error(GetLastError())); 34 | } 35 | 36 | void 37 | nni_msleep(nni_duration dur) 38 | { 39 | uint64_t exp; 40 | 41 | exp = (uint64_t) GetTickCount64() + dur; 42 | 43 | // Sleep() would be our preferred API, if it didn't have a nasty 44 | // feature where it rounds *down*. We always want to sleep *at 45 | // least* the requested amount of time, and never ever less. 46 | // If we wind up sleeping less, then we will sleep(1) in the hope 47 | // of waiting until the next clock tick. 48 | 49 | Sleep((DWORD) dur); 50 | while ((uint64_t) GetTickCount64() < exp) { 51 | Sleep(1); 52 | } 53 | } 54 | 55 | #endif // NNG_PLATFORM_WINDOWS 56 | -------------------------------------------------------------------------------- /src/platform/windows/win_ipc.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2019 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2019 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef PLATFORM_WIN_WINIPC_H 13 | #define PLATFORM_WIN_WINIPC_H 14 | 15 | // This header file is private to the IPC (named pipes) support for Windows. 16 | 17 | #include "core/nng_impl.h" 18 | #include "win_impl.h" 19 | 20 | #define IPC_PIPE_PREFIX "\\\\.\\pipe\\" 21 | 22 | extern int nni_win_ipc_init(nng_stream **, HANDLE, const nng_sockaddr *, bool); 23 | 24 | #endif // NNG_PLATFORM_WIN_WINIPC_H 25 | -------------------------------------------------------------------------------- /src/platform/windows/win_rand.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #include "core/nng_impl.h" 11 | 12 | #ifdef NNG_PLATFORM_WINDOWS 13 | 14 | #ifndef _CRT_RAND_S 15 | #define _CRT_RAND_S 16 | #endif 17 | 18 | #include 19 | 20 | uint32_t 21 | nni_random(void) 22 | { 23 | unsigned val; 24 | 25 | // rand_s is claimed by Microsoft to generate cryptographically 26 | // secure numbers. It also is claimed that this will only fail 27 | // for EINVAL if val is NULL (not the case here). Other error 28 | // conditions might be possible, but we have no way to tell. 29 | // For now we just ignore that possibility. 30 | rand_s(&val); 31 | return ((uint32_t)val); 32 | } 33 | 34 | #endif // NNG_PLATFORM_WINDOWS -------------------------------------------------------------------------------- /src/platform/windows/win_socketpair.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2023 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #include "core/nng_impl.h" 11 | 12 | #ifdef NNG_HAVE_SOCKETPAIR_TODO 13 | // TODO: Windows lacks socketpair. We can emulate it with an explicit 14 | // implementation based on AF_UNIX. 15 | 16 | #include 17 | #include 18 | 19 | int 20 | nni_socket_pair(int fds[2]) 21 | { 22 | int rv; 23 | rv = socketpair(PF_UNIX, SOCK_STREAM, 0, fds); 24 | if (rv != 0) { 25 | return (nni_plat_errno(errno)); 26 | } 27 | 28 | return (0); 29 | } 30 | #else 31 | int 32 | nni_socket_pair(int fds[2]) 33 | { 34 | NNI_ARG_UNUSED(fds); 35 | return (NNG_ENOTSUP); 36 | } 37 | 38 | // This is also the fdc transport. 39 | 40 | typedef struct nni_sfd_conn nni_sfd_conn; 41 | 42 | void 43 | nni_sfd_close_fd(int fd) 44 | { 45 | NNI_ARG_UNUSED(fd); 46 | } 47 | 48 | nng_err 49 | nni_sfd_conn_alloc(nni_sfd_conn **cp, int fd) 50 | { 51 | NNI_ARG_UNUSED(cp); 52 | NNI_ARG_UNUSED(fd); 53 | return (NNG_ENOTSUP); 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/platform/windows/win_tcp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2019 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef PLATFORM_WIN_WINTCP_H 13 | #define PLATFORM_WIN_WINTCP_H 14 | 15 | // This header file is private to the TCP support for Windows. 16 | 17 | #include "core/nng_impl.h" 18 | 19 | struct nni_tcp_conn { 20 | nng_stream ops; 21 | SOCKET s; 22 | nni_win_io recv_io; 23 | nni_win_io send_io; 24 | nni_win_io conn_io; 25 | nni_list recv_aios; 26 | nni_list send_aios; 27 | nni_aio *conn_aio; 28 | SOCKADDR_STORAGE sockname; 29 | SOCKADDR_STORAGE peername; 30 | nni_tcp_dialer *dialer; 31 | void *listener; 32 | int recv_rv; 33 | int send_rv; 34 | int conn_rv; 35 | bool closed; 36 | char buf[512]; // to hold acceptex results 37 | bool sending; 38 | bool recving; 39 | nni_mtx mtx; 40 | nni_cv cv; 41 | }; 42 | 43 | extern int nni_win_tcp_init(nni_tcp_conn **, SOCKET); 44 | 45 | // Following functions are wrappers around Windows functions that have to be 46 | // looked up by pointer/GUID. 47 | extern int nni_win_acceptex( 48 | SOCKET listen, SOCKET child, void *buf, LPOVERLAPPED olpd); 49 | extern void nni_win_get_acceptex_sockaddrs( 50 | void *buf, SOCKADDR_STORAGE *self, SOCKADDR_STORAGE *peer); 51 | extern int nni_win_connectex( 52 | SOCKET s, SOCKADDR *peer, int peer_len, LPOVERLAPPED olpd); 53 | 54 | #endif // NNG_PLATFORM_WIN_WINTCP_H 55 | -------------------------------------------------------------------------------- /src/sp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2024 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | nng_directory(sp) 11 | 12 | add_subdirectory(protocol) 13 | add_subdirectory(transport) 14 | 15 | nng_sources( 16 | protocol.c 17 | transport.c 18 | transport.h 19 | ) 20 | 21 | nng_test(pipe_test) 22 | nng_test(device_test) 23 | nng_test(multistress_test) 24 | nng_test(nonblock_test) 25 | nng_test(scalability_test) 26 | nng_test(reconnect_stress_test) 27 | -------------------------------------------------------------------------------- /src/sp/protocol.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2021 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #include 12 | 13 | #include "core/nng_impl.h" 14 | 15 | int 16 | nni_proto_open(nng_socket *sip, const nni_proto *proto) 17 | { 18 | int rv; 19 | nni_sock *sock; 20 | 21 | if ((rv = nni_sock_open(&sock, proto)) == 0) { 22 | nng_socket s; 23 | s.id = nni_sock_id(sock); // Keep socket held open. 24 | *sip = s; 25 | } 26 | return (rv); 27 | } 28 | -------------------------------------------------------------------------------- /src/sp/protocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2020 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # Protocols. 11 | nng_directory(protocol) 12 | 13 | add_subdirectory(bus0) 14 | add_subdirectory(pair0) 15 | add_subdirectory(pair1) 16 | add_subdirectory(pipeline0) 17 | add_subdirectory(pubsub0) 18 | add_subdirectory(reqrep0) 19 | add_subdirectory(survey0) 20 | 21 | -------------------------------------------------------------------------------- /src/sp/protocol/bus0/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # Bus protocol 12 | nng_directory(bus0) 13 | 14 | nng_sources_if(NNG_PROTO_BUS0 bus.c) 15 | nng_defines_if(NNG_PROTO_BUS0 NNG_HAVE_BUS0) 16 | 17 | nng_test(bus_test) 18 | -------------------------------------------------------------------------------- /src/sp/protocol/pair0/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # PAIRv0 protocol 12 | nng_directory(pair0) 13 | 14 | nng_sources_if(NNG_PROTO_PAIR0 pair.c) 15 | nng_defines_if(NNG_PROTO_PAIR0 NNG_HAVE_PAIR0) 16 | nng_test(pair0_test) 17 | -------------------------------------------------------------------------------- /src/sp/protocol/pair1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # PAIRv1 protocol 12 | nng_directory(pair1) 13 | 14 | nng_sources_if(NNG_PROTO_PAIR1 pair.c pair1_poly.c) 15 | nng_defines_if(NNG_PROTO_PAIR1 NNG_HAVE_PAIR1) 16 | 17 | nng_test(pair1_test) 18 | nng_test(pair1_poly_test) 19 | -------------------------------------------------------------------------------- /src/sp/protocol/pipeline0/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # Pipeline protocol 12 | nng_directory(pipeline0) 13 | 14 | nng_sources_if(NNG_PROTO_PUSH0 push.c) 15 | nng_defines_if(NNG_PROTO_PUSH0 NNG_HAVE_PUSH0) 16 | 17 | nng_sources_if(NNG_PROTO_PULL0 pull.c) 18 | nng_defines_if(NNG_PROTO_PULL0 NNG_HAVE_PULL0) 19 | 20 | nng_test(pull_test) 21 | nng_test(push_test) 22 | -------------------------------------------------------------------------------- /src/sp/protocol/pubsub0/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # Pub/Sub protocol 12 | nng_directory(pubsub0) 13 | 14 | nng_sources_if(NNG_PROTO_PUB0 pub.c) 15 | nng_defines_if(NNG_PROTO_PUB0 NNG_HAVE_PUB0) 16 | 17 | nng_sources_if(NNG_PROTO_SUB0 sub.c xsub.c) 18 | nng_defines_if(NNG_PROTO_SUB0 NNG_HAVE_SUB0) 19 | 20 | nng_test(pub_test) 21 | nng_test(sub_test) 22 | nng_test(xsub_test) 23 | -------------------------------------------------------------------------------- /src/sp/protocol/reqrep0/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # Req/Rep protocol 12 | nng_directory(reqrep0) 13 | 14 | nng_sources_if(NNG_PROTO_REQ0 req.c xreq.c) 15 | nng_defines_if(NNG_PROTO_REQ0 NNG_HAVE_REQ0) 16 | 17 | nng_sources_if(NNG_PROTO_REP0 rep.c xrep.c) 18 | nng_defines_if(NNG_PROTO_REP0 NNG_HAVE_REP0) 19 | 20 | nng_test(req_test) 21 | nng_test(rep_test) 22 | nng_test(xrep_test) 23 | nng_test(xreq_test) 24 | nng_test(reqstress_test) 25 | -------------------------------------------------------------------------------- /src/sp/protocol/survey0/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # Surveyor/Respondent protocol 12 | nng_directory(survey0) 13 | 14 | nng_sources_if(NNG_PROTO_SURVEYOR0 survey.c xsurvey.c) 15 | nng_defines_if(NNG_PROTO_SURVEYOR0 NNG_HAVE_SURVEYOR0) 16 | 17 | nng_sources_if(NNG_PROTO_RESPONDENT0 respond.c xrespond.c) 18 | nng_defines_if(NNG_PROTO_RESPONDENT0 NNG_HAVE_RESPONDENT0) 19 | 20 | nng_test(respond_test) 21 | nng_test(survey_test) 22 | nng_test(xrespond_test) 23 | nng_test(xsurvey_test) 24 | -------------------------------------------------------------------------------- /src/sp/transport/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # Transports. 11 | nng_directory(transport) 12 | 13 | add_subdirectory(socket) 14 | add_subdirectory(inproc) 15 | add_subdirectory(ipc) 16 | add_subdirectory(tcp) 17 | add_subdirectory(tls) 18 | add_subdirectory(dtls) 19 | add_subdirectory(udp) 20 | add_subdirectory(ws) 21 | -------------------------------------------------------------------------------- /src/sp/transport/dtls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # DTLS transport 11 | nng_directory(dtls) 12 | 13 | if (NNG_TRANSPORT_DTLS) 14 | nng_sources(dtls.c) 15 | nng_defines(NNG_TRANSPORT_DTLS) 16 | nng_test(dtls_tran_test) 17 | endif() 18 | -------------------------------------------------------------------------------- /src/sp/transport/inproc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # inproc protocol 12 | nng_directory(inproc) 13 | 14 | if (NNG_TRANSPORT_INPROC) 15 | nng_sources(inproc.c) 16 | nng_defines(NNG_TRANSPORT_INPROC) 17 | nng_test(inproc_test) 18 | endif() 19 | -------------------------------------------------------------------------------- /src/sp/transport/inproc/inproc_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2024 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #include 11 | 12 | NUTS_DECLARE_TRAN_TESTS(inproc) 13 | 14 | NUTS_TESTS = { 15 | NUTS_INSERT_TRAN_TESTS(inproc), 16 | { NULL, NULL }, 17 | }; 18 | -------------------------------------------------------------------------------- /src/sp/transport/ipc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # ipc protocol 12 | nng_directory(ipc) 13 | 14 | if (NNG_TRANSPORT_IPC) 15 | nng_sources(ipc.c) 16 | nng_defines(NNG_TRANSPORT_IPC) 17 | nng_test(ipc_test) 18 | endif() 19 | -------------------------------------------------------------------------------- /src/sp/transport/socket/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # File Descriptor (or Handle) based connections 11 | nng_directory(socket) 12 | 13 | if (NNG_TRANSPORT_FDC) 14 | nng_sources(sockfd.c) 15 | nng_defines(NNG_TRANSPORT_FDC) 16 | nng_test(sockfd_test) 17 | endif() 18 | -------------------------------------------------------------------------------- /src/sp/transport/tcp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # TCP protocol 12 | nng_directory(tcp) 13 | 14 | if (NNG_TRANSPORT_TCP) 15 | nng_sources(tcp.c) 16 | nng_defines(NNG_TRANSPORT_TCP) 17 | nng_test(tcp_test) 18 | endif() 19 | -------------------------------------------------------------------------------- /src/sp/transport/tls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # TLS transport 12 | nng_directory(tls) 13 | 14 | if (NNG_TRANSPORT_TLS) 15 | nng_sources(tls.c) 16 | nng_defines(NNG_TRANSPORT_TLS) 17 | nng_test(tls_tran_test) 18 | endif() 19 | -------------------------------------------------------------------------------- /src/sp/transport/udp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # UDP transport 11 | nng_directory(udp) 12 | 13 | if (NNG_TRANSPORT_UDP) 14 | nng_sources(udp.c) 15 | nng_defines(NNG_TRANSPORT_UDP) 16 | nng_test(udp_tran_test) 17 | endif() 18 | -------------------------------------------------------------------------------- /src/sp/transport/ws/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | # WebSocket transport 12 | nng_directory(ws) 13 | 14 | if (NNG_TRANSPORT_WS OR NNG_TRANSPORT_WSS) 15 | nng_sources(websocket.c) 16 | endif() 17 | 18 | if (NNG_TRANSPORT_WS) 19 | nng_defines(NNG_TRANSPORT_WS) 20 | nng_test(ws_test) 21 | endif() 22 | if (NNG_TRANSPORT_WSS) 23 | nng_defines(NNG_TRANSPORT_WSS) 24 | nng_test(wss_test) 25 | endif() 26 | -------------------------------------------------------------------------------- /src/sp/transport/ws/README.adoc: -------------------------------------------------------------------------------- 1 | = websocket transport 2 | 3 | This transport provides support for SP over websocket using TCP or TLS. 4 | When using TCP, it is compatible with the libnanomsg legacy transport. 5 | It also is compatible with mangos (both TCP and TLS). 6 | 7 | TLS support requires the mbedTLS library. 8 | 9 | We set the "protocol" such as "pair.sp.nanomsg.org" in the 10 | Sec-WebSocket-Protocol field -- the client sets to the the server's 11 | protocol - i.e. the protocol that the server speaks. For example, 12 | if the the server is a REP, then a REQ client would send "rep.sp.nanomsg.org". 13 | 14 | The server sends the same value (it's own), per the WebSocket specs. (Note 15 | that the client's protocol is never sent, but assumed to be complementary 16 | to the protocol in the Sec-WebSocket-Protocol field.) 17 | 18 | Each SP message is a WebSocket message. 19 | 20 | WebSocket is defined in RFC 6455. 21 | 22 | == Design 23 | 24 | We unfortunately need to implement our own design for this -- the only 25 | reasonable client library would be libcurl, and there is a dearth of 26 | suitable server libraries. Since we don't have to support full HTTP, but 27 | just the initial handshake, this isn't too tragic. 28 | 29 | == Multiple Server Sockets 30 | 31 | In order to support Multiple Server sockets listening on the same port, 32 | the application must be long lived. We will set up a listener on the 33 | configured TCP (or TLS) port, and examine the PATH supplied in the GET. 34 | This will be used to match against the URL requested, and if the URL 35 | matches we will create the appropriate pipe. 36 | 37 | If no server endpoint at that address can be found, we return an 38 | HTTP error, and close the socket. 39 | -------------------------------------------------------------------------------- /src/supplemental/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | nng_directory(supplemental) 11 | 12 | add_subdirectory(http) 13 | add_subdirectory(tls) 14 | add_subdirectory(websocket) 15 | -------------------------------------------------------------------------------- /src/supplemental/README.adoc: -------------------------------------------------------------------------------- 1 | = supplemental sources 2 | 3 | This is for code that is not intrinsic to nng, but which may be used 4 | by multiple other subsystems. For example, common code for TLS support 5 | used by multiple transports is located here. 6 | -------------------------------------------------------------------------------- /src/supplemental/http/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | option (NNG_ENABLE_HTTP "Enable HTTP API" ON) 12 | if (NNG_ENABLE_HTTP) 13 | set(NNG_SUPP_HTTP ON) 14 | endif() 15 | mark_as_advanced(NNG_ENABLE_HTTP) 16 | 17 | nng_sources(http_public.c http_api.h) 18 | 19 | nng_defines_if(NNG_SUPP_HTTP NNG_SUPP_HTTP) 20 | nng_sources_if(NNG_SUPP_HTTP 21 | http_client.c 22 | http_chunk.c 23 | http_conn.c 24 | http_msg.c 25 | http_public.c 26 | http_schemes.c 27 | http_server.c) 28 | nng_test_if(NNG_SUPP_HTTP http_server_test) 29 | -------------------------------------------------------------------------------- /src/supplemental/http/http_msg.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef NNG_SUPPLEMENTAL_HTTP_HTTP_MSG 12 | #define NNG_SUPPLEMENTAL_HTTP_HTTP_MSG 13 | 14 | #include "core/defs.h" 15 | #include "core/list.h" 16 | 17 | // Note that as we parse headers, the rule is that if a header is already 18 | // present, then we can append it to the existing header, separated by 19 | // a comma. From experience, for example, Firefox uses a Connection: 20 | // header with two values, "keepalive", and "upgrade". 21 | typedef struct http_header { 22 | char *name; 23 | char *value; 24 | nni_list_node node; 25 | bool static_name : 1; // name is static, do not free it 26 | bool static_value : 1; // value is static, do not free it 27 | bool alloc_header : 1; // header is heap allocated 28 | } http_header; 29 | typedef struct http_header nni_http_header; 30 | 31 | typedef struct nni_http_entity { 32 | char *data; 33 | size_t size; 34 | char clen[24]; // 64-bit lengths, in decimal 35 | char ctype[128]; // 63+63+; per RFC 6838 36 | http_header content_type; 37 | http_header content_length; 38 | nni_list hdrs; 39 | char *buf; 40 | size_t bufsz; 41 | bool parsed; 42 | bool own; // if true, data is "ours", and should be freed 43 | } nni_http_entity; 44 | 45 | struct nng_http_req { 46 | nni_http_entity data; 47 | }; 48 | 49 | struct nng_http_res { 50 | nni_http_entity data; 51 | }; 52 | 53 | extern void nni_http_free_header(http_header *); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/supplemental/http/http_schemes.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 Staysail Systems, Inc. 3 | // 4 | // This software is supplied under the terms of the MIT License, a 5 | // copy of which should be located in the distribution where this 6 | // file was obtained (LICENSE.txt). A copy of the license may also be 7 | // found online at https://opensource.org/licenses/MIT. 8 | // 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "core/nng_impl.h" 15 | 16 | #include "http_api.h" 17 | 18 | static struct { 19 | const char *upper; 20 | const char *lower; 21 | } http_schemes[] = { 22 | { 23 | .upper = "http", 24 | .lower = "tcp", 25 | }, 26 | { 27 | .upper = "ws", 28 | .lower = "tcp", 29 | }, 30 | { 31 | .upper = "https", 32 | .lower = "tls+tcp", 33 | }, 34 | { 35 | .upper = "wss", 36 | .lower = "tls+tcp", 37 | }, 38 | { 39 | .upper = "http4", 40 | .lower = "tcp4", 41 | }, 42 | { 43 | .upper = "ws4", 44 | .lower = "tcp4", 45 | }, 46 | { 47 | .upper = "http6", 48 | .lower = "tcp6", 49 | }, 50 | { 51 | .upper = "ws6", 52 | .lower = "tcp6", 53 | }, 54 | { 55 | .upper = "https4", 56 | .lower = "tls+tcp4", 57 | }, 58 | { 59 | .upper = "wss4", 60 | .lower = "tls+tcp4", 61 | }, 62 | { 63 | .upper = "https6", 64 | .lower = "tls+tcp6", 65 | }, 66 | { 67 | .upper = "wss6", 68 | .lower = "tls+tcp6", 69 | }, 70 | { 71 | .upper = NULL, 72 | .lower = NULL, 73 | }, 74 | }; 75 | 76 | const char * 77 | nni_http_stream_scheme(const char *upper) 78 | { 79 | for (int i = 0; http_schemes[i].upper != NULL; i++) { 80 | if (strcmp(http_schemes[i].upper, upper) == 0) { 81 | return (http_schemes[i].lower); 82 | } 83 | } 84 | return (NULL); 85 | } -------------------------------------------------------------------------------- /src/supplemental/tls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # Copyright 2019 Devolutions 5 | # 6 | 7 | # 8 | # This software is supplied under the terms of the MIT License, a 9 | # copy of which should be located in the distribution where this 10 | # file was obtained (LICENSE.txt). A copy of the license may also be 11 | # found online at https://opensource.org/licenses/MIT. 12 | # 13 | 14 | if (NNG_ENABLE_TLS) 15 | # List of TLS engines we support. TLS engines must support TLS 1.2 or better, 16 | # and must also support DTLS. Support for PSK is preferred. 17 | set(NNG_TLS_ENGINES mbed wolf none) 18 | # We assume Mbed for now. 19 | set(NNG_TLS_ENGINE mbed CACHE STRING "TLS engine to use.") 20 | set_property(CACHE NNG_TLS_ENGINE PROPERTY STRINGS ${NNG_TLS_ENGINES}) 21 | else () 22 | set(NNG_TLS_ENGINE none) 23 | endif () 24 | 25 | if (NOT NNG_TLS_ENGINE STREQUAL "none") 26 | nng_test(tls_test) 27 | endif () 28 | 29 | add_subdirectory(mbedtls) 30 | add_subdirectory(wolfssl) 31 | 32 | if (NNG_ENABLE_TLS) 33 | nng_sources(tls_common.c tls_dialer.c tls_listener.c tls_stream.c) 34 | nng_sources(tls_api.h tls_common.h tls_engine.h tls_stream.h) 35 | else() 36 | nng_sources(tls_stubs.c) 37 | endif() 38 | -------------------------------------------------------------------------------- /src/supplemental/tls/mbedtls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | if (NNG_TLS_ENGINE STREQUAL "mbed") 11 | message(NOTICE " 12 | ************************************************************ 13 | Linking against Mbed TLS may change license terms. 14 | Consult a lawyer and the license files for details. 15 | ************************************************************") 16 | nng_sources(mbedtls.c) 17 | nng_defines(NNG_TLS_ENGINE_INIT=nng_tls_engine_init_mbed) 18 | nng_defines(NNG_TLS_ENGINE_FINI=nng_tls_engine_fini_mbed) 19 | nng_defines(NNG_SUPP_TLS) 20 | # For now Mbed TLS has PSK unconditionally 21 | nng_defines(NNG_SUPP_TLS_PSK) 22 | nng_defines(NNG_TLS_ENGINE_MBEDTLS) 23 | 24 | # If Mbed TLS was added by a consuming project, then we should use that 25 | # instance of it, instead of configuring our own. 26 | if (TARGET mbedtls) 27 | nng_link_libraries(mbedtls) 28 | else() 29 | # We want to prefer config mode over our local find package. 30 | # mbedTLS v3 has a config file, which should work better than 31 | # what we do here. We only make this override locally, to 32 | # avoid confounding any other package consumers, and we honor overrides. 33 | if (NOT (DEFINED CMAKE_FIND_PACKAGE_PREFER_CONFIG)) 34 | set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) 35 | nng_find_package(MbedTLS) 36 | unset(CMAKE_FIND_PACKAGE_PREFER_CONFIG) 37 | else() 38 | nng_find_package(MbedTLS) 39 | endif() 40 | nng_link_libraries_public(MbedTLS::mbedtls MbedTLS::mbedcrypto MbedTLS::mbedx509) 41 | endif() 42 | endif() 43 | -------------------------------------------------------------------------------- /src/supplemental/tls/tls_api.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2019 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef NNG_SUPPLEMENTAL_TLS_TLS_API_H 13 | #define NNG_SUPPLEMENTAL_TLS_TLS_API_H 14 | 15 | #include "core/stream.h" 16 | 17 | // The implementation supplies this function to create the TLS connection 18 | // object. All fields will be zeroed. 19 | extern nng_err nni_tls_dialer_alloc(nng_stream_dialer **, const nng_url *); 20 | extern nng_err nni_tls_listener_alloc(nng_stream_listener **, const nng_url *); 21 | 22 | #endif // NNG_SUPPLEMENTAL_TLS_TLS_API_H 23 | -------------------------------------------------------------------------------- /src/supplemental/tls/tls_stream.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2019 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef NNG_TLS_TLS_STREAM_H 13 | #define NNG_TLS_TLS_STREAM_H 14 | 15 | #include "core/nng_impl.h" 16 | #include "tls_common.h" 17 | 18 | typedef struct tls_stream_s { 19 | nng_stream stream; 20 | size_t size; 21 | nni_reap_node reap; 22 | nni_aio conn_aio; 23 | nni_aio *user_aio; 24 | nni_tls_conn conn; // NB: must be last! 25 | } tls_stream; 26 | 27 | extern void nni_tls_stream_free(void *arg); 28 | extern int nni_tls_stream_alloc( 29 | tls_stream **tsp, nng_tls_config *cfg, nng_aio *user_aio); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/supplemental/websocket/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2025 Staysail Systems, Inc. 3 | # Copyright 2017 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | if (NNG_SUPP_WEBSOCKET) 12 | nng_sources(base64.c base64.h sha1.c sha1.h websocket.c websocket.h) 13 | nng_test(sha1_test) 14 | nng_test(base64_test) 15 | else () 16 | nng_sources(stub.c) 17 | endif () 18 | nng_test(wssfile_test) 19 | nng_test(websocket_test) 20 | -------------------------------------------------------------------------------- /src/supplemental/websocket/base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2014 Wirebird Labs LLC. All rights reserved. 3 | // Copyright 2020 Staysail Systems, Inc. 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), 7 | // to deal in the Software without restriction, including without limitation 8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | // and/or sell copies of the Software, and to permit persons to whom 10 | // the Software is furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included 13 | // in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | // IN THE SOFTWARE. 22 | // 23 | 24 | #ifndef NNI_BASE64_INCLUDED 25 | #define NNI_BASE64_INCLUDED 26 | 27 | #include 28 | #include 29 | 30 | // Based on base64.c (Public Domain) by Jon Mayo. 31 | // Base64 is defined in RFC 2045, section 6.8. 32 | 33 | // This function encodes an arbitrary byte array into base64 34 | // null-terminated string. It returns the number of characters 35 | // emitted. 36 | size_t nni_base64_encode(const uint8_t *, size_t, char *, size_t); 37 | 38 | // This function decodes a base64 string into supplied buffer. 39 | // It returns the number of bytes emitted. 40 | size_t nni_base64_decode(const char *, size_t, uint8_t *, size_t); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/supplemental/websocket/sha1.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #ifndef NNG_SUPPLEMENTAL_WEBSOCKET_SHA1_H 12 | #define NNG_SUPPLEMENTAL_WEBSOCKET_SHA1_H 13 | 14 | #include "core/defs.h" 15 | 16 | typedef struct { 17 | uint32_t digest[5]; // resulting digest 18 | uint64_t len; // length in bits 19 | uint8_t blk[64]; // message block 20 | int idx; // index of next byte in block 21 | } nni_sha1_ctx; 22 | 23 | extern void nni_sha1_init(nni_sha1_ctx *); 24 | extern void nni_sha1_update(nni_sha1_ctx *, const void *, size_t); 25 | extern void nni_sha1_final(nni_sha1_ctx *, uint8_t[20]); 26 | extern void nni_sha1(const void *, size_t, uint8_t[20]); 27 | 28 | #endif // NNG_SUPPLEMENTAL_WEBSOCKET_SHA1_H 29 | -------------------------------------------------------------------------------- /src/supplemental/websocket/stub.c: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2019 Staysail Systems, Inc. 3 | // Copyright 2019 Devolutions 4 | // 5 | // This software is supplied under the terms of the MIT License, a 6 | // copy of which should be located in the distribution where this 7 | // file was obtained (LICENSE.txt). A copy of the license may also be 8 | // found online at https://opensource.org/licenses/MIT. 9 | // 10 | 11 | #include "core/nng_impl.h" 12 | 13 | // This stub file exists to support configuration of the stream subsystem 14 | // when websocket support is unconfigured. 15 | 16 | int 17 | nni_ws_dialer_alloc(nng_stream_dialer **dp, const nng_url *url) 18 | { 19 | NNI_ARG_UNUSED(dp); 20 | NNI_ARG_UNUSED(url); 21 | return (NNG_ENOTSUP); 22 | } 23 | 24 | int 25 | nni_ws_listener_alloc(nng_stream_listener **lp, const nng_url *url) 26 | { 27 | NNI_ARG_UNUSED(lp); 28 | NNI_ARG_UNUSED(url); 29 | return (NNG_ENOTSUP); 30 | } 31 | 32 | int 33 | nni_ws_checkopt(const char *name, const void *data, size_t sz, nni_type t) 34 | { 35 | NNI_ARG_UNUSED(name); 36 | NNI_ARG_UNUSED(data); 37 | NNI_ARG_UNUSED(sz); 38 | NNI_ARG_UNUSED(t); 39 | return (NNG_ENOTSUP); 40 | } 41 | -------------------------------------------------------------------------------- /src/supplemental/websocket/websocket.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2025 Staysail Systems, Inc. 3 | // Copyright 2018 Capitar IT Group BV 4 | // Copyright 2019 Devolutions 5 | // 6 | // This software is supplied under the terms of the MIT License, a 7 | // copy of which should be located in the distribution where this 8 | // file was obtained (LICENSE.txt). A copy of the license may also be 9 | // found online at https://opensource.org/licenses/MIT. 10 | // 11 | 12 | #ifndef NNG_SUPPLEMENTAL_WEBSOCKET_WEBSOCKET_H 13 | #define NNG_SUPPLEMENTAL_WEBSOCKET_WEBSOCKET_H 14 | 15 | #include 16 | 17 | #include "core/stream.h" 18 | 19 | typedef struct nni_ws nni_ws; 20 | typedef struct nni_ws_listener nni_ws_listener; 21 | typedef struct nni_ws_dialer nni_ws_dialer; 22 | 23 | // Internal option, not for normal use (at present). This sets the 24 | // dialer/listener into message mode. This is used by the SP transport. 25 | // This is a boolean. 26 | #define NNI_OPT_WS_MSGMODE "ws:msgmode" 27 | 28 | // Specify URL as ws://[][:port][/path] 29 | // If host is missing, INADDR_ANY is assumed. If port is missing, 30 | // then either 80 or 443 are assumed. Note that ws:// means listen 31 | // on INADDR_ANY port 80, with path "/". For connect side, INADDR_ANY 32 | // makes no sense. (TBD: return NNG_EADDRINVAL, or try loopback?) 33 | 34 | // Much of the websocket API is still "private", meaning you should not 35 | // rely upon it being around. 36 | extern nng_err nni_ws_listener_alloc(nng_stream_listener **, const nng_url *); 37 | extern nng_err nni_ws_dialer_alloc(nng_stream_dialer **, const nng_url *); 38 | 39 | #endif // NNG_SUPPLEMENTAL_WEBSOCKET_WEBSOCKET_H 40 | -------------------------------------------------------------------------------- /src/testing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2020 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # Protocols. 11 | nng_directory(testing`) 12 | 13 | target_sources(nng_testing PRIVATE 14 | certs.c 15 | marry.c 16 | streams.c 17 | util.c) 18 | 19 | target_include_directories(nng_testing PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) 20 | -------------------------------------------------------------------------------- /src/tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2021 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | nng_directory(tools) 11 | 12 | add_subdirectory(nngcat) 13 | add_subdirectory(perf) 14 | -------------------------------------------------------------------------------- /src/tools/nngcat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2021 Staysail Systems, Inc. 3 | # Copyright 2018 Capitar IT Group BV 4 | # 5 | # This software is supplied under the terms of the MIT License, a 6 | # copy of which should be located in the distribution where this 7 | # file was obtained (LICENSE.txt). A copy of the license may also be 8 | # found online at https://opensource.org/licenses/MIT. 9 | # 10 | 11 | nng_directory(nngcat) 12 | 13 | if (NNG_ENABLE_NNGCAT) 14 | add_executable(nngcat nngcat.c) 15 | target_include_directories(nngcat PUBLIC ${PROJECT_SOURCE_DIR}/src) 16 | target_link_libraries(nngcat nng nng_private) 17 | install(TARGETS nngcat RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 18 | COMPONENT Tools) 19 | 20 | if (NNG_TESTS AND CMAKE_SYSTEM_NAME MATCHES "Linux") 21 | include(FindUnixCommands) 22 | endif () 23 | # TODO: This should be refactored to use a test driver. 24 | # We only run the tests on Linux for now, because the Darwin CI/CD is too brittle. 25 | if (NNG_TESTS AND BASH AND CMAKE_SYSTEM_NAME MATCHES "Linux") 26 | macro(add_nngcat_test NAME TIMEOUT) 27 | add_test(NAME nng.${NAME} COMMAND ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}_test.sh $) 28 | set_tests_properties(nng.${NAME} PROPERTIES TIMEOUT ${TIMEOUT}) 29 | endmacro() 30 | add_nngcat_test(nngcat_async 10) 31 | add_nngcat_test(nngcat_ambiguous 10) 32 | add_nngcat_test(nngcat_need_proto 10) 33 | add_nngcat_test(nngcat_dup_proto 10) 34 | add_nngcat_test(nngcat_help 10) 35 | add_nngcat_test(nngcat_incompat 10) 36 | add_nngcat_test(nngcat_pubsub 20) 37 | add_nngcat_test(nngcat_recvmaxsz 20) 38 | add_nngcat_test(nngcat_unlimited 20) 39 | add_nngcat_test(nngcat_stdin_pipe 20) 40 | endif () 41 | endif () 42 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_ambiguous_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | CMD="${NNGCAT} --re --dial=tcp://127.0.0.1:27272" 16 | 17 | echo -n "Verify ambiguous options fail: " 18 | if ${CMD} >/dev/null 2>&1 19 | then 20 | echo "Failed: ambiguous accepted" 21 | exit 1 22 | fi 23 | x=$(${CMD} 2>&1) 24 | if [[ ${x} =~ "ambiguous" ]] 25 | then 26 | echo "pass" 27 | exit 0 28 | fi 29 | 30 | echo "Failed: error did not match" 31 | exit 1 32 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_async_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | ADDR="ipc:///tmp/nngcat_async_test" 16 | 17 | echo -n "Verify async connect: " 18 | 19 | ${NNGCAT} --async -d 1 --connect ${ADDR} --req0 -D "ping" & 20 | 21 | 22 | answer=$( ${NNGCAT} --rep0 --recv-timeout=3 --listen ${ADDR} -D "pong" --ascii 2>/dev/null ) 23 | 24 | if [[ ${answer} == "ping" ]] 25 | then 26 | echo "pass" 27 | exit 0 28 | fi 29 | 30 | echo "Failed: req did not match" 31 | echo "RES: $answer" 32 | exit 1 33 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_dup_proto_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | 16 | echo -n "Verify only a single protocol is allowed: " 17 | if ${NNGCAT} --pub0 --sub0 --dial=tcp://127.0.0.1:8989 >/dev/null 2>&1 18 | then 19 | echo "Failed: duplicate protocols accepted" 20 | exit 1 21 | fi 22 | echo "pass" 23 | exit 0 24 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_help_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | 16 | echo -n "Verify nngcat help: " 17 | if ${NNGCAT} --help >/dev/null 2>&1 18 | then 19 | echo "Failed: help didn't return 1" 20 | exit 1 21 | fi 22 | x=$(${NNGCAT} --help 2>&1) 23 | if [[ ${x} =~ "Usage:" ]] 24 | then 25 | echo "pass" 26 | exit 0 27 | fi 28 | 29 | echo "Failed: usage did not match" 30 | echo "Output:" 31 | echo "$x" 32 | exit 1 33 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_incompat_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | 16 | echo "Verify incompatible options: " 17 | 18 | # Just bind something to this so other ones connect 19 | ${NNGCAT} --pull0 --ascii -X /tmp/bogusipc & 20 | pid=$! 21 | 22 | trap "kill $pid && wait $pid 2>/dev/null" 0 23 | 24 | echo -n " --subscribe doesn't work with non-sub" 25 | if ${NNGCAT} --req0 -x /tmp/bogusipc --subscribe=oops >/dev/null 2>&1 26 | then 27 | echo "fail" 28 | exit 1 29 | fi 30 | echo "pass" 31 | 32 | echo -n " --interval doesn't work with recv only: " 33 | if ${NNGCAT} --interval 1 --pull -x /tmp/bogusipc >/dev/null 2>&1 34 | then 35 | echo "fail" 36 | exit 1 37 | fi 38 | echo "pass" 39 | 40 | echo -n " --pair1 doesn't work with --compat: " 41 | if ${NNGCAT} --compat --pair1 -x /tmp/bogusipc >/dev/null 2>&1 42 | then 43 | echo "fail" 44 | exit 1 45 | fi 46 | echo "pass" 47 | 48 | echo -n " --count doesn't work with --compat: " 49 | if ${NNGCAT} --compat --count=1 --pair0 -x /tmp/bogusipc >/dev/null 2>&1 50 | then 51 | echo "fail" 52 | exit 1 53 | fi 54 | echo "pass" 55 | 56 | echo -n " --count fails with non-integer: " 57 | if ${NNGCAT} --count=xyz --pair0 -x /tmp/bogusipc >/dev/null 2>&1 58 | then 59 | echo "fail" 60 | exit 1 61 | fi 62 | echo "pass" 63 | 64 | echo -n " --file fails with non-existing file: " 65 | if ${NNGCAT} --async --file=/nosuchfilehere --push0 -x /tmp/bogusipc >/dev/null 2>&1 66 | then 67 | echo "fail" 68 | exit 1 69 | fi 70 | echo "pass" 71 | 72 | echo "PASS." 73 | exit 0 74 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_need_proto_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | 16 | echo -n "Verify a protocol is needed: " 17 | if ${NNGCAT} --dial=tcp://127.0.0.1:8989 >/dev/null 2>&1 18 | then 19 | echo "Failed: protocol should be required" 20 | exit 1 21 | fi 22 | echo "pass" 23 | exit 0 24 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_pubsub_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | ADDR="ipc:///tmp/nngcat_pub_sub_test" 16 | OUTPUT=/tmp/nngcat_pubsub_test.$$.out 17 | 18 | echo -n "Verify pub sub: " 19 | 20 | trap "rm $OUTPUT" 0 21 | 22 | ${NNGCAT} --listen ${ADDR} --count=3 --recv-timeout=20 --sub0 --subscribe=one --subscribe=two --quoted > $OUTPUT 2>/dev/null & 23 | sleep 1 24 | # for speed of execution, run these in the background, they should be ignored 25 | ${NNGCAT} -d 1 --connect ${ADDR} --pub0 --data "xyz" & 26 | ${NNGCAT} -d 1 --connect ${ADDR} --pub0 -D "none swam" & 27 | # these we care about, due to ordering (checksum) so run them serially 28 | ${NNGCAT} -d 1 --connect ${ADDR} --pub0 -D "one flew" 29 | ${NNGCAT} -d 1 --connect ${ADDR} --pub0 --data "twofer test" 30 | ${NNGCAT} -d 1 --connect ${ADDR} --pub0 --data "one more" 31 | 32 | wait $bgid 2>/dev/null 33 | 34 | sum=$(cksum ${OUTPUT}) 35 | sum=${sum%% *} 36 | if [[ ${sum} == 3929078614 ]] 37 | then 38 | echo "pass" 39 | exit 0 40 | fi 41 | echo "FAIL: Checksum failed (Wanted 3929078614 got ${sum})" 42 | echo "OUTPUT:" 43 | cat ${OUTPUT} 44 | 45 | exit 1 46 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_recvmaxsz_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | ADDR="ipc:///tmp/nngcat_recvmaxsz_test" 16 | OUTPUT=/tmp/nngcat_recvmaxsz_test.$$.out 17 | 18 | echo -n "Verify maximum receive size: " 19 | 20 | trap "rm $OUTPUT" 0 21 | 22 | ${NNGCAT} --listen ${ADDR} --count=3 --recv-maxsz=5 --pull0 --quoted > $OUTPUT 2>/dev/null & 23 | sleep 1 24 | # for speed of execution, run these in the background, they should be ignored 25 | ${NNGCAT} --connect ${ADDR} --push0 --data "one" 26 | ${NNGCAT} --connect ${ADDR} --push0 --data "55555" 27 | ${NNGCAT} --connect ${ADDR} --push0 --data "666666" 28 | ${NNGCAT} --connect ${ADDR} --push0 --data "7777777" 29 | ${NNGCAT} --connect ${ADDR} --push0 --data "88888" 30 | 31 | wait $bgid 2>/dev/null 32 | 33 | sum=$(cksum ${OUTPUT}) 34 | sum=${sum%% *} 35 | 36 | # This matches 3 lines of "one", "55555", "88888". 37 | if [[ ${sum} == 4122906158 ]] 38 | then 39 | echo "pass" 40 | exit 0 41 | fi 42 | echo "FAIL: Checksum failed (Wanted 3929078614 got ${sum})" 43 | echo "OUTPUT:" 44 | cat ${OUTPUT} 45 | 46 | exit 1 47 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_stdin_pipe_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # Copyright 2020 Lager Data, Inc. 7 | # 8 | # This software is supplied under the terms of the MIT License, a 9 | # copy of which should be located in the distribution where this 10 | # file was obtained (LICENSE.txt). A copy of the license may also be 11 | # found online at https://opensource.org/licenses/MIT. 12 | # 13 | 14 | NNGCAT=${NNGCAT:=$1} 15 | NNGCAT=${NNGCAT:-./nngcat} 16 | ADDR="ipc:///tmp/nngcat_stdin_pipe_test" 17 | OUTPUT=/tmp/nngcat_stdin_pipe_test.$$.out 18 | 19 | echo -n "Verify reading from stdin pipe: " 20 | 21 | trap "rm $OUTPUT" 0 22 | 23 | ${NNGCAT} --listen ${ADDR} --count=1 --recv-timeout=3 --recv-maxsz=0 --pull0 --raw > $OUTPUT 2>/dev/null & 24 | bgid=$! 25 | 26 | sleep 1 27 | # for speed of execution, run these in the background, they should be ignored 28 | echo "hello world" | ${NNGCAT} --connect ${ADDR} --delay=1 --push0 --file - 29 | wait "$bgid" 2>/dev/null 30 | 31 | sum=$(cksum ${OUTPUT}) 32 | sum=${sum%% *} 33 | 34 | # This matches "hello world\n" since echo adds a trailing newline 35 | if [[ ${sum} == 3733384285 ]] 36 | then 37 | echo "pass" 38 | exit 0 39 | fi 40 | echo "FAIL: Checksum failed (Wanted 3733384285 got ${sum})" 41 | echo "OUTPUT:" 42 | ls -la ${OUTPUT} 43 | 44 | exit 1 45 | -------------------------------------------------------------------------------- /src/tools/nngcat/nngcat_unlimited_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # 4 | # Copyright 2018 Staysail Systems, Inc. 5 | # Copyright 2018 Capitar IT Group BV 6 | # 7 | # This software is supplied under the terms of the MIT License, a 8 | # copy of which should be located in the distribution where this 9 | # file was obtained (LICENSE.txt). A copy of the license may also be 10 | # found online at https://opensource.org/licenses/MIT. 11 | # 12 | 13 | NNGCAT=${NNGCAT:=$1} 14 | NNGCAT=${NNGCAT:-./nngcat} 15 | ADDR="ipc:///tmp/nngcat_unlimited_test" 16 | INPUT=/tmp/nngcat_unlimited_test.$$.in 17 | OUTPUT=/tmp/nngcat_unlimited_test.$$.out 18 | 19 | echo -n "Verify unlimited receive size: " 20 | 21 | trap "rm $OUTPUT $INPUT" 0 22 | 23 | # 4 MB 24 | dd if=/dev/urandom of=${INPUT} bs=1024 count=4096 >/dev/null 2>&1 25 | goodsum=$(cksum ${INPUT}) 26 | goodsum=${goodsum%% *} 27 | 28 | ${NNGCAT} --listen ${ADDR} --count=1 --recv-maxsz=0 --pull0 --raw > $OUTPUT 2>/dev/null & 29 | sleep 1 30 | # for speed of execution, run these in the background, they should be ignored 31 | ${NNGCAT} --connect ${ADDR} --delay=1 --push0 --file ${INPUT} 32 | wait $bgid 2>/dev/null 33 | 34 | sum=$(cksum ${OUTPUT}) 35 | sum=${sum%% *} 36 | 37 | if [[ ${sum} == ${goodsum} ]] 38 | then 39 | echo "pass" 40 | exit 0 41 | fi 42 | echo "FAIL: Checksum failed (Wanted ${goodsum} got ${sum})" 43 | echo "OUTPUT:" 44 | ls -la ${OUTPUT} 45 | 46 | exit 1 47 | -------------------------------------------------------------------------------- /src/tools/perf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2024 Staysail Systems, Inc. 3 | # 4 | # This software is supplied under the terms of the MIT License, a 5 | # copy of which should be located in the distribution where this 6 | # file was obtained (LICENSE.txt). A copy of the license may also be 7 | # found online at https://opensource.org/licenses/MIT. 8 | # 9 | 10 | # Build performance tests. 11 | 12 | nng_directory(perf) 13 | 14 | if (NNG_TESTS) 15 | macro (add_nng_perf NAME) 16 | add_executable (${NAME} perf.c) 17 | target_link_libraries (${NAME} nng nng_private) 18 | endmacro (add_nng_perf) 19 | 20 | add_nng_perf(remote_lat) 21 | add_nng_perf(local_lat) 22 | add_nng_perf(local_thr) 23 | add_nng_perf(remote_thr) 24 | add_nng_perf(inproc_thr) 25 | add_nng_perf(inproc_lat) 26 | 27 | # These tests seem to fail in CI/CID on Windows. Guessing 28 | # that there is some bad interaction with the properties and Windows. 29 | if (NOT WIN32) 30 | add_test (NAME nng.inproc_lat COMMAND inproc_lat 64 10000) 31 | set_tests_properties (nng.inproc_lat PROPERTIES TIMEOUT 30) 32 | 33 | add_test (NAME nng.inproc_thr COMMAND inproc_thr 1400 10000) 34 | set_tests_properties (nng.inproc_thr PROPERTIES TIMEOUT 30) 35 | 36 | add_test (NAME nng.pubdrop COMMAND pubdrop inproc://junk 64 1000 2 1) 37 | add_executable (pubdrop pubdrop.c) 38 | target_link_libraries(pubdrop nng nng_private) 39 | endif() 40 | endif () 41 | -------------------------------------------------------------------------------- /tests/README.adoc: -------------------------------------------------------------------------------- 1 | == About C-Convey 2 | 3 | The convey framework in this directory was originally started for 4 | this project, but has since been promoted to a project of it's own. 5 | Please see it's home page on https://github.com/gdamore/c-convey[github] 6 | for updates and further information. 7 | 8 | The convey framework is licensed under the same terms as the rest 9 | of this project (MIT style license). 10 | 11 | Having said that, we are moving towards a new testing infrastructure. 12 | See the acutest.h header in this directory, along with testutil.h. 13 | 14 | Please do not write new tests in c-convey format. --------------------------------------------------------------------------------