nng

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!

Requirements

Usage

Socket creation

[procedure] (make-rep-socket)
[procedure] (make-req-socket)
[procedure] (make-pull-socket)
[procedure] (make-push-socket)
[procedure] (make-pub-socket)
[procedure] (make-sub-socket)
[procedure] (make-pair-socket)
[procedure] (make-surveyor-socket)
[procedure] (make-respondent-socket)
[procedure] (make-bus-socket)

Spawn a specific socket type. All sockets are closed automatically when their finalizers run.

Socket/listener/dialer options

[procedure] (socket-get socket option)
[procedure] (socket-set! socket option value)
[procedure] (listener-get listener option)
[procedure] (listener-set! listener option value)
[procedure] (dialer-get dialer option)
[procedure] (dialer-set! dialer option value)

option is object-specific. Currently supported options are:

Listening/Dialing

[procedure] (make-listener socket address)

Make listener from socket to bind to address.

[procedure] (make-dialer socket address)

Make a dialer from socket to connect to address.

[procedure] (listener-start! listener)

Bind listener.

[procedure] (dialer-start! dialer)

Connect dialer.

[procedure] (nng-listen socket address [listener])

Bind a socket to an address.

[procedure] (nng-dial socket address [dialer])

Connect a socket to an address.

Send/Recv

[procedure] (nng-send socket msg)

Send string msg through a socket.

[procedure] (nng-recv socket [non-blocking?])

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.

Closing

[procedure] (nng-close! socket)

Close socket explicitly.

[procedure] (listener-close! listener)

Close listener explicitly. Should not be necessary since listeners get close whenever their associated sockets get closed.

[procedure] (dialer-close! dialer)

Same as above; usually unnecessary.

TLS Transport

[procedure] (tls-register!)

Register TLS transport. Usually not necessary, but depends on how your libnng was built.

[procedure] (tls-enabled?)

Check if TLS is enabled in your system.

[procedure] (set-listener-tls-own-certificate! listener cert key enforce-client-auth? [pass])

Configure listener with a certificate, secret key and a (possible) passphrase. If enfonce-client-auth? is #t, it will require clients to authenticate themselves.

[procedure] (set-dialer-tls-certificate! dialer chain [server-name [key [pass]]])

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.

Repository

https://gitlab.com/ariSun/chicken-nng

Bugs/Caveats/TODOs

License

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.