Last change
on this file since 39074 was
39074,
checked in by Moritz Heidkamp, 3 months ago
|
vandusen-remote: Handle timeout errors from tcp-accept
|
File size:
2.5 KB
|
Line | |
---|
1 | (module vandusen-remote () |
---|
2 | |
---|
3 | (import chicken scheme) |
---|
4 | (require-library regex) |
---|
5 | (import irregex) |
---|
6 | (use extras srfi-13 vandusen tcp srfi-18 ports) |
---|
7 | |
---|
8 | (plugin 'remote |
---|
9 | (lambda () |
---|
10 | (let ((listener (tcp-listen ($ 'remote-port) |
---|
11 | (or ($ 'remote-backlog) 10) |
---|
12 | (or ($ 'remote-host) "localhost")))) |
---|
13 | (add-finalizer (lambda () |
---|
14 | (debug "finalizing remote listener") |
---|
15 | (tcp-close listener))) |
---|
16 | |
---|
17 | (thread-start! (lambda () |
---|
18 | (parameterize ((tcp-accept-timeout 10000) |
---|
19 | (tcp-read-timeout 3000)) |
---|
20 | (let loop () |
---|
21 | (condition-case |
---|
22 | (receive (in out) (tcp-accept listener) |
---|
23 | (thread-start! (lambda () |
---|
24 | (dynamic-wind |
---|
25 | void |
---|
26 | (lambda () |
---|
27 | (let ((line (read-line in))) |
---|
28 | (and-let* ((match (irregex-match |
---|
29 | '(seq (submatch (+ (~ space))) |
---|
30 | " " |
---|
31 | (submatch (+ any))) |
---|
32 | line))) |
---|
33 | (say (string-trim (irregex-match-substring match 2)) |
---|
34 | (irregex-match-substring match 1))))) |
---|
35 | (lambda () |
---|
36 | (close-input-port in) |
---|
37 | (close-output-port out))))) |
---|
38 | (loop)) |
---|
39 | (e (exn i/o net timeout) |
---|
40 | (print "tcp-accept timed out") |
---|
41 | (loop))))))))) |
---|
42 | |
---|
43 | ) |
---|
Note: See
TracBrowser
for help on using the repository browser.