-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrrbroker.scm
36 lines (30 loc) · 1012 Bytes
/
rrbroker.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(use zmq srfi-18)
(define front (make-socket 'xrep)) ;; FIXME: should be 'router
(define back (make-socket 'xreq)) ;; FIXME: should be 'dealer
(bind-socket front "tcp://*:5559")
(bind-socket back "tcp://*:5560")
(define-syntax forever
(syntax-rules () ((forever e0 e1 ...)
(let loop () e0 e1 ... (loop)))))
(define (route)
(forever
(let more ()
(let ((msg (receive-message* front))
(more? (socket-option front 'rcvmore)))
(printf "routing ~s more? ~a\n" msg more?)
(send-message back msg send-more: more?)
(when more? (more))))))
(define (deal)
(forever
(let more ()
(let ((msg (receive-message* back))
(more? (socket-option back 'rcvmore)))
(printf "dealing ~s more? ~a\n" msg more?)
(send-message front msg send-more: more?)
(when more? (more))))))
(let ((rt (make-thread route))
(dt (make-thread deal)))
(thread-start! rt)
(thread-start! dt)
(thread-join! rt)
(thread-join! dt))