• Effekt Logo 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
      Example usage: examples/stdlib/io/network
      • Connection
      • 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.
      • read (handle: Connection, buffer: ByteArray, offset: Int, size: Int): Int / {Exception[IOError]}
      • 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`).
      • write (handle: Connection, buffer: ByteArray, offset: Int, size: Int): Int / {Exception[IOError]}
      • 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`).
      • Address
      • An IP address (v4 or v6) resolved by the system from a previously given host.
      • toString (address: Address): String / {}
      • The text of the given `address`, such as `127.0.0.1` or `::1`.
      • resolve (host: String): List[Address] / {Exception[IOError]}
      • 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.
      • connect (address: Address, port: Int): Connection / {Exception[IOError]}
      • Establishes a TCP connection to the given `address` and port.
      • connect (host: String, port: Int): Connection / {Exception[IOError]}
      • 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).
      • close (handle: Connection): Unit / {}
      • Closes a TCP connection and releases associated resources.
      • Listener
      • 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.
      • bind (address: Address, port: Int): Listener / {Exception[IOError]}
      • 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.
      • bind (host: String, port: Int): Listener / {Exception[IOError]}
      • 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).
      • port (listener: Listener): Int / {Exception[IOError]}
      • The port which the given `listener` is bound to.
        Raises `EBADF` if the listener was shut down.
      • listen (listener: Listener, handler: (Connection) => Unit at {io,async,global}): Unit / {Exception[IOError]}
      • 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`.
      • shutdown (listener: Listener): Unit / {}
      • Stops a TCP listener and releases associated resources.
      • streaming [R] (connection: Connection) { program: => R / {next[ByteArray], emit[ByteArray]} }: R / {Exception[IOError]}
      • 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.
      • internal
        • addresses (resolution: Int): Unit / {emit[Address]}
        • The addresses of a `resolution`, in order.
        • eachAddress [R] (addresses: List[Address]) { attempt: (Address) => R / {Exception[IOError]} }: R / {Exception[IOError]}
        • Runs `attempt` on each of the `addresses` of a host in turn until one succeeds,
          and otherwise raises the error of the last attempt.
        • resolve (host: String): Int / {}
        • addressCount (resolution: Int): Int / {}
        • The number of addresses in a `resolution`, and each of them by its index, as for `args`.
        • 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 / {}
        • The connection whose handle `connect` returned, or which `listen` passed to its handler.
        • listener (handle: Int): Listener / {}
        • The listener whose handle `bind` returned.