diff options
author | Maxime Devos <maximedevos@telenet.be> | 2021-09-12 17:25:54 +0200 |
---|---|---|
committer | Maxime Devos <maximedevos@telenet.be> | 2021-09-21 12:21:06 +0200 |
commit | 1f416463bd46b669dc9929dc9453db9f22feacd1 (patch) | |
tree | 9b7a1c8e3e9f8e1d26dd20a20e793159db785328 /gnu/gnunet/nse | |
parent | 9b37dcd204b49f6843be9722e5a9ba7c7d6be4d4 (diff) | |
download | gnunet-scheme-1f416463bd46b669dc9929dc9453db9f22feacd1.tar.gz gnunet-scheme-1f416463bd46b669dc9929dc9453db9f22feacd1.zip |
nse/client: Stop reconnecting when a disconnect is requested.
* gnu/gnunet/nse/client.scm
(<server>)[request-close?/box]: New field.
(disconnect!): Set new box before signalling the condition.
(reconnect)[error-handler]{input:regular-end-of-file,input:premature-end-of-file}:
When the new box holds #t as value, don't reconnect.
(connect): Adjust callers.
* tests/network-size.scm
("close, connected --> all fibers stop, two callbacks called"): New test.
Diffstat (limited to 'gnu/gnunet/nse')
-rw-r--r-- | gnu/gnunet/nse/client.scm | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/gnu/gnunet/nse/client.scm b/gnu/gnunet/nse/client.scm index 006d533..21af1bb 100644 --- a/gnu/gnunet/nse/client.scm +++ b/gnu/gnunet/nse/client.scm | |||
@@ -38,7 +38,7 @@ | |||
38 | begin define quote lambda case values expt = else apply | 38 | begin define quote lambda case values expt = else apply |
39 | and >=) | 39 | and >=) |
40 | (only (rnrs control) | 40 | (only (rnrs control) |
41 | when) | 41 | when unless) |
42 | (only (rnrs records syntactic) | 42 | (only (rnrs records syntactic) |
43 | define-record-type) | 43 | define-record-type) |
44 | (only (ice-9 atomic) | 44 | (only (ice-9 atomic) |
@@ -83,6 +83,10 @@ | |||
83 | (define-record-type (<server> %make-server server?) | 83 | (define-record-type (<server> %make-server server?) |
84 | ;; Atomic box of <estimate> | 84 | ;; Atomic box of <estimate> |
85 | (fields (immutable estimate/box server-estimate/box) | 85 | (fields (immutable estimate/box server-estimate/box) |
86 | ;; Atomic box of boolean. Initially #f. Set this | ||
87 | ;; to #t before signalling request-close-condition. | ||
88 | (immutable request-close?/box | ||
89 | server-request-close?/box) | ||
86 | (immutable request-close-condition | 90 | (immutable request-close-condition |
87 | server-request-close-condition))) | 91 | server-request-close-condition))) |
88 | 92 | ||
@@ -117,10 +121,12 @@ timestamp." | |||
117 | (define (disconnect! server) | 121 | (define (disconnect! server) |
118 | "Asynchronuously disconnect from the NSE server and stop reconnecting, | 122 | "Asynchronuously disconnect from the NSE server and stop reconnecting, |
119 | even if not connected. This is an idempotent operation." | 123 | even if not connected. This is an idempotent operation." |
124 | (atomic-box-set! (server-request-close?/box server) #t) | ||
120 | (signal-condition! (server-request-close-condition server))) | 125 | (signal-condition! (server-request-close-condition server))) |
121 | 126 | ||
122 | ;; See 'connect'. | 127 | ;; See 'connect'. |
123 | (define* (reconnect estimate/box request-close-condition config #:key | 128 | (define* (reconnect estimate/box request-close?/box request-close-condition config |
129 | #:key | ||
124 | updated connected disconnected spawn #:rest rest) | 130 | updated connected disconnected spawn #:rest rest) |
125 | (define (handle-estimate! estimate-slice) | 131 | (define (handle-estimate! estimate-slice) |
126 | (define estimate | 132 | (define estimate |
@@ -169,7 +175,15 @@ even if not connected. This is an idempotent operation." | |||
169 | ;; be confusing. | 175 | ;; be confusing. |
170 | (signal-condition! mq-closed) | 176 | (signal-condition! mq-closed) |
171 | (when disconnected (disconnected)) | 177 | (when disconnected (disconnected)) |
172 | (apply reconnect estimate/box request-close-condition config rest)) | 178 | ;; Don't reconnect after 'close-queue!'. About races: it's not |
179 | ;; paramount we stop reconnecting immediately, but we should stop | ||
180 | ;; eventually after 'request-close?/box' is set and | ||
181 | ;; 'request-close-condition' is signalled, and 'request-close-handler' | ||
182 | ;; will take care of closing the new queue if it shouldn't have been | ||
183 | ;; created. | ||
184 | (unless (atomic-box-ref request-close?/box) | ||
185 | (apply reconnect estimate/box request-close?/box request-close-condition | ||
186 | config rest))) | ||
173 | ((connection:interrupted) | 187 | ((connection:interrupted) |
174 | (values)) | 188 | (values)) |
175 | (else | 189 | (else |
@@ -205,8 +219,9 @@ shortly after calling @var{disconnected}. | |||
205 | 219 | ||
206 | The procedures @var{updated}, @var{connected} and @var{disconnected} are optional." | 220 | The procedures @var{updated}, @var{connected} and @var{disconnected} are optional." |
207 | (define estimate/box (make-atomic-box #f)) | 221 | (define estimate/box (make-atomic-box #f)) |
222 | (define request-close?/box (make-atomic-box #f)) | ||
208 | (define request-close-condition (make-condition)) | 223 | (define request-close-condition (make-condition)) |
209 | (reconnect estimate/box request-close-condition config | 224 | (reconnect estimate/box request-close?/box request-close-condition config |
210 | #:updated updated #:connected connected #:disconnected disconnected | 225 | #:updated updated #:connected connected #:disconnected disconnected |
211 | #:spawn spawn) | 226 | #:spawn spawn) |
212 | (%make-server estimate/box request-close-condition)))) | 227 | (%make-server estimate/box request-close?/box request-close-condition)))) |