From e02beef5c3be4fca59de9f89cb2e69f320d73e6f Mon Sep 17 00:00:00 2001 From: Mikhail Novikov Date: Mon, 15 Apr 2013 22:39:25 +0300 Subject: [PATCH] Contexts are error handled + tests for that. --- src/meta.lisp | 8 ++++---- src/zeromq-api.lisp | 36 +++++++++++++++++++++++++++--------- src/zeromq.lisp | 4 ++-- zeromq.asd | 11 ++++++++++- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/meta.lisp b/src/meta.lisp index d5729e9..576da6a 100644 --- a/src/meta.lisp +++ b/src/meta.lisp @@ -19,10 +19,10 @@ (if (funcall error-p ret) (let* ((error-code (%errno)) (error-description - (convert-from-foreign (%strerror error-code) :uint))) - (make-condition 'zmq-error - :code error-code - :description error-description)) + (convert-from-foreign (%strerror error-code) :string))) + (error 'zmq-error + :code error-code + :description error-description)) ret))) ;; Stolen from CFFI. Uses custom allocator (alloc-fn) instead of foreign-alloc diff --git a/src/zeromq-api.lisp b/src/zeromq-api.lisp index 859fb31..fd3b048 100644 --- a/src/zeromq-api.lisp +++ b/src/zeromq-api.lisp @@ -22,18 +22,36 @@ (progn ,@body) (ctx-destroy ,context)))) +(defun ctx-new () + (call-with-error-check + #'%ctx-new '() + :type :pointer)) + (defun ctx-get (context option) - (%ctx-get context - (foreign-enum-value - 'context-options - option))) + (call-with-error-check + #'%ctx-get + (list context + (or (foreign-enum-value + 'context-options + option + :errorp nil) + -1)))) (defun ctx-set (context option value) - (%ctx-set context - (foreign-enum-value - 'context-options - option) - value)) + (call-with-error-check + #'%ctx-set + (list context + (or (foreign-enum-value + 'context-options + option + :errorp nil) + -1) + value))) + +(defun ctx-destroy (context) + (call-with-error-check + #'%ctx-destroy + (list context))) ;; Sockets diff --git a/src/zeromq.lisp b/src/zeromq.lisp index 56aa8e8..5be927b 100644 --- a/src/zeromq.lisp +++ b/src/zeromq.lisp @@ -46,7 +46,7 @@ ;; 0MQ contexts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defcfun ("zmq_ctx_new" ctx-new) c-context) +(defcfun ("zmq_ctx_new" %ctx-new) c-context) (defcfun ("zmq_ctx_get" %ctx-get) :int (context c-context) @@ -57,7 +57,7 @@ (option-name :int) (option-value :int)) -(defcfun ("zmq_ctx_destroy" ctx-destroy) :int +(defcfun ("zmq_ctx_destroy" %ctx-destroy) :int (context c-context)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/zeromq.asd b/zeromq.asd index 21f7a2a..bf698fa 100644 --- a/zeromq.asd +++ b/zeromq.asd @@ -3,7 +3,7 @@ (cl:eval-when (:load-toplevel :execute) (asdf:operate 'asdf:load-op 'cffi-grovel)) -(asdf:defsystem zeromq +(asdf:defsystem zeromq3 :name "zeromq" :version "0.2.0" :author "Vitaly Mayatskikh " @@ -21,3 +21,12 @@ (:file "meta") (:file "zeromq") (:file "zeromq-api"))))) + +(asdf:defsystem zeromq.tests + :depends-on (:zeromq :fiveam) + :components + ((:module "tests" + :serial t + :components + ((:file "package") + (:file "main"))))) -- 2.11.4.GIT