TcpStream¶
Import: import system.net;
Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.
TcpStream¶
An owned TCP byte stream supporting one simultaneous read and one simultaneous write.
connect¶
Connects with a deadline in milliseconds; zero disables the deadline.
public static async fun connect(
host: string,
port: int,
timeout_ms: int = 0,
token: Option<CancellationToken> = Option.None
): Result<TcpStream, IoError>
local_host¶
Numeric local interface address selected for this connection.
local_port¶
Actual bound local port.
peer_host¶
Numeric remote address of the peer.
peer_port¶
Remote TCP port of the peer.
read_async¶
Reads at least one and at most max_bytes bytes, returning whatever has arrived. A request above 1 MiB returns at most 1 MiB per call. A positive-size empty success denotes peer EOF.
public async unique fun read_async(
max_bytes: int,
token: Option<CancellationToken> = Option.None
): Result<byte[], IoError>
read_with_timeout¶
Reads with a per-operation deadline; a concurrent read returns EBUSY.
public fun read_with_timeout(
max_bytes: int,
timeout_ms: int,
token: Option<CancellationToken> = Option.None
): Future<Result<byte[], IoError>>
write_async¶
Writes a partial byte count; cancellation preserves completed side effects.
public async unique fun write_async(
bytes: byte[],
token: Option<CancellationToken> = Option.None
): Result<int, IoError>
write_all_async¶
Retries partial writes until every byte has been accepted; does not roll back failures.
public async fun write_all_async(
bytes: byte[],
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
flush_async¶
TCP writes are unbuffered by this wrapper; validates openness and cancellation.
public async unique fun flush_async(
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
shutdown_write¶
Sends FIN after accepted writes while retaining the read side; pending writes return EBUSY.
set_nodelay¶
Enables or disables TCP_NODELAY; pending native reads may return EBUSY.
close¶
Closes the owned socket and wakes pending operations; repeated closure succeeds.