Created
October 1, 2010 19:36
-
-
Save ninjudd/606724 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 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