Skip to content

Instantly share code, notes, and snippets.

@ninjudd
Created October 1, 2010 19:36
Show Gist options
  • Select an option

  • Save ninjudd/606724 to your computer and use it in GitHub Desktop.

Select an option

Save ninjudd/606724 to your computer and use it in GitHub Desktop.
;; doesn't work because the body may not always be fully realized
(defn- read-body [in length & [buffer offset]]
(lazy-seq
(if length
(if (= 0 length)
nil
(let [buffer (or buffer (char-array length))
offset (or offset 0)
count (.read in buffer offset length)]
(println offset length)
(concat
(seq (String. buffer offset count))
(read-body (- length count) in buffer offset))))
(let [c (.read in)]
(println c)
(if (= 0 c)
nil
(cons c (read-body in nil)))))))
(defn- receive-frame [in]
(locking in
(binding [*in* (io/reader in)]
(let [type (keyword (read-line))
headers (read-headers)
body (read-body *in* (:content-length headers))]
(Frame. type headers body)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment