Barebones libnng bindings for CHICKEN Scheme. rep, req, pull, push, sub, pub, pair, surveyor, respondent and bus sockets are supported. Feedback and patches are very welcome!
- libnng, at least 1.3. Known to work with 1.4+.
- libmbedtls (and a TLS-enabled libnng) if you plan on using TLS transport.
- CHICKEN 5 with the following eggs:
- test and miscmacros (for tests)
Spawn a specific socket type. All sockets are closed automatically when their finalizers run.
- socket-get socket optionprocedure
- socket-set! socket option valueprocedure
- listener-get listener optionprocedure
- listener-set! listener option valueprocedure
- dialer-get dialer optionprocedure
- dialer-set! dialer option valueprocedure
option is object-specific. Currently supported options are:
- make-listener socket addressprocedure
Make listener from socket to bind to address.
- make-dialer socket addressprocedure
Make a dialer from socket to connect to address.
- listener-start! listenerprocedure
- dialer-start! dialerprocedure
- nng-listen socket address #!optional listenerprocedure
Bind a socket to an address.
- nng-dial socket address #!optional dialerprocedure
Connect a socket to an address.
- nng-send socket msgprocedure
Send string msg through a socket.
- nng-recv socket #!optional non-blocking?procedure
Receive msg through a socket. If non-blocking? is passed and is not false, nng-recv returns #f when it would otherwise block. Additionally, if a timeout has been set with nng-socket-set-recv-timeout!, #f is returned when said timeout is reached.
- nng-close! socketprocedure
Close socket explicitly.
- listener-close! listenerprocedure
Close listener explicitly. Should not be necessary since listeners get close whenever their associated sockets get closed.
- dialer-close! dialerprocedure
Same as above; usually unnecessary.
Register TLS transport. Usually not necessary, but depends on how your libnng was built.
Check if TLS is enabled in your system.
- set-listener-tls-own-certificate! listener cert key enforce-client-auth? #!optional passprocedure
Configure listener with a certificate, secret key and a (possible) passphrase. If enfonce-client-auth? is #t, it will require clients to authenticate themselves.
- set-dialer-tls-certificate! dialer chain #!optional server-name key passprocedure
Configure dialer with a certificate. server-name defaults to localhost. If the certificate is its own, also provide a private key, and passphrase if applicable.
- Some options don’t seem to work properly yet. nng/recvtimeo isn’t particularly useful since we block the current thread with thread-wait-for-i/o! when receiving.
- We use NNG_OPT_RECVFD in combination with thread-wait-for-i/o! to avoid blocking all threads. Unfortunately, this means we can’t use nng_ctx.
Copyright 2021 Ariela Wenner arisunz at disroot dot org
Licensed under MIT.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.