Overview
Context
Changes
Modified ulex-trials/Makefile
from [e108f86d9a]
to [cec464a43d].
1
2
3
4
5
6
7
8
|
1
2
3
4
5
6
7
8
|
-
+
-
+
|
ulex-test : ulex-test.scm
ulex-test : ulex-test.scm ../ulex/ulex.scm
csc ulex-test.scm
test : ulex-test
./ulex-test do-test
for x in $$(seq 9);do export NBFAKE_LOG=NBFAKE_$$x;sleep 1;nbfake ./ulex-test run 828$$x;echo $$cmd;$$cmd;done
clean :
rm -f .runners/* NBFAKE*
|
Modified ulex-trials/ulex-test.scm
from [563b467581]
to [f76ffe0828].
︙ | | |
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
|
directory-utils
ulex
)
(define help "Usage: ulex-test COMMAND
where COMMAND is one of:
do-test : run the basic req/rep test
run tcp://host:port : start test server - start several in same dir
run host:port : start test server - start several in same dir
")
(define address-tcp-1 "tcp://localhost:5555")
(define address-tcp-2 "tcp://localhost:6666")
(define address-inproc-1 "inproc://local1")
(define address-inproc-2 "inproc://local2")
;;;
;;; Req-Rep
;;;
(define (make-listening-reply-socket address)
(let ((socket (make-rep-socket)))
(socket-set! socket 'nng/recvtimeo 2000)
(nng-listen socket address)
socket))
(define (make-dialed-request-socket address)
(let ((socket (make-req-socket)))
(socket-set! socket 'nng/recvtimeo 2000)
(nng-dial socket address)
socket))
(define (req-rep-test address)
(let ((rep (make-listening-reply-socket address))
(req (make-dialed-request-socket address)))
(nng-send req "message 1")
(nng-recv rep)
(nng-send rep "message")
(begin0
(nng-recv req)
(nng-close! rep))))
(define (do-test)
(define (call uconn msg addr)
(test-group "nng"
(test "tcp req-rep"
"message"
(req-rep-test address-tcp-1))
(test "inproc req-rep"
"message"
(req-rep-test address-inproc-1)))
(test-exit))
;; this should be run in a thread
(define (run-listener-responder socket myaddr)
(let loop ((status 'running))
(let* ((msg (nng-recv socket))
(response (process-message msg)))
(if (not (eq? response 'done))
(begin
(nng-send socket response)
(loop status))))))
(define *channels* (make-hash-table))
(define (call channels msg addr)
(let* ((csocket (hash-table-ref/default channels addr #f))
(socket (or csocket (make-dialed-request-socket addr))))
(nng-send socket msg)
(print "Sent: "msg", received: "(nng-recv socket))
(print "Sent: "msg", received: "
(if (not (hash-table-exists? channels addr))
(hash-table-set! channels addr socket))))
(send-receive uconn addr 'hello msg)))
;; start => hello 0
;; hello 0 => hello 1
;; hello 1 => hello 2
;; ...
;; hello 11 => 'done
;;
|
︙ | | |
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
-
-
+
+
-
-
-
+
+
+
+
+
-
-
-
-
-
+
-
-
+
-
+
|
(conc msg " 0"))
(else
"hello 0"))))
(define (main)
(match
(command-line-arguments)
(("do-test")(do-test))
((run myaddr)
((run myport)
;; start listener
;; put myaddr into file by host-pid in .runners
;; for 1 minute
;; get all in .runners
;; call each with a message
;;
(let* ((port (string->number myport))
(let* ((endtimes (+ (current-seconds) 20)) ;; run for 20 seconds
(socket (make-listening-reply-socket myaddr))
(rfile (conc ".runners/"(get-host-name)"-"(current-process-id)))
(endtimes (+ (current-seconds) 20)) ;; run for 20 seconds
(handler (lambda (rem-host-port qrykey cmd params)
(process-message params)))
(uconn (run-listener handler myport))
(rfile (conc ".runners/"(get-host-name)"-"(current-process-id))))
(th1 (make-thread (lambda ()
(run-listener-responder socket myaddr)
)
"responder")))
(if (not (and (file-exists? ".runners")
(directory? ".runners")))
(create-directory ".runners" #t))
(with-output-to-file rfile
(lambda ()
(print myaddr)))
(print myport)))
(thread-start! th1)
(let loop ((entries '()))
(if (> (current-seconds) endtimes)
(begin
(delete-file* rfile)
(sleep 1)
(exit))
(if (null? entries)
(loop (glob ".runners/*"))
(let* ((entry (car entries))
(destaddr (with-input-from-file entry read-line)))
(call *channels* (conc "hello-from-"destaddr) destaddr)
(call uconn (conc "hello-from-"myport"to-"destaddr) destaddr)
;; (thread-sleep! 0.025)
(loop (cdr entries))))))))
((cmd)(print "ERROR: command "cmd", not recognised.\n\n"help))
(else
(print help))))
) ;; end module
(import nng-test)
(import ulex-test)
(main)
|
Modified ulex.scm
from [64369b6c76]
to [f004a2cedd].
︙ | | |
16
17
18
19
20
21
22
23
24
|
16
17
18
19
20
21
22
23
24
|
-
-
+
+
|
;; You should have received a copy of the GNU General Public License
;; along with Megatest. If not, see <http://www.gnu.org/licenses/>.
;;======================================================================
(declare (unit ulex))
;; (include "ulex/ulex.scm")
(include "ulex-simple/ulex.scm")
(include "ulex/ulex.scm")
;; (include "ulex-simple/ulex.scm")
|
Modified ulex/ulex.scm
from [ded9484f4d]
to [70c15d4319].
︙ | | |
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
-
+
+
|
;; See README in the distribution at https://www.kiatoa.com/fossils/ulex
;; NOTES:
;; Why sql-de-lite and not say, dbi? - performance mostly, then simplicity.
;;
;;======================================================================
(module ulex
(
*
#;(
;; NOTE: looking for the handler proc - find the run-listener :)
run-listener ;; (run-listener handler-proc [port]) => uconn
;; NOTE: handler-proc params;
;; (handler-proc rem-host-port qrykey cmd params)
|
︙ | | |
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
-
+
-
+
|
(work-queue-thread #f)
(num-threads-running 0)
)
;; Parameters
;; work-method:
(define work-method (make-parameter 'direct))
(define work-method (make-parameter 'mailbox))
;; mailbox - all rdat goes through mailbox
;; threads - all rdat immediately executed in new thread
;; direct - no queuing
;;
;; return-method, return the result to waiting send-receive:
(define return-method (make-parameter 'direct))
(define return-method (make-parameter 'mailbox))
;; mailbox - create a mailbox and use it for passing returning results to send-receive
;; polling - put the result in a hash table keyed by qrykey and send-receive can poll it for result
;; direct - no queuing, result is passed back in single tcp connection
;;
;; ;; struct for keeping track of others we are talking to
;; ;;
|
︙ | | |