amber/conn

Types

pub type Conn

Values

pub fn close(conn: Conn) -> Result(Nil, error.Error)

Closes the connection, freeing the resource.

pub fn close_write(
  conn: Conn,
) -> promise.Promise(Result(Nil, error.Error))

Shuts down (shutdown(2)) the write side of the connection. Most callers should just use close().

pub fn local_addr(of conn: Conn) -> net_addr.NetAddr

The local address of the connection.

pub fn read(
  conn: Conn,
  into p: uint8_array.Uint8Array,
) -> promise.Promise(Result(option.Option(Int), error.Error))

Read the incoming data from the connection into an array buffer (p).

Resolves to either the number of bytes read during the operation or EOF (None) if there was nothing more to read.

It is possible for a read to successfully return with 0 bytes. This does not indicate EOF.

It is not guaranteed that the full buffer will be read in a single call.

pub fn ref(conn: Conn) -> Nil

Make the connection block the event loop from finishing.

pub fn remote_addr(of conn: Conn) -> net_addr.NetAddr

The remote address of the connection.

pub fn unref(conn: Conn) -> Nil

Make the connection not block the event loop from finishing.

pub fn write(
  conn: Conn,
  from p: uint8_array.Uint8Array,
) -> promise.Promise(Result(Int, error.Error))

Write the contents of the array buffer (p) to the connection.

Resolves to the number of bytes written.

It is not guaranteed that the full buffer will be written in a single call.

Search Document