Last change
on this file since 39071 was
39071,
checked in by Moritz Heidkamp, 3 months ago
|
vandusen-remote: Always close ports after having accepted a connection (i.e. also in error cases). Also, use some shorter timeouts - the defaults are unnecesserily generous for this use case.
|
File size:
2.2 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 | (receive (in out) (tcp-accept listener) |
---|
22 | (thread-start! (lambda () |
---|
23 | (dynamic-wind |
---|
24 | void |
---|
25 | (lambda () |
---|
26 | (let ((line (read-line in))) |
---|
27 | (and-let* ((match (irregex-match |
---|
28 | '(seq (submatch (+ (~ space))) |
---|
29 | " " |
---|
30 | (submatch (+ any))) |
---|
31 | line))) |
---|
32 | (say (string-trim (irregex-match-substring match 2)) |
---|
33 | (irregex-match-substring match 1))))) |
---|
34 | (lambda () |
---|
35 | (close-input-port in) |
---|
36 | (close-output-port out))))) |
---|
37 | (loop))))))))) |
---|
38 | |
---|
39 | ) |
---|
Note: See
TracBrowser
for help on using the repository browser.