1 ;; This file is part of CL-ZMQ.
5 (define-condition zmq-error
(error)
6 ((code :reader error-code
:initarg
:code
)
7 (description :reader error-description
:initarg
:description
))
8 (:report
(lambda (condition stream
)
9 (format stream
"ZMQ Error ~A - ~A."
10 (error-code condition
)
11 (error-description condition
)))))
13 (defun call-with-error-check (function args
&key
(type :int
) error-p
)
14 (let ((error-p (or error-p
18 (ret (apply function args
)))
19 (if (funcall error-p ret
)
20 (let* ((error-code (%errno
))
22 (convert-from-foreign (%strerror error-code
) :string
)))
25 :description error-description
))
28 ;; Stolen from CFFI. Uses custom allocator (alloc-fn) instead of foreign-alloc
29 (defun copy-lisp-string-octets (string alloc-fn
31 (encoding cffi
::*default-foreign-encoding
*)
33 "Allocate a foreign string containing Lisp string STRING.
34 The string must be freed with FOREIGN-STRING-FREE."
35 (check-type string string
)
36 (cffi::with-checked-simple-vector
((string
37 (coerce string
'babel
:unicode-string
))
38 (start start
) (end end
))
39 (declare (type simple-string string
))
40 (let* ((mapping (cffi::lookup-mapping
41 cffi
::*foreign-string-mappings
*
43 (count (funcall (cffi::octet-counter mapping
) string start end
0))
44 (ptr (funcall alloc-fn count
)))
45 (funcall (cffi::encoder mapping
) string start end ptr
0)
48 (defmacro with-zmq-string
(args &body body
)
49 `(with-foreign-string (,@args
:null-terminated-p
'())