Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/nanomsg|the CHICKEN 5 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-5.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. == chicken-nanomsg [[toc:]] [[http://call-cc.org/|Chicken Scheme]] bindings for the lightweight ZMQ-alternative, [[http://nanomsg.org/|nanomsg]]. There [[http://api.call-cc.org/doc/zmq|exists Chicken ZMQ bindings]], but this turned out to be a little troublesome with zmq_poll blocking other srfi-18 threads. === Why nanomsg Nanomsg is smaller, written in C, has a simplified API (sockets are simple ints), no multipart messages, and has explicit support for poll on a socket's recv file-descriptor. === Requirements This egg requires nanomsg-[1.0] or (probably) above. === Repository [[https://github.com/Adellica/chicken-nanomsg|https://github.com/Adellica/chicken-nanomsg]] === API <procedure> (nn-socket protocol [domain])</procedure> Create a nanomsg socket. Protocol can be any of the symbols pair, pub, sub, pull, push, req, rep, surveyor, respondent or bus. Domain can be the symbol sp or raw, and defaults to sp. <procedure> (nn-bind socket address)</procedure> [[http://nanomsg.org/v0.6/nn_bind.3.html|Binds]] nanomsg socket to address, where address is a string of the form "ipc:///var/ipc/music.nn.pair" or "tcp://0.0.0.0:10080". If the nn-library can't parse the address string, it throws an "Illegal argument" error. <procedure> (nn-connect socket address)</procedure> [[http://nanomsg.org/v0.6/nn_connect.3.html|Connects]] nanomsg socket {{socket}} to {{address}}. <procedure> (nn-subscribe socket prefix)</procedure> Set the [[http://nanomsg.org/v0.6/nn_pubsub.7.html|NN_SUBSCRIBE]] option on {{socket}} which will make the socket receive to all messages that start with {{prefix}}. Note that if this is never called, {{(nn-sock 'sub)}} sockets will never receive anything. <procedure> (nn-recv socket)</procedure> Receive a message from socket. This blocks until a message is received from nanomsg, but it does not block other srfi-18 threads. It always returns a string. An error is thrown if the socket is in an illegal state. <procedure> (nn-send socket msg)</procedure> Send a message on {{socket}}, using the socket's semantics. {{msg}} must be a string. In the current implementation, this operation may block for certain protocols in which case other srfi-18 threads block too. <procedure> (nn-recv* socket flags)</procedure> Receive a message from socket. This will block other srfi-18 threads, unless the {{nn/dontwait}} flag is specified, in which case {{nn-recv*}} will immediately with either a message as a string or #f (for EAGAIN). An error is thrown if {{socket}} is in an illegal state. Note that memory is copied from the nanomsg buffer into a new scheme string. <procedure> (nn-recv! socket buffer size flags)</procedure> A version of {{nn-recv*}} which requires a preallocated buffer. If the size of the buffer can be found automatically (using {{number-of-bytes}}), size can be {{#f}}. <procedure> (nn-close socket)</procedure> Explicitly close {{socket}}. This is normally not needed as this is done in the socket's finalizer. === Development Status These bindings are incomplete, but all protocols and transport types should be supported. However, socket options ({{nn_setsockopt}} and {{nn_getsockopt}}) aren't supported with the exception of {{nn-subscribe}}. Patches are welcome! Favored TODO's: - support socket options - bundle nanomsg itself? === Sample <enscript highlight="scheme"> ;; test.scm (use nanomsg) (define s (nn-socket 'rep)) (nn-bind s "tcp://127.0.0.1:22022") (let loop ((n 0)) (nn-send s (conc (nn-recv s) " " n)) (loop (add1 n))) (nn-close s) </enscript> then test with the brilliant {{nanocat}} util that comes with [nanomsg]: <enscript highlight="bash"> $ csi -s test.scm & $ nanocat --req -l22022 -D"bottles of beer:" -A --interval 1 </enscript>
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 5 by 1?