Common Lisp bindings to POSIX message queues. Contributions and questions are welcome.
POSIX message queue is an IPC (Inter-Process Communication) method that is easy to use and quick to setup.
(with-open-queue (mq "/myqueue" :open-flags '(:read-write :create)
:max-messages 5 :message-size 10)
;; Messages are ordered based on priority. High priority messages are placed
;; at the beginning.
(send-string mq "hello" 4) ; 4 is priority
(multiple-value-bind (msg-string priority) (receive-string mq)
(when (and (string= "hello" msg-string) (= 4 priority))
(print "It works!"))))
(unlink "/myqueue")
(with-open-queue (mq "/myqueue" :open-flags '(:read-only))
(multiple-value-bind (msg priority)
;; Timestamps are absolute
(timed-receive-string mq (local-time:timestamp+ (local-time:now) 1 :sec))
(when (eq :connection-timed-out msg)
(print "Timed out!"))))
(unlink "/myqueue")
(with-open-queue (mq "/myqueue" :open-flags '(:read-only :create :non-blocking))
(multiple-value-bind (msg priority) (receive-string mq)
(when (eq :try-again msg)
(print "Would block!"))))
(unlink "/myqueue")
This library uses local-time library for timestamps. All of the exported symbols are documented in details through the internal common lisp documentation system.
- sbcl
- ecl
- ccl
- clisp
First of all, slynk failed to load. Quicklisp and cl-posix-mqueue, loaded just fine. Tests failed. When I started using cl-posix-mqueue manually, memory errors were printed. After that, core dumped. Maybe cffi should be set differently for jvm.
Could not build implementation on my machine
It does unnecessary writes and reads on implementations where direct access to vectors is not supported. Maybe on receive it should only read and on send it should only write.