Skip to content

Commit

Permalink
force-output of a prepend-stream
Browse files Browse the repository at this point in the history
%Testing: aserve/test/t-aserve.cl

The prepend-stream is a stream defined in AllegroServe.
In this change we cause a force-output of a prepend-stream
to pass the data in the prepend-stream's buffer to the underlying
stream and then do a force-output of the underlying stream.
As the prepend-stream is used when sending a response back to
the client this allows a function handling an http request
to send the response back in pieces and have those pieces available
to the client as soon as they are computed.

Change-Id: I92c1d65a479ef7e9ab4945a009bf0a343c99120c
Reviewed-on: https://gerrit.franz.com:9080/9692
Reviewed-by: John Foderaro <jkf@franz.com>
Reviewed-by: Kevin Layer <layer@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information
John Foderaro authored and dklayer committed Jan 29, 2018
1 parent 7aad175 commit 718b6af
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.cl
Expand Up @@ -21,7 +21,7 @@
#+ignore
(check-smp-consistency)

(defparameter *aserve-version* '(1 3 55))
(defparameter *aserve-version* '(1 3 56))

(eval-when (eval load)
(require :sock)
Expand Down
10 changes: 6 additions & 4 deletions packages.cl
Expand Up @@ -5,8 +5,9 @@
;; See the file LICENSE for the full license governing this code.

#+(version= 10 1)
(sys:defpatch "aserve" 7
"v7: 1.3.55: Add and export a more full set of http response codes;
(sys:defpatch "aserve" 8
"v8: 1.3.56: force-output of a prepend-stream supported
v7: 1.3.55: Add and export a more full set of http response codes;
v6: 1.3.54: Use Allegro's built-in base64 routines when available;
v5: 1.3.53: Add :no-keep-alive strategy;
v4: 1.3.52: optimize compilation for speed;
Expand All @@ -17,8 +18,9 @@ v1: 1.3.49: speed up read-sock-line."
:post-loadable t)

#+(version= 10 0)
(sys:defpatch "aserve" 18
"v18: 1.3.55: Add and export a more full set of http response codes;
(sys:defpatch "aserve" 19
"v19: 1.3.56: force-output of a prepend-stream supported
v18: 1.3.55: Add and export a more full set of http response codes;
v17: 1.3.54: Use Allegro's built-in base64 routines when available;
v16: 1.3.53: Add :no-keep-alive strategy;
v15: 1.3.52: optimize compilation for speed;
Expand Down
7 changes: 6 additions & 1 deletion publish.cl
Expand Up @@ -2986,10 +2986,15 @@
(write-full-vector content output-handle))

(if* (> end start)
then (write-full-vector (or buffer (slot-value p 'excl::buffer))
then (prog1 (write-full-vector (or buffer (slot-value p 'excl::buffer))
output-handle
:start start
:end end)
;; this will cause a force-output of the prepend-stream
;; to also force-output the underlying stream.
;; We'll also force-output when the buffer fills up
;; and that's not a bad thing to do and it is unavoidable.
(force-output output-handle))
else start)))


Expand Down
32 changes: 32 additions & 0 deletions test/t-aserve.cl
Expand Up @@ -346,6 +346,9 @@
(stop-proxy-running)
))

;; independent test of a stream used in aserve
(test-force-output-prepend-stream)

(if* (and ssl (errorset (as-require :ssl)))
then (test-aserve-extra-ssl))
)
Expand Down Expand Up @@ -2922,7 +2925,36 @@ Returns a vector."
(test t seen-error-3)
(and *wserver* (shutdown)))))


(defun test-force-output-prepend-stream ()
;; the prepend-stream is defined in aserve
;; we test here that force-output of such
;; a stream will force-output the underlying
;; stream
(let* ((passive (socket:make-socket :connect :passive))
(sender (socket:make-socket :remote-host "127.0.0.1"
:remote-port
(socket:local-port passive)))
(receiver (socket:accept-connection passive))
(prepend (net.aserve::make-instance-prepend-stream+content+output-handle
"" ; no content
sender)))
(unwind-protect
(progn
(write-byte 1 prepend)
(force-output prepend)

(mp::with-timeout (10 (test nil "force-output of prepend-stream didn't work"))

;; read-byte will return immediately if the force-output
;; was successful
(test 1 (read-byte receiver))))

(close passive)
(close sender)
(close receiver))))




;; (net.aserve::debug-on :xmit)
Expand Down

0 comments on commit 718b6af

Please sign in to comment.