Send bencode using BufferedOutputStream (#342)

This new implementation is faster because you only flush when you issue `.flush`, or until the buffer is full. Some simple experiments with Chlorine confirmed that small messages are being received in a whole block, instead of fragmented.
This commit is contained in:
Maurício Szabo 2020-04-11 04:47:06 -03:00 committed by GitHub
parent 1c467080fa
commit 9f199ddef7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,7 +7,7 @@
[sci.impl.interpreter :refer [eval-string*]]
[sci.impl.utils :as sci-utils]
[sci.impl.vars :as vars])
(:import [java.io StringWriter OutputStream InputStream PushbackInputStream EOFException]
(:import [java.io StringWriter OutputStream InputStream PushbackInputStream EOFException BufferedOutputStream]
[java.net ServerSocket]))
(set! *warn-on-reflection* true)
@ -166,7 +166,8 @@
(let [client-socket (.accept listener)
in (.getInputStream client-socket)
in (PushbackInputStream. in)
out (.getOutputStream client-socket)]
out (.getOutputStream client-socket)
out (BufferedOutputStream. out)]
(when @dev? (println "Connected."))
(sci/future
(sci/binding