Expand description
Actor-based duplex bytestream connections.
This module provides the equivalent of a TcpStream duplex bytestream connection between two actors,
implemented via actor message passing. It allows actors to communicate using familiar AsyncRead and
AsyncWrite interfaces while leveraging the hyperactor framework’s message passing capabilities.
§Overview
The connection system consists of:
ActorConnection: A duplex connection that implements bothAsyncReadandAsyncWriteOwnedReadHalfandOwnedWriteHalf: Split halves for independent reading and writingConnectmessage for establishing connections- Helper functions [
connect] andacceptfor client and server usage
§Usage Patterns
§Client Side (Initiating Connection)
Clients use Connect::allocate() to create a connection request. This method returns:
- A
Connectmessage to send to the server to initiate the connection - A
ConnectionCompleterobject that can be awaited for the server to finish connecting, returning theActorConnectionused by the client.
The typical pattern is: allocate components, send Connect message to server, await completion.
§Server Side (Accepting Connections)
Servers forward Connect messages to the accept() helper function to finish setting up the
connection, which returns the ActorConnection they can use.
Structs§
- Actor
Connection - A duplex bytestream connection between two actors. Can generally be used like a
TcpStream. - Connect
- A message sent from a client to initiate a connection.
- Connection
Completer - A helper struct that contains the state needed to complete a connection.
- Owned
Read Half - Wrap a
PortReceiver<IoMsg>as aAsyncRead. - Owned
Write Half - Wrap a
PortRef<IoMsg>as aAsyncWrite.
Functions§
- accept
- Helper used by
Handler<Connect>s to accept a connection initiated by aConnectmessage and returnAsyncReadandAsyncWritestreams that can be used to communicate with the other side.