Module net/tcp

net/tcp

Async TCP networking — listeners and streams with Exception-based error handling.

Types

TcpListener object
TcpListener

A TCP socket that listens for incoming connections.

Fields

NameTypeDescription
_fdi32
_local_addrSocketAddr
_is_closedbool

Trait Implementations

impl(TcpListener, ...)
bind : (TcpListener) fn(addr : SocketAddr, using(io : IO)) -> Impl(Future(TcpListener, IO, Exception))

Bind to a socket address and start listening.

Parameters

NameTypeNotes
addrSocketAddr

Returns: Impl(Future(TcpListener, IO, Exception))

accept : (TcpListener) fn(self : TcpListener, using(io : IO)) -> Impl(Future(TcpStream, IO, Exception))

Accept an incoming connection, returning a new TcpStream.

Parameters

NameTypeNotes
selfTcpListener

Returns: Impl(Future(TcpStream, IO, Exception))

local_addr : (TcpListener) fn(self : TcpListener) -> SocketAddr

Get the local address this listener is bound to.

Parameters

NameTypeNotes
selfTcpListener

Returns: SocketAddr

close : (TcpListener) fn(self : TcpListener, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Close the stream.

Parameters

NameTypeNotes
selfTcpListener

Returns: Impl(Future(unit, IO, Exception))

fd : (TcpListener) fn(self : TcpListener) -> i32

Get the underlying file descriptor.

Parameters

NameTypeNotes
selfTcpListener

Returns: i32

impl(TcpListener, Dispose(...))
dispose : (fn(self: Self) -> unit)

Returns: unit

TcpStream object
TcpStream

A connected TCP stream for bidirectional data transfer.

Fields

NameTypeDescription
_fdi32
_peer_addrSocketAddr
_is_closedbool

Trait Implementations

impl(TcpStream, ...)
connect : (TcpStream) fn(addr : SocketAddr, using(io : IO)) -> Impl(Future(TcpStream, IO, Exception))

Connect to a remote address, returning a new TcpStream.

Parameters

NameTypeNotes
addrSocketAddr

Returns: Impl(Future(TcpStream, IO, Exception))

read : (TcpStream) fn(self : TcpStream, buf : *(u8), size : usize, using(io : IO)) -> Impl(Future(i32, IO, Exception))

Read bytes from the stream into buf. Returns the number of bytes read, or 0 if the peer closed the connection.

Parameters

NameTypeNotes
selfTcpStream
buf*(u8)
sizeusize

Returns: Impl(Future(i32, IO, Exception))

write_str : (TcpStream) fn(self : TcpStream, data : str, using(io : IO)) -> Impl(Future(i32, IO, Exception))

Write a str to the stream. Returns the number of bytes written.

Parameters

NameTypeNotes
selfTcpStream
datastr

Returns: Impl(Future(i32, IO, Exception))

write_string : (TcpStream) fn(self : TcpStream, data : String, using(io : IO)) -> Impl(Future(i32, IO, Exception))

Write a String to the stream. Returns the number of bytes written.

Parameters

NameTypeNotes
selfTcpStream
dataString

Returns: Impl(Future(i32, IO, Exception))

write_bytes : (TcpStream) fn(self : TcpStream, data : ArrayList(u8), using(io : IO)) -> Impl(Future(i32, IO, Exception))

Write raw bytes from an ArrayList(u8) to the stream. Returns the number of bytes written.

Parameters

NameTypeNotes
selfTcpStream
dataArrayList(u8)

Returns: Impl(Future(i32, IO, Exception))

read_bytes : (TcpStream) fn(self : TcpStream, using(io : IO)) -> Impl(Future(ArrayList(u8), IO, Exception))

Read all available data from the stream into a byte list.

Parameters

NameTypeNotes
selfTcpStream

Returns: Impl(Future(ArrayList(u8), IO, Exception))

shutdown : (TcpStream) fn(self : TcpStream, how : i32, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Shut down part or all of the connection. how: 0 = read, 1 = write, 2 = both.

Parameters

NameTypeNotes
selfTcpStream
howi32

Returns: Impl(Future(unit, IO, Exception))

close : (TcpStream) fn(self : TcpStream, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Close the stream.

Parameters

NameTypeNotes
selfTcpStream

Returns: Impl(Future(unit, IO, Exception))

peer_addr : (TcpStream) fn(self : TcpStream) -> SocketAddr

Get the remote peer's socket address.

Parameters

NameTypeNotes
selfTcpStream

Returns: SocketAddr

fd : (TcpStream) fn(self : TcpStream) -> i32

Get the underlying file descriptor.

Parameters

NameTypeNotes
selfTcpStream

Returns: i32

set_nodelay : (TcpStream) fn(self : TcpStream, nodelay : bool, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Enable or disable TCP_NODELAY (disables Nagle's algorithm).

Parameters

NameTypeNotes
selfTcpStream
nodelaybool

Returns: Impl(Future(unit, IO, Exception))

set_keepalive : (TcpStream) fn(self : TcpStream, enabled : bool, using(io : IO)) -> Impl(Future(unit, IO, Exception))

Enable or disable SO_KEEPALIVE on the socket.

Parameters

NameTypeNotes
selfTcpStream
enabledbool

Returns: Impl(Future(unit, IO, Exception))

impl(TcpStream, Dispose(...))
dispose : (fn(self: Self) -> unit)

Returns: unit