[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 218/324: mq-impl/stream: Name the reader and writer thun
From: |
gnunet |
Subject: |
[gnunet-scheme] 218/324: mq-impl/stream: Name the reader and writer thunks. |
Date: |
Tue, 21 Sep 2021 13:24:18 +0200 |
This is an automated email from the git hooks/post-receive script.
maxime-devos pushed a commit to branch master
in repository gnunet-scheme.
commit a4fa419b648276beb2565cbab0d6b795a78dd7e2
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Sep 1 09:46:22 2021 +0200
mq-impl/stream: Name the reader and writer thunks.
This makes writing changelog entries simpler,
and will be useful for unifying connect/fibers and
port->message-queue.
* gnu/gnunet/mq-impl/stream.scm
(port->message-queue)[start-reader!,start-writer!]:
Move arguments of 'spawn' to a named variable.
---
gnu/gnunet/mq-impl/stream.scm | 118 +++++++++++++++++++++---------------------
1 file changed, 60 insertions(+), 58 deletions(-)
diff --git a/gnu/gnunet/mq-impl/stream.scm b/gnu/gnunet/mq-impl/stream.scm
index 6a03b8a..a8d0606 100644
--- a/gnu/gnunet/mq-impl/stream.scm
+++ b/gnu/gnunet/mq-impl/stream.scm
@@ -281,64 +281,66 @@ XXX: Likewise for connect/fibers?"
;; an appropriate error, unless the other fiber will do it already.
(define closed-condition (make-condition))
(define mq (make-message-queue handlers error-handler interrupt!))
- (spawn (lambda ()
- (define-values (key . rest)
- (let/ec escape
- (define wait-op
- (choice-operation
- (wait-until-port-readable-operation port)
- (wrap-operation (wait-operation closed-condition)
- (lambda ()
- (escape 'input:regular-end-fof-file)))))
- (define (new-waiter . _)
- (perform-operation wait-op))
- ;; XXX: if (define-values error ...) is written and
- ;; 'handle-input!' raises an error (resulting in a
backtrace),
- ;; a segfault can
- ;; happen:
<https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50153>.
- (parameterize ((current-read-waiter new-waiter))
- (handle-input! mq port #:return values))))
- (when (signal-condition! closed-condition)
- (apply inject-error! mq key rest))))
- (spawn (lambda ()
- (let/ec escape
- ;; operation for calling the escape continuation when
- ;; when the other fiber detected the connection is broken
- (define escape-when-closed-operation
- (wrap-operation (wait-operation closed-condition)
- escape))
- ;; operation for waiting until the port is writable
- ;; or the other fiber detected the connection is broken.
- (define wait-writable-operation
- (choice-operation
- escape-when-closed-operation
- (wait-until-port-writable-operation port)))
- (define (wait!)
- (perform-operation
- (choice-operation
- (prepare-await-trigger! rcvar)
- ;; Don't wait for the port to be writable here!
- ;;
- ;; Otherwise, if the port is writable, but the message
- ;; queue has nothing buffered for a while, the fiber
- ;; keeps spinning.
- ;;
- ;; XXX it would be nice if it could be detected when the
- ;; write end of the port is closed.
- escape-when-closed-operation)))
- (define (wait!/blocking)
- (perform-operation wait-writable-operation))
- (define old-waiter (current-write-waiter))
- (define (new-waiter p)
- (if (eq? p port)
- (wait!/blocking)
- ;; Maybe a backtrace is being printed,
- ;; 'system-async-mark' is used ...
- (old-waiter p)))
- (parameterize ((current-write-waiter new-waiter))
- (handle-output! mq port wait!)))
- (when (signal-condition! closed-condition)
- (inject-error! mq 'input:regular-end-of-file))))
+ (define (start-reader!)
+ (define-values (key . rest)
+ (let/ec escape
+ (define wait-op
+ (choice-operation
+ (wait-until-port-readable-operation port)
+ (wrap-operation (wait-operation closed-condition)
+ (lambda ()
+ (escape 'input:regular-end-fof-file)))))
+ (define (new-waiter . _)
+ (perform-operation wait-op))
+ ;; XXX: if (define-values error ...) is written and
+ ;; 'handle-input!' raises an error (resulting in a backtrace),
+ ;; a segfault can
+ ;; happen: <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50153>.
+ (parameterize ((current-read-waiter new-waiter))
+ (handle-input! mq port #:return values))))
+ (when (signal-condition! closed-condition)
+ (apply inject-error! mq key rest)))
+ (define (start-writer!)
+ (let/ec escape
+ ;; operation for calling the escape continuation when
+ ;; when the other fiber detected the connection is broken
+ (define escape-when-closed-operation
+ (wrap-operation (wait-operation closed-condition)
+ escape))
+ ;; operation for waiting until the port is writable
+ ;; or the other fiber detected the connection is broken.
+ (define wait-writable-operation
+ (choice-operation
+ escape-when-closed-operation
+ (wait-until-port-writable-operation port)))
+ (define (wait!)
+ (perform-operation
+ (choice-operation
+ (prepare-await-trigger! rcvar)
+ ;; Don't wait for the port to be writable here!
+ ;;
+ ;; Otherwise, if the port is writable, but the message
+ ;; queue has nothing buffered for a while, the fiber
+ ;; keeps spinning.
+ ;;
+ ;; XXX it would be nice if it could be detected when the
+ ;; write end of the port is closed.
+ escape-when-closed-operation)))
+ (define (wait!/blocking)
+ (perform-operation wait-writable-operation))
+ (define old-waiter (current-write-waiter))
+ (define (new-waiter p)
+ (if (eq? p port)
+ (wait!/blocking)
+ ;; Maybe a backtrace is being printed,
+ ;; 'system-async-mark' is used ...
+ (old-waiter p)))
+ (parameterize ((current-write-waiter new-waiter))
+ (handle-output! mq port wait!)))
+ (when (signal-condition! closed-condition)
+ (inject-error! mq 'input:regular-end-of-file)))
+ (spawn start-reader!)
+ (spawn start-writer!)
mq)
(define* (connect/fibers config service-name handlers error-handler
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] 192/324: tests/mq-stream: Recognise the 'input:regular-end-of-file' error., (continued)
- [gnunet-scheme] 192/324: tests/mq-stream: Recognise the 'input:regular-end-of-file' error., gnunet, 2021/09/21
- [gnunet-scheme] 206/324: mq-impl/stream: Flush the output port regularily., gnunet, 2021/09/21
- [gnunet-scheme] 198/324: doc: Document dependencies and how to get the source code., gnunet, 2021/09/21
- [gnunet-scheme] 202/324: mq-impl/stream: Allow the write fiber to stop even if blocking., gnunet, 2021/09/21
- [gnunet-scheme] 205/324: tests/mq-stream: Unbreak SIGPIPE signal handler., gnunet, 2021/09/21
- [gnunet-scheme] 203/324: tests/mq-stream: Make tests less fragile., gnunet, 2021/09/21
- [gnunet-scheme] 193/324: mq-impl/stream: Eliminate condition variable., gnunet, 2021/09/21
- [gnunet-scheme] 207/324: hat-let: Allow (dotted) variable lists with <--., gnunet, 2021/09/21
- [gnunet-scheme] 211/324: doc: Correct typo (mesage -> message), gnunet, 2021/09/21
- [gnunet-scheme] 215/324: tests/mq-stream: Use 'message-handler' macro., gnunet, 2021/09/21
- [gnunet-scheme] 218/324: mq-impl/stream: Name the reader and writer thunks.,
gnunet <=
- [gnunet-scheme] 208/324: tests/mq-stream: Don't assume setvbuf returns anything., gnunet, 2021/09/21
- [gnunet-scheme] 212/324: mq/handler: Define a macro for constructing handlers., gnunet, 2021/09/21
- [gnunet-scheme] 220/324: mq-impl/stream: Extract code to be shared with connect/fibers., gnunet, 2021/09/21
- [gnunet-scheme] 226/324: doc: Generate PDF and HTML documentation, gnunet, 2021/09/21
- [gnunet-scheme] 227/324: mq: Remove TODOs about hypothetical &malformed-message., gnunet, 2021/09/21
- [gnunet-scheme] 229/324: guix: Import missing module., gnunet, 2021/09/21
- [gnunet-scheme] 194/324: mq-impl/stream: Eliminate atomic box., gnunet, 2021/09/21
- [gnunet-scheme] 191/324: doc: Document message queue error handling., gnunet, 2021/09/21
- [gnunet-scheme] 216/324: mq: Inject errors if no appropriate message handler exists., gnunet, 2021/09/21
- [gnunet-scheme] 190/324: Correct XXX and TODO on input:regular-end-of-file., gnunet, 2021/09/21