[zeromq-dev] adding timeout in zmq_poll
Martin Sustrik
sustrik at 250bpm.com
Wed Jan 13 13:36:35 CET 2010
Hi Vitaly,
Commited to the trunk (rev. 30a107e).
Thanks!
Martin
Vitaly Mayatskikh wrote:
> At Mon, 04 Jan 2010 15:58:27 +0100, Martin Sustrik wrote:
>> Hi Pavel,
>>
>>> Martin, please review patch and commit it to trunk (under required MIT
>>> license) if there no warnings.
>> I've reviewed the patch and made following changes:
>>
>> 1. I've removed the common lisp patch - let's rely on Vitaly to fix it
>> in a clean way.
>
> Here's my part:
>
> diff --git a/bindings/cl/zeromq-api.lisp b/bindings/cl/zeromq-api.lisp
> index 188bdd4..44d725b 100644
> --- a/bindings/cl/zeromq-api.lisp
> +++ b/bindings/cl/zeromq-api.lisp
> @@ -146,7 +146,7 @@ The string must be freed with FOREIGN-STRING-FREE."
> (setf (mem-aref int :long 0) value)
> (%setsockopt socket option int (foreign-type-size :long))))))
>
> -(defun poll (items)
> +(defun poll (items &optional (timeout -1))
> (let ((len (length items)))
> (with-foreign-object (%items 'pollitem len)
> (dotimes (i len)
> @@ -156,14 +156,16 @@ The string must be freed with FOREIGN-STRING-FREE."
> (setf socket (pollitem-socket item)
> fd (pollitem-fd item)
> events (pollitem-events item)))))
> - (let ((ret (%poll %items len)))
> - (if (> ret 0)
> + (let ((ret (%poll %items len timeout)))
> + (cond
> + ((zerop ret) nil)
> + ((> ret 0)
> (loop for i below len
> for revent = (foreign-slot-value (mem-aref %items 'pollitem i)
> 'pollitem
> 'revents)
> - collect (setf (pollitem-revents (nth i items)) revent))
> - (error (convert-from-foreign (%strerror *errno*) :string)))))))
> + collect (setf (pollitem-revents (nth i items)) revent)))
> + (t (error (convert-from-foreign (%strerror *errno*) :string))))))))
>
> (defmacro with-polls (list &body body)
> `(let ,(loop for (name . polls) in list
> diff --git a/bindings/cl/zeromq.lisp b/bindings/cl/zeromq.lisp
> index 90b42da..217b97c 100644
> --- a/bindings/cl/zeromq.lisp
> +++ b/bindings/cl/zeromq.lisp
> @@ -231,7 +231,8 @@
>
> (defcfun ("zmq_poll" %poll) :int
> (items :pointer)
> - (nitems :int))
> + (nitems :int)
> + (timeout :long))
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;; Helper functions.
>
More information about the zeromq-dev
mailing list