class
ACP::StdioTransport
- ACP::StdioTransport
- ACP::Transport
- Reference
- Object
Overview
Implements the ACP transport over a pair of IO objects. In the typical case these are the stdin (for writing) and stdout (for reading) of a spawned agent child process.
Incoming messages are read in a background fiber and placed into
a buffered channel so that #receive never blocks the writer.
Thread safety: Crystal fibers are cooperatively scheduled on a single thread, so we don't need mutexes — just channels.
Direct Known Subclasses
Defined in:
acp/transport.crConstructors
-
.new(reader : IO, writer : IO, buffer_size : Int32 = 256)
Creates a new stdio transport.
Instance Method Summary
-
#close : Nil
Closes the transport, signaling the reader to stop and closing the underlying IO objects.
-
#closed? : Bool
Returns true if the transport has been closed.
-
#incoming : Channel(JSON::Any | Nil)
The channel that the reader fiber pushes parsed messages into.
-
#receive(timeout : Time::Span) : JSON::Any | Nil
Receives with a timeout.
-
#receive : JSON::Any | Nil
Receives the next incoming JSON-RPC message.
-
#send(message : Hash(String, JSON::Any)) : Nil
Sends a JSON-RPC message over the transport.
Instance methods inherited from class ACP::Transport
close : Nil
close,
closed? : Bool
closed?,
receive : JSON::Any | Nil
receive,
send(message : Hash(String, JSON::Any)) : Nil
send,
send_json(obj : Hash(String, JSON::Any)) : Nil
send_json
Constructor Detail
Creates a new stdio transport.
reader— the IO to read incoming JSON-RPC messages from (typically the agent process's stdout).writer— the IO to write outgoing JSON-RPC messages to (typically the agent process's stdin).buffer_size— how many messages to buffer in the channel before back-pressuring the reader fiber. Default 256.
Instance Method Detail
Closes the transport, signaling the reader to stop and closing the underlying IO objects.
The channel that the reader fiber pushes parsed messages into. A nil value signals that the reader has stopped (EOF or error).
Receives with a timeout. Returns nil if no message arrives within the given duration.
Receives the next incoming JSON-RPC message. Blocks until a message is available. Returns nil if the transport is closed or the reader encountered EOF.
Sends a JSON-RPC message over the transport. The message is serialized as a single line of JSON followed by a newline.