@@ -27,15 +27,15 @@ nmsg-transport ( nmsg:start-server nmsg:open-send-close nmsg:open-send-receive + nmsg:close ) (import scheme posix chicken data-structures ports) -(use pkts) (use nanomsg srfi-18) ;;start a server, returns the connection ;; (define (nmsg:start-server portnum ) @@ -50,16 +50,17 @@ ;; open connection to server, send message, close connection ;; ;; to take an action on failure use proc which is called with the error info ;; (proc exn errormsg) +;; +;; returns the response or #f if no response within timeout ;; (define (nmsg:open-send-close host-port msg attrib #!key (timeout 3)(proc #f)) ;; default timeout is 3 seconds (let ((req (nn-socket 'req)) (uri (conc "tcp://" host-port)) (res #f) - ;; (contacts (alist-ref 'contact attrib)) (mode (alist-ref 'mode attrib))) (handle-exceptions exn (let ((emsg ((condition-property-accessor 'exn 'message) exn))) ;; Send notification @@ -70,13 +71,11 @@ (nn-send req msg) (print "Request Sent") (let* ((th1 (make-thread (lambda () (let ((resp (nn-recv req))) (nn-close req) - (set! res (if (equal? resp "ok") - #t - #f)))) + (set! res resp))) "recv thread")) (th2 (make-thread (lambda () (thread-sleep! timeout) (thread-terminate! th1)) "timer thread"))) @@ -119,10 +118,9 @@ (thread-start! th1) (thread-start! th2) (thread-join! th1) res)))) -;; get a signature for identifing this process -(define (nmsg:get-process-signature) - (conc (get-host-name) " " (current-process-id))) +(define (nmsg:close conn) + (nn-close conn)) )