OxL Reference

method TcpListener.accept

Waits for the next connection. timeout bounds the wait.

Example:

oxl✓ checked in CI
use std.net { SocketAddr, TcpListener, TcpStream }

fn main() -> () | ParseError  io, net {
  let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")!)
  match l {
    TcpListener ok => {
      match ok.accept(50ms) {
        TcpStream s => {
          print("connected")
          _ = s.close()
        }
        Timeout _ => print("nobody connected")
        NetError _ => print("error")
      }
      _ = ok.close()
    }
    NetError _ => print("cannot bind")
  }
}
Output
nobody connected
pub(api) fn accept(timeout: Duration? = none) -> TcpStream | NetError  net

Since. 1.0.0-beta

Parameters

NameType
timeoutDuration? = none

Returns

TcpStream

Errors

  • NetError
  • `Timeout` when no connection arrives in time; `Cancelled`; `Unavailable`.

Effects

net

Defined in: std/net/net.oxl:413

See also