OxL Справочник OxL
РусскийEnglish

method TcpListener.accept

Waits for the next connection. timeout bounds the wait.

Example:

oxl✓ проверяется в 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")
  }
}
Вывод
nobody connected
pub(api) fn accept(timeout: Duration? = none) -> TcpStream | NetError  net

С версии. 1.0.0-beta

Параметры

ИмяТип
timeoutDuration? = none

Возвращает

TcpStream

Ошибки

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

Эффекты

net

Определено в: std/net/net.oxl:413

См. также