Skip to content

Commit 074fedd

Browse files
committed
Use FileHandle for reading/writing in JSONRPCConnection
There's a long standing issue with `DispatchIO.read` on Windows that causes a continual spin. `DispatchIO` is more complex than what we need here, so switch to `FileHandle.readabilityHandler` for reading and `FileHandle.write` for writing. Given there's been issues with `FileHandle.availableData` and we can't read to EOF, the reads are instead broken up into chunks - reading one byte at a time for the header and then the entire contents after we have the content length. The header read could be a little more optimized, but reading a single byte allows for better error handling in the case of an invalid header. Using the `FileHandle`s directly also allows us to simplify a lot of the surrounding code, as there's no need for a `DispatchGroup` or `sendQueue`. A further change could switch `JSONRPCConnection` to return an `AsyncStream` for the received messages rather than being passed a `MessageHandler` (skipping for now as this change is already large enough and all existing clients already use `MessageHandler`). Many thanks to @roman-bcny for starting this change.
1 parent f86b413 commit 074fedd

File tree

5 files changed

+291
-294
lines changed

5 files changed

+291
-294
lines changed

0 commit comments

Comments
 (0)