Megatest

Diff
Login

Differences From Artifact [885fd93f8a]:

To Artifact [cf3eba2587]:


17
18
19
20
21
22
23
24



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
;;     along with Megatest.  If not, see <http://www.gnu.org/licenses/>.

(declare (unit nmsg-transport))

(module
 nmsg-transport
 (
  *



  )

(import scheme posix chicken data-structures ports)

(use pkts)
(use nanomsg srfi-18)

;;start a server, returns the connection
;;
(define (start-server portnum )
  (let ((rep (nn-socket 'rep)))
    (handle-exceptions
     exn
     (let ((emsg ((condition-property-accessor 'exn 'message) exn)))
       (print "ERROR: Failed to start server \"" emsg "\"")
       #f)
     (nn-bind rep (conc "tcp://*:" portnum)))
    rep))

;; 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)
;;
(define (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







<
>
>
>









|














|







17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
;;     along with Megatest.  If not, see <http://www.gnu.org/licenses/>.

(declare (unit nmsg-transport))

(module
 nmsg-transport
 (

  nmsg:start-server
  nmsg:open-send-close
  nmsg:open-send-receive
  )

(import scheme posix chicken data-structures ports)

(use pkts)
(use nanomsg srfi-18)

;;start a server, returns the connection
;;
(define (nmsg:start-server portnum )
  (let ((rep (nn-socket 'rep)))
    (handle-exceptions
     exn
     (let ((emsg ((condition-property-accessor 'exn 'message) exn)))
       (print "ERROR: Failed to start server \"" emsg "\"")
       #f)
     (nn-bind rep (conc "tcp://*:" portnum)))
    rep))

;; 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)
;;
(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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
       (thread-start! th1)
       (thread-start! th2)
       (thread-join! th1)
       res))))

;; default timeout is 3 seconds
;;
(define (open-send-receive host-port msg attrib #!key (timeout 3)(proc #f)) 
  (let ((req  (nn-socket 'req))
        (uri  (conc "tcp://" host-port))
        (res  #f)
        (mode (alist-ref 'mode attrib))) 
    (handle-exceptions
     exn
     (let ((emsg ((condition-property-accessor 'exn 'message) exn)))







|







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
       (thread-start! th1)
       (thread-start! th2)
       (thread-join! th1)
       res))))

;; default timeout is 3 seconds
;;
(define (nmsg:open-send-receive host-port msg attrib #!key (timeout 3)(proc #f)) 
  (let ((req  (nn-socket 'req))
        (uri  (conc "tcp://" host-port))
        (res  #f)
        (mode (alist-ref 'mode attrib))) 
    (handle-exceptions
     exn
     (let ((emsg ((condition-property-accessor 'exn 'message) exn)))