Supported implementations
These Lisps were tested on Linux x86-64:
- SBCL 1.0.43
- CLISP 2.49
- Clozure CL 1.5-r13651
- LispWorks 6.0.1
Kamil Shakirov also reports that cl-zmq works with development branch of ECL and at Mac OS X (tested with Snow Leopard x86 (10.6.4)).
Package
Source Code
http://repo.or.cz/w/cl-zmq.git
Installation
Using Quicklisp
(ql:quickload "zeromq")
Documentation
Common Lisp API repeats C API in general. All constants defined with C API are available with Common Lisp API. C names are mapped to lisp names by these rules:
- all names are in ‘zmq’ namespace;
- all names are in lower case;
- underscores translate to dashes.
Example of mappings:
zmq_msg_init_data maps to zmq:msg-init-data
ZMQ_PUB maps to zmq:pub
To learn about individual functions and parameters check appropriate C API manual pages.
For example, to understand zmq:setsockopt function check zmq_setsockopt(3) manual page.
Data structures are wrapped into CLOS classes with automatic memory management. ØMQ describes two such structures, msg_t and pollitem_t.
Message constructor supports keywords :size and :data. Keyword :size specifies the size of message. Keyword :data specifies initial contents of message, and it can be either string or 8-bit array. For example, following code creates a message with 3 bytes '1, 2, 3' in it:
(make-instance 'zmq:msg :data #(1 2 3))
There 3 functions to read message body in different forms: msg-data-as-string, msg-data-as-array and msg-data-as-is, returning data as string, as array and as raw foreign pointer to underlaying buffer respectively. For example, following code returns #(1 2 3) for message from previous example:
(zmq:msg-data-as-array msg)
It is possible to access underlying foreign object via class slot named ‘raw’:
(slot-value obj 'zmq:raw)
Or, if ‘obj’ is of known type ‘msg’:
(zmq:msg-raw obj)
There are several macros to simplify managing ØMQ objects:
Macro with-context creates ØMQ context and requires 2 obligatory arguments: context name and number of input/output threads, see zmq_init(3). Context is terminated implicitly at the end of macro block.
Macro with-socket creates ØMQ socket within given context. It requires 3 arguments: socket name, context name and socket type. See zmq_socket(3). Socket is closed implicitly at the end of macro block.
Macro with-polls creates ØMQ polls, containing different sets of pollitems. For example, to create two poll sets for network pipes:
(zmq:with-polls ((poll1 . ((sock1 . zmq:pollin)
(sock2 . zmq:pollout)))
(poll2 . ((sock1 . zmq:pollout)
(sock2 . zmq:pollin))))
(process-sockets (zmq:poll poll-set1))
(process-sockets (zmq:poll poll-set2)))
Note: zmq:poll returns list of revents for sockets from given poll set.
Polls are closed implicitly at the end of macro block.
Example
(zmq:with-context (ctx 1)
(zmq:with-socket (s ctx zmq:pub)
(zmq:connect s "tcp://192.168.0.115:5555")
(zmq:send s (make-instance 'zmq:msg :data "Hello, world!"))))
Bug Reporting
If you encounter problems please write email to zeromq-dev list or to:
moc.liamg|hikstayam.v#moc.liamg|hikstayam.v
Mailing List
Discussions about this language binding take place on the general zeromq-dev list.