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 bothAsyncRead
andAsyncWrite
OwnedReadHalf
andOwnedWriteHalf
: Split halves for independent reading and writingConnect
message for establishing connections- Helper functions
connect
andaccept
for client and server usage
§Usage Patterns
§Client Side (Initiating Connection)
Clients use Connect::allocate()
to create a connection request. This method returns:
- A
Connect
message to send to the server to initiate the connection - A
ConnectionCompleter
object that can be awaited for the server to finish connecting, returning theActorConnection
used 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 aConnect
message and returnAsyncRead
andAsyncWrite
streams that can be used to communicate with the other side. - connect
- Helper used by clients to initiate a connection by sending a
Connect
message to the given port and awaiting anAccept
response. ReturnsAsyncRead
andAsyncWrite
streams that can be used to communicate with the remote actor.