Permalink
Browse files

prefer receive-all to receive-in order, and make sure we wait all wri…

…tes on a streaming response to complete
  • Loading branch information...
ztellman committed Jan 25, 2012
1 parent ec66b05 commit 64dfb161d42f090c71bc06398ffbad8ac6143e52
Showing with 23 additions and 26 deletions.
  1. +3 −2 src/aleph/http/server/responses.clj
  2. +11 −9 src/aleph/netty.clj
  3. +9 −15 src/aleph/tcp.clj
@@ -131,8 +131,9 @@
(enqueue returned-result (write-to-channel netty-channel msg false))
nil)))
(fn [_]
(enqueue-and-close returned-result
(write-to-channel netty-channel HttpChunk/LAST_CHUNK false))))))
(let [final-write (write-to-channel netty-channel HttpChunk/LAST_CHUNK false)]
(enqueue-and-close returned-result final-write)
final-write)))))
;;;
View
@@ -489,6 +489,7 @@
(let [write-queue (create-write-queue
netty-channel
#(write-to-channel netty-channel nil true))]
(run-pipeline (.getCloseFuture netty-channel)
wrap-netty-channel-future
(fn [_]
@@ -498,15 +499,16 @@
(.close channel-group)
wrap-netty-channel-group-future)))
(.add channel-group netty-channel)
(run-pipeline
(receive-in-order outer
(fn [[returned-result msg]]
(enqueue write-queue
(let [result (write-to-channel netty-channel (send-encoder msg) false)]
(siphon-result result returned-result)
result))))
(fn [_]
(close write-queue)))
(receive-all outer
(fn [[returned-result msg]]
(when returned-result
(enqueue write-queue
(let [result (write-to-channel netty-channel (send-encoder msg) false)]
(siphon-result result returned-result)
result)))))
(on-drained outer #(close write-queue))
inner)))))
;;;
View
@@ -65,21 +65,15 @@
netty-channel
#(write-to-channel netty-channel nil true))]
(handler inner {:remote-addr (.getRemoteAddress netty-channel)})
(run-pipeline nil
:error-handler (fn [ex]
(when-not (trace [(:name options) :errors]
{:exception ex, :channel inner})
(log/error ex "Unhandled exception in TCP connection handler.")))
(fn [_]
(receive-in-order outer
(fn [[returned-result msg]]
(enqueue write-queue
(let [result (write-to-channel netty-channel (send-encoder msg) false)]
(siphon-result result returned-result)
result))
nil)))
(fn [_]
(close write-queue)))))))
(receive-all outer
(fn [[returned-result msg]]
(when returned-result
(enqueue write-queue
(let [result (write-to-channel netty-channel (send-encoder msg) false)]
(siphon-result result returned-result)
result)))
nil))
(on-drained outer #(close write-queue))))))
:channel-close (upstream-stage
(channel-close-stage
(fn [_]

0 comments on commit 64dfb16

Please sign in to comment.