[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 245/324: mq-impl/stream: Eliminate 'return' argument of
From: |
gnunet |
Subject: |
[gnunet-scheme] 245/324: mq-impl/stream: Eliminate 'return' argument of 'handle-input!'. |
Date: |
Tue, 21 Sep 2021 13:24:45 +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 dd8fd583a378486a93661e1d4cc4c1e112526fe7
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Sep 8 16:03:27 2021 +0200
mq-impl/stream: Eliminate 'return' argument of 'handle-input!'.
* gnu/gnunet/mq-impl/stream.scm
(handle-input!): Remove 'return' argument. Return errors from
'add-from-port!' instead of injecting them.
(prepare-port-message-queue)[start-reader!]: Remove #:return argument.
* tests/mq-stream.scm
(handle-input*): New procedure.
("messages + eof are injected in-order")
("overly small message is detected (--> stop)")
("premature eof is detected (--> stop)"): Use new procedure.
---
gnu/gnunet/mq-impl/stream.scm | 48 +++++++++++++++++--------------------------
tests/mq-stream.scm | 14 +++++++++----
2 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/gnu/gnunet/mq-impl/stream.scm b/gnu/gnunet/mq-impl/stream.scm
index df12cb6..15974a0 100644
--- a/gnu/gnunet/mq-impl/stream.scm
+++ b/gnu/gnunet/mq-impl/stream.scm
@@ -110,34 +110,29 @@ parameterise the current write waiter and install
exception handlers."
((already-sent) (error "tried to send an envelope twice"))))
;; TODO: maybe note that this procedure blocks?
- ;; TODO: rework callers and documentation
- ;; to remove 'return' argument
- (define* (handle-input! mq input #:key
- (return (lambda error
- (apply inject-error! mq error)
- (values))))
+ (define (handle-input! mq input)
"Keep reading message from the input port @var{input}.
Feed each read message in-order to @var{mq} with @code{inject-message!}.
This procedure might inject errors by its own as usual (e.g. when
-no appropriate message handler exists).
+no appropriate message handler exists). This does not include
+@code{input:overly-small}, @code{input:premature-end-of-file} or
+@code{input:regular-end-of-file}.
If a message with an overly small message size it its header
-is encountered, inject the error @code{input:overly-small type size}
-into @var{mq}, where @var{type} is the message type as an integer
-(or @code{#f} if it could not be determined) and @var{size} is the
-message size in the header.
+is encountered, return the error @code{input:overly-small type size},
+where @var{type} is the message type as an integer (or @code{#f} if it
+could not be determined) and @var{size} is the message size in the header.
-When the end-of-file has been reached, inject the error
+When the end-of-file has been reached, return (not inject) the error
@code{input:regular-end-of-file} into @var{mq}. If the end-of-file
-happened while inside a (partial) message, inject
+happened while inside a (partial) message, return
@code{input:premature-end-of-file} instead.
@code{ECONNRESET} is treated as @code{input:regular-end-of-file}.
This might or might not be correct. In case of an I/O error, TODO.
-In these exceptional cases, the call to this procedure also returns
-after injecting the error. TODO closing message queues."
+TODO closing message queues."
(let^ ((! tok (make-tokeniser))
(! (handle/message bv offset length)
(inject-message!
@@ -145,25 +140,20 @@ after injecting the error. TODO closing message queues."
;; TODO: this allocates memory
(slice/read-only
(bv-slice/read-write bv offset length))))
- ;; Thunk the call to 'inject-error!' such that
- ;; the exception handler is only active for the call to
- ;; 'add-from-port!' and not for the call to 'inject-error!'.
- (! (return/thunked . stuff)
- (lambda () (apply return stuff)))
(! (return/overly-small type size)
- (return/thunked 'input:overly-small type size))
+ (values 'input:overly-small type size))
(! (return/premature-eof)
- (return/thunked 'input:premature-end-of-file))
+ (values 'input:premature-end-of-file))
(! (return/done-eof)
- (return/thunked 'input:regular-end-of-file)))
+ (values 'input:regular-end-of-file)))
;; Prevent ‘In procedure fport_read: Connection reset by peer’
;; in tests/network-size.scm. XXX can this also happen in
;; 'handle-output!'?
- ((guard (c ((and (eq? 'system-error (exception-kind c))
- (= ECONNRESET (car (list-ref (exception-args c)
3))))
- (return/done-eof)))
- (add-from-port! tok input handle/message return/overly-small
- return/done-eof return/premature-eof)))))
+ (guard (c ((and (eq? 'system-error (exception-kind c))
+ (= ECONNRESET (car (list-ref (exception-args c)
3))))
+ (return/done-eof)))
+ (add-from-port! tok input handle/message return/overly-small
+ return/done-eof return/premature-eof))))
(define (handle-output! mq output wait!)
"Keep sending message envelopes over the output port @var{output}.
@@ -313,7 +303,7 @@ an appropriate @code{&undefined-key-error} is raised."
;; 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))))
+ (handle-input! mq port))))
(if (signal-condition! closed-condition)
(apply inject-error! mq key rest)
;; TODO: close-port can block!
diff --git a/tests/mq-stream.scm b/tests/mq-stream.scm
index 6b1850a..360e41a 100644
--- a/tests/mq-stream.scm
+++ b/tests/mq-stream.scm
@@ -76,6 +76,12 @@
;; writing to a broken pipe.
(sigaction SIGPIPE SIG_IGN)
+(define (handle-input*! mq input)
+ (call-with-values (lambda () (handle-input! mq input))
+ (lambda e
+ (apply inject-error! mq e)
+ (values))))
+
(test-assert "messages + eof are injected in-order"
(let^ ((! input/bv #vu8(0 4 0 1 ; Message type 1, size 4
0 5 0 2 1 ; Message type 2, size 6
@@ -99,9 +105,9 @@
(assert (equal? arguments '(input:regular-end-of-file)))
(set! received 'end-of-file))
(! mq (make-message-queue handlers error-handler no-sender))
- (<-- () (handle-input! mq input)))
+ (<-- () (handle-input*! mq input)))
;; TODO: should the port be closed?
- (assert (equal? received 'end-of-file))))
+ (assert (equal? received 'end-of-file)))
(test-assert "overly small message is detected (--> stop)"
(let^ ((! input/bv #vu8(0 4 0 0 ; Message type 0, size 4
@@ -128,7 +134,7 @@
(assert (equal? arguments `(input:overly-small ,(* 256 9) 3)))
(set! received 'overly-small))
(! mq (make-message-queue handlers error-handler no-sender))
- (<-- () (handle-input! mq input)))
+ (<-- () (handle-input*! mq input)))
(assert (equal? received 'overly-small))))
(test-assert "premature eof is detected (--> stop)"
@@ -140,7 +146,7 @@
(assert (equal? arguments '(input:premature-end-of-file)))
(set! received #t))
(! mq (make-message-queue no-handlers error-handler no-sender))
- (<-- () (handle-input! mq input)))
+ (<-- () (handle-input*! mq input)))
(assert (equal? received #t))))
(test-equal "envelopes are written (no blocking)"
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] 213/324: nse/client: Use 'message-handler' macro., (continued)
- [gnunet-scheme] 213/324: nse/client: Use 'message-handler' macro., gnunet, 2021/09/21
- [gnunet-scheme] 222/324: mq-impl/stream: Handle closed ports more gracefully., gnunet, 2021/09/21
- [gnunet-scheme] 223/324: mq,doc: Update TODOs about message queues., gnunet, 2021/09/21
- [gnunet-scheme] 224/324: doc: Don't forget the message verifier., gnunet, 2021/09/21
- [gnunet-scheme] 225/324: mq: Inject errors when message verification has negative result., gnunet, 2021/09/21
- [gnunet-scheme] 234/324: doc: Remove resolved TODO., gnunet, 2021/09/21
- [gnunet-scheme] 240/324: mq-impl/stream: Handle ECONNRESET gracefully., gnunet, 2021/09/21
- [gnunet-scheme] 238/324: mq-impl/stream: Allow closing queues made with connect-fibers., gnunet, 2021/09/21
- [gnunet-scheme] 244/324: doc: Document the 'disconnected' callback., gnunet, 2021/09/21
- [gnunet-scheme] 246/324: mq,mq-impl: Remove TODOs about allocating memory., gnunet, 2021/09/21
- [gnunet-scheme] 245/324: mq-impl/stream: Eliminate 'return' argument of 'handle-input!'.,
gnunet <=
- [gnunet-scheme] 251/324: tests/utils: Move call-with-spawner from tests/mq-stream.scm., gnunet, 2021/09/21
- [gnunet-scheme] 221/324: mq-impl/stream: Delay knowing the port., gnunet, 2021/09/21
- [gnunet-scheme] 228/324: doc/fdl: Correct ‘quote’ typography., gnunet, 2021/09/21
- [gnunet-scheme] 231/324: doc: Document message verifiers., gnunet, 2021/09/21
- [gnunet-scheme] 236/324: mq-impl/stream: Close the port when stopping the fibers., gnunet, 2021/09/21
- [gnunet-scheme] 242/324: nse/client: Remove unused fields., gnunet, 2021/09/21
- [gnunet-scheme] 243/324: doc/scheme-gnunet.tm: Correct use of 'connected' and 'updated'., gnunet, 2021/09/21
- [gnunet-scheme] 237/324: mq-impl/stream: Allow closing the queue on request., gnunet, 2021/09/21
- [gnunet-scheme] 247/324: nse/client: Only call 'send-start!' after 'mq' has been defined., gnunet, 2021/09/21
- [gnunet-scheme] 248/324: tests/mq-stream: Add missing parenthesis., gnunet, 2021/09/21