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

method TcpListener.bind

Binds and listens (SO_REUSEADDR is set). Port 0 picks a free port: read it back from the field local.

Example:

oxl✓ проверяется в CI
use std.net { SocketAddr, TcpListener }

fn main() -> () | ParseError  io, net {
  let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")?)
  match l {
    TcpListener ok => {
      print("bound")
      _ = ok.close()
    }
    NetError _ => print("cannot bind")
  }
}
Вывод
bound
pub(api) static fn bind(addr: SocketAddr, backlog: i64 = 1024) -> TcpListener | NetError  net

С версии. 1.0.0-beta

Параметры

ИмяТип
addrSocketAddr
backlogi64 = 1024

Возвращает

TcpListener

Ошибки

  • NetError
  • `Unavailable` (address in use, no resources), `AccessDenied` (privileged port), `ProtocolError`.

Эффекты

net

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

См. также