Multiple socket reader in CL

;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; -*-
;;; Reading from multiple sockets in Common Lisp
;;; This version uses a simple recv loop
;;; Kamil Shakirov <moc.liamg|08slimak#moc.liamg|08slimak>

(defpackage #:zguide.msreader
(:nicknames #:msreader)
(:use #:cl #:zhelpers)
(:export #:main))

(in-package :zguide.msreader)

(defun main ()
;; Prepare our context and socket
(zmq:with-context (context 1)
;; Connect to task ventilator
(zmq:with-socket (receiver context zmq:pull)
(zmq:connect receiver "tcp://localhost:5557")
;; Connect to weather server
(zmq:with-socket (subscriber context zmq:sub)
(zmq:connect subscriber "tcp://localhost:5556")
(zmq:setsockopt subscriber zmq:subscribe "10001 ")

;; Process messages from both sockets
;; We prioritize traffic from the task ventilator
(let ((task (make-instance 'zmq:msg)))
(zmq:recv receiver task zmq:noblock)
;; process task
(dump-message task)

(zmq:error-again () nil))

;; Process any waiting weather updates
(let ((update (make-instance 'zmq:msg)))
(zmq:recv subscriber update zmq:noblock)
;; process weather update
(dump-message update)

(zmq:error-again () nil))

;; No activity, so sleep for 1 msec
(isys:usleep 1000)))))