Module connect

Source
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:

§Usage Patterns

§Client Side (Initiating Connection)

Clients use Connect::allocate() to create a connection request. This method returns:

  1. A Connect message to send to the server to initiate the connection
  2. A ConnectionCompleter object that can be awaited for the server to finish connecting, returning the ActorConnection 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§

ActorConnection
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.
ConnectionCompleter
A helper struct that contains the state needed to complete a connection.
OwnedReadHalf
Wrap a PortReceiver<IoMsg> as a AsyncRead.
OwnedWriteHalf
Wrap a PortRef<IoMsg> as a AsyncWrite.

Functions§

accept
Helper used by Handler<Connect>s to accept a connection initiated by a Connect message and return AsyncRead and AsyncWrite 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 an Accept response. Returns AsyncRead and AsyncWrite streams that can be used to communicate with the remote actor.