|
6 | 6 | [neovim-client.message :refer [id value msg-type method params
|
7 | 7 | ->response-msg]
|
8 | 8 | :as msg])
|
9 |
| - (:import [java.io DataInputStream DataOutputStream] |
10 |
| - [java.net Socket])) |
| 9 | + (:import (java.io DataInputStream DataOutputStream))) |
11 | 10 |
|
12 | 11 | (defn- method-not-found
|
13 | 12 | [msg]
|
|
20 | 19 | (let [chan (async/chan 1024)]
|
21 | 20 | (async/go-loop
|
22 | 21 | []
|
23 |
| - (when-let [msg (msgpack/unpack (DataInputStream. input-stream))] |
| 22 | + (when-let [msg (msgpack/unpack input-stream)] |
24 | 23 | (log/info "stream -> msg -> in chan: " msg)
|
25 | 24 | (async/>! chan msg)
|
26 | 25 | (recur)))
|
|
40 | 39 | []
|
41 | 40 | (when-let [msg (async/<! chan)]
|
42 | 41 | (log/info "stream <- msg <- out chan: " msg)
|
43 |
| - (write-msg! (msgpack/pack msg) (DataOutputStream. output-stream)) |
| 42 | + (write-msg! (msgpack/pack msg) output-stream) |
44 | 43 | (recur)))
|
45 | 44 | chan))
|
46 | 45 |
|
|
68 | 67 | [{:keys [input-stream output-stream out-chan in-chan]}]
|
69 | 68 | (async/close! out-chan)
|
70 | 69 | (async/close! in-chan)
|
| 70 | + ;; TODO - drain the out-chan before closing the output-stream. |
| 71 | + (log/info "closing output stream") |
| 72 | + (.close output-stream) |
| 73 | + (log/info "closing input stream") |
71 | 74 | (.close input-stream)
|
72 |
| - (.close output-stream)) |
| 75 | + (log/info "input and output streams closed")) |
73 | 76 |
|
74 |
| -(defn new* |
| 77 | +(defn new |
75 | 78 | [input-stream output-stream]
|
76 | 79 | (let [in-chan (create-input-channel input-stream)
|
| 80 | + input-stream (DataInputStream. input-stream) |
| 81 | + output-stream (DataOutputStream. output-stream) |
77 | 82 | message-table (atom {})
|
78 | 83 | method-table (atom {})
|
79 | 84 | component {:input-stream input-stream
|
|
99 | 104 | component (->response-msg (id msg) result) nil)))
|
100 | 105 | (recur))))
|
101 | 106 | component))
|
102 |
| - |
103 |
| -(defn new |
104 |
| - "Connect to msgpack-rpc channel via standard io or TCP socket." |
105 |
| - ([] (new* System/in System/out)) |
106 |
| - ([host port] |
107 |
| - (let [socket (java.net.Socket. host port)] |
108 |
| - (.setTcpNoDelay socket true) |
109 |
| - (new* (.getInputStream socket) (.getOutputStream socket))))) |
0 commit comments