-
Effekt Library
- io/network
- Connection
- read
- write
- Address
- toString
- resolve
- connect
- connect
- close
- Listener
- bind
- bind
- port
- listen
- shutdown
- streaming
- internal
- addresses
- eachAddress
- resolve
- addressCount
- addressAt
- release
- connect
- read
- write
- close
- bind
- port
- listen
- shutdown
- connection
- listener
- io/network Jump to source: libraries/common/io/network.effekt
- Connection
- read
(handle: Connection, buffer: ByteArray, offset: Int, size: Int): Int / {Exception[IOError]} - write
(handle: Connection, buffer: ByteArray, offset: Int, size: Int): Int / {Exception[IOError]} - Address
- toString
(address: Address): String / {} - resolve
(host: String): List[Address] / {Exception[IOError]} - connect
(address: Address, port: Int): Connection / {Exception[IOError]} - connect
(host: String, port: Int): Connection / {Exception[IOError]} - close
(handle: Connection): Unit / {} - Listener
- bind
(address: Address, port: Int): Listener / {Exception[IOError]} - bind
(host: String, port: Int): Listener / {Exception[IOError]} - port
(listener: Listener): Int / {Exception[IOError]} - listen
(listener: Listener, handler: (Connection) => Unit at {io,async,global}): Unit / {Exception[IOError]} - shutdown
(listener: Listener): Unit / {} - streaming
[R] (connection: Connection) { program: => R / {next[ByteArray], emit[ByteArray]} }: R / {Exception[IOError]} - internal
- addresses
(resolution: Int): Unit / {emit[Address]} - eachAddress
[R] (addresses: List[Address]) { attempt: (Address) => R / {Exception[IOError]} }: R / {Exception[IOError]} - resolve
(host: String): Int / {} - addressCount
(resolution: Int): Int / {} - addressAt
(resolution: Int, index: Int): Address / {} - release
(resolution: Int): Unit / {} - connect
(address: Address, port: Int): Int / {} - read
(handle: Connection, buffer: ByteArray, offset: Int, size: Int): Int / {} - write
(handle: Connection, buffer: ByteArray, offset: Int, size: Int): Int / {} - close
(handle: Connection): Unit / {} - bind
(address: Address, port: Int): Int / {} - port
(listener: Listener): Int / {} - listen
(listener: Listener, handler: (Connection) => Unit at {io,async,global}): Int / {} - shutdown
(handle: Listener): Unit / {} - connection
(handle: Int): Connection / {} - listener
(handle: Int): Listener / {}
Example usage: examples/stdlib/io/network
A TCP connection, either open or closed. Reading from or writing to a closed connection raises `EBADF`, but closing it again does nothing. Closing is explicit.
Reads up to `size` bytes from a TCP connection into `buffer`, starting at `offset`. Returns as soon as at least one byte is available, so the result may be smaller than `size`. Returns 0 once the peer has closed the connection (end of file), and every subsequent call returns 0 too. At most one read can be pending on a connection: another one raises `EALREADY`. Raises `EBADF` if the connection is closed. Panics unless: - `size` is positive (a read of nothing would look like end of file), and - `[offset, offset + size)` is a valid range inside `buffer` (like `bytearray::copy`).
Writes `size` bytes from `buffer`, starting at `offset`, to a TCP connection. Returns once all bytes are written, and returns `size`. Raises `EBADF` if the connection is closed. Panics unless `[offset, offset + size)` is a valid range inside `buffer` (like `bytearray::copy`).
An IP address (v4 or v6) resolved by the system from a previously given host.
The text of the given `address`, such as `127.0.0.1` or `::1`.
Resolves the given `host`, a name or an IPv4 or IPv6 address, to its addresses, in the order which the system prefers. Raises the error of the resolver, such as `EAI_NONAME`, if it has none.
Establishes a TCP connection to the given `address` and port.
Establishes a TCP connection to the given `host` and port, trying the addresses of the host in turn until one accepts (o/w raising the error of the last one).
Closes a TCP connection and releases associated resources.
A TCP listener, either listening or shut down. Listening on a listener that was shut down raises `EBADF`, but shutting it down again does nothing.
Creates a TCP listener bound to the given `address` and port, reserving it (o/w raising `EADDRINUSE`). Port 0 asks the system for a free port, which `port` then returns.
Creates a TCP listener bound to the given `host` and port, trying the addresses of the host in turn until one can be bound (o/w raising the error of the last one).
The port which the given `listener` is bound to. Raises `EBADF` if the listener was shut down.
Starts listening for incoming connections and handles each with the given `handler`, including those which arrived since `bind`. Returns only once `shutdown` is called on this `Listener`, so it is usually run with `spawn`.
Stops a TCP listener and releases associated resources.
Runs `program` with `emit` writing to the connection and `next` reading from it. `next` returns the bytes read so far (at most 4096) and performs `stop` at end of file, so a loop over `next` ends when the peer closes the connection.
The addresses of a `resolution`, in order.
Runs `attempt` on each of the `addresses` of a host in turn until one succeeds, and otherwise raises the error of the last attempt.
The number of addresses in a `resolution`, and each of them by its index, as for `args`.
The connection whose handle `connect` returned, or which `listen` passed to its handler.
The listener whose handle `bind` returned.