method TcpListener.accept
Waits for the next connection. timeout bounds the wait.
Example:
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 netSince. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
timeout | Duration? = none |
Returns
Errors
NetError- `Timeout` when no connection arrives in time; `Cancelled`; `Unavailable`.
Effects
net
Defined in: std/net/net.oxl:413