baml.net.TcpStream

A TCP connection. Created by `baml.net.TcpStream.connect` or returned by `baml.net.TcpListener.accept`.

Reference version

Signature

class baml.net.TcpStream

A TCP connection. Created by baml.net.TcpStream.connect or returned by baml.net.TcpListener.accept.

Implements baml.io.Read and baml.io.Write.

Source:<builtin>/baml/ns_net/net.bamlbytes 167–1827

Fields

_handle

$rust_type

(internal)

Static methods

function

connect

(
addr: string,
timeout: baml.time.Duration | null = …
) -> baml.net.TcpStream throws baml.errors.Io | baml.errors.Timeout

Opens a TCP connection to addr (e.g. "127.0.0.1:8080") and returns the stream.

timeout bounds how long to wait for the connection to be established; null (the default) waits indefinitely (subject to the OS default). On expiry this throws baml.errors.Timeout.

Instance methods

function

close

(self) -> null throws baml.errors.Io

Closes the connection.

Implementations

baml.Concrete for T

Static methods

function

type

() -> reflect.Type throws never

This type's runtime type value: int.type() is the same value as reflect.Type.of<int>().

Spell it on a declared type written as one name, optionally qualified or with generic arguments: Foo.type(), root.models.Base.type(), Box<int[]>.type(). Array, optional, union, map and function types, interfaces, and generic type parameters keep the reflect.Type.of<T>() form. A type that declares its own type member keeps resolving to it.

Source:<builtin>/baml/core.bamlbytes 1360–1392

baml.io.Read for baml.net.TcpStream

Instance methods

function

bytes

(self) -> uint8array throws baml.errors.Io

Consume all remaining bytes through EOF.

function

read

(self, limit: int) -> uint8array | null throws baml.errors.Io

Read at most limit bytes. Blocks until data or EOF is available.

Source:<builtin>/baml/ns_net/net.bamlbytes 1135–1364

baml.io.Write for baml.net.TcpStream

Instance methods

function

flush

(self) -> null throws never

No-op because TCP streams are unbuffered.

function

write

(self, data: string | uint8array) -> int throws baml.errors.Io

Write all of data to the destination. Strings are encoded as UTF-8. Returns the number of bytes written.

Like Rust's write_all, this does not flush: it is a loop over write_some, and pushing buffered bytes onward stays the caller's separate flush. Implementors are expected to make write_some report its own failures rather than defer them.

function

write_some

(self, data: uint8array) -> int throws baml.errors.Io

Attempt one write and return the number of bytes accepted.

Source:<builtin>/baml/ns_net/net.bamlbytes 1370–1704