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

module std.net

std.net — low-level networking (II.1): TCP, IP addresses, DNS. Every operation has the effect net.

A blocking call suspends only the calling task. All calls that wait take an optional timeout (Timeout is returned when it passes) and are cancellation points: a cancelled task, or one whose chain deadline passed, unwinds from them (§8.6; inside shield the call completes first). Errors are NetError values (§6.5, D-2203): Timeout, Unavailable (refused, reset, unreachable, address in use, name not found, resource limits), AccessDenied, Cancelled (an OS-level cancellation) and ProtocolError (everything else, msg has the OS text). Intrinsics: compiler/src/codegen/CGNet.cpp over runtime/src/net (D-2200..D-2299).

Example:

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

fn main() -> () | NetError | ParseError  io, net {
  let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")?)?
  defer l.close()?
  let c = TcpStream.connect(l.local, 2s)?
  defer c.close()?
  let s = l.accept(3s)?
  defer s.close()?
  c.writeText("ping")?
  print(s.readText(16)?)
}
Вывод
ping

std.net — TLS 1.2 / 1.3 over TCP (II.1 Tls, [С §13.1], requirement Р6). Part of module std.net; every operation that touches the network or loads certificates has the effect net.

TlsStream is a TcpStream plus a TLS session: all I/O still parks only the calling task and honours timeout, cancellation and chain deadlines exactly like TcpStream (D-2200..D-2203). TlsStream.connect / connectHost verify the server certificate against the system roots or TlsConfig.ca and check the host name; TlsListener accepts and runs the server side of the handshake. The crypto is OpenSSL (or AWS-LC, OXL_TLS_BACKEND), see runtime/src/net/tls.h.

Errors (D-2403): the standard NetError union is kept. Timeout, Unavailable (also: the peer ended the connection without close_notify), AccessDenied and Cancelled are those of D-2203; every TLS failure — handshake, certificate verification, host name or pin mismatch, fatal alert, unusable configuration or key — is a ProtocolError whose msg starts with a stable prefix: tls handshake:, tls certificate:, tls hostname:, tls pin:, tls alert: or tls:. Intrinsics: compiler/src/codegen/CGTls.cpp over runtime/src/net/tls_abi.cpp.

Типы

enum ClientAuthWhether a server asks its clients for a certificate (mutual TLS).
data dnsNamespace of name resolution functions.
data IpAddrIPv4 or IPv6 address, kept in canonical text form (::0:1 is ::1).
data SocketAddrIP address and port.
data TcpListenerA listening TCP socket.
data TcpStreamA connected TCP stream.
data TlsConfigTLS options for both roles; only the fields that apply to the role are used.
data TlsListenerA listening TLS socket
data TlsStreamA TLS session over a connected TCP socket.

См. также