OxL Reference

data TlsListener

A listening TLS socket: accept takes a TCP connection and runs the server handshake.

Example:

oxl✓ checked in CI
use std.net { TlsListener, TlsConfig, SocketAddr }

fn serve(addr: SocketAddr) -> () | NetError  io, net {
  let l = TlsListener.bind(addr, TlsConfig{ cert: "server.pem", key: "server.key" })?
  defer l.close()?
  let s = l.accept()?
  defer s.close()?
  s.writeText("hello\n")?
}
@must_close
pub(api) data TlsListener

Thread safety. `accept` may be called by one task at a time.

Since. 1.0.0-beta

Fields

pub(api) local: SocketAddr

The address the socket listens on.

Methods

bind(addr: SocketAddr, cfg: TlsConfig, backlog: i64) -> TlsListener | NetError net
Binds, listens and loads the certificate from cfg (port 0 picks a free port
accept(timeout: Duration?) -> TlsStream | NetError net
Waits for the next connection and completes its TLS handshake.
acceptTcp(timeout: Duration?) -> TcpStream | NetError net
Accepts the next TCP connection without TLS; finish it with handshake.
handshake(tcp: TcpStream, timeout: Duration?) -> TlsStream | NetError net
Runs the server handshake on a connection from acceptTcp (which it consumes).
close() -> () | NetError net
Closes the listening socket.

Defined in: std/net/tls.oxl:469

See also