API Reference
This page is the canonical home for Reseau's public package, TCP, and TLS docstrings.
Package Modules
Reseau.TCP — Module
TCPCore TCP socket operations and connection/listener types.
This layer sits directly above SocketOps and IOPoll. It is responsible for turning raw non-blocking sockets into higher-level connection/listener objects, including:
- sockets are created non-blocking and registered with the poller
- non-blocking connect completes by waiting for write readiness and then reading
SO_ERROR - accept returns already-initialized child descriptors that are ready for the same poll-driven read/write paths as outbound connections
- deadline expiry is surfaced as
TCP.DeadlineExceededErrorfor transport I/O
Reseau.Unix — Module
UnixFilesystem Unix-domain stream clients on Linux, macOS and FreeBSD.
Use Reseau.Unix.connect(path) to open a poll-driven IO connection. Reads, writes, half-close and deadlines follow the same stream contracts as TCP. The client owns its descriptor and never removes the server's socket path.
Reseau.UDP — Module
UDPCore UDP socket operations and the datagram connection type.
This layer sits directly above SocketOps, IOPoll, and NetCommon, and mirrors Go's net.UDPConn:
- one
Conntype serves both unconnected (bound) and connected sockets listenbinds a socket forsendto/recvfrom-style use;connectfixes a peer sosend/recvapply and ICMP errors surface asSystemErrors- a datagram is sent and received whole: there are no partial transfers, a zero-byte datagram is valid data rather than EOF, and
Connis deliberately not anIO(stream helpers likereadlinewould corrupt datagram boundaries) - deadline expiry is surfaced as
UDP.DeadlineExceededError, with the same sticky per-socket deadline model asTCP
Reseau.TLS — Module
TLSTLS client/server layer built on native TLS 1.2/1.3 machinery, OpenSSL-backed crypto/X.509 helpers, and TCP connections.
This layer provides:
- reusable
Configobjects for client and server policy Connwrappers that can handshake eagerly or lazily on first I/O- deadline handling delegated to the wrapped transport so TLS retries follow the same timeout model as plain TCP
- transport timeout handling is available as
TLS.DeadlineExceededError
TCP
Address Types and Constructors
Reseau.NetCommon.SocketAddr — Type
SocketAddrAbstract network endpoint type for socket addresses.
Reseau.NetCommon.SocketAddrV4 — Type
SocketAddrV4IPv4 endpoint snapshot.
The address bytes are stored in presentation order and the port is stored in host byte order. Conversion to platform sockaddr structs happens lazily when a socket operation actually needs one.
Reseau.NetCommon.SocketAddrV6 — Type
SocketAddrV6IPv6 endpoint snapshot.
scope_id is used for scoped link-local addresses and is preserved all the way down to the platform sockaddr representation so bind/connect can target the same interface the caller selected.
Reseau.NetCommon.loopback_addr — Function
loopback_addr(port) -> SocketAddrV4Convenience constructor for 127.0.0.1:port.
Reseau.NetCommon.any_addr — Function
any_addr(port) -> SocketAddrV4Convenience constructor for 0.0.0.0:port, typically used for wildcard binds.
Reseau.NetCommon.loopback_addr6 — Function
loopback_addr6(port; scope_id=0) -> SocketAddrV6Convenience constructor for [::1]:port.
Reseau.NetCommon.any_addr6 — Function
any_addr6(port; scope_id=0) -> SocketAddrV6Convenience constructor for the IPv6 wildcard bind address [::]:port.
Connections and I/O
Reseau.TCP.Conn — Type
ConnUser-facing connected TCP stream.
Reads and writes are forwarded to IOPoll, which means blocking operations are actually readiness waits against the shared low-level poller rather than thread-per-socket blocking syscalls. Because Conn <: IO, standard Base stream helpers like read, read!, readbytes!, eof, and write apply directly.
Reseau.TCP.Listener — Type
ListenerUser-facing passive TCP listener.
Accepted children are returned as Conn values whose underlying sockets are already non-blocking, poll-registered, and configured with the default TCP options Reseau wants.
Reseau.TCP.connect — Function
connectConnect a TCP client using either a concrete SocketAddr or a string-address overload added later in the file load order.
Reseau.TCP.listen — Function
listenCreate a TCP listener from either a concrete SocketAddr or a string-address overload added later in the file load order.
Reseau.TCP.accept — Function
acceptAccept one inbound Conn from a TCP.Listener.
Base.read! — Method
read!(conn, buf) -> bufRead exactly length(buf) bytes into buf or throw EOFError.
Because Conn <: IO, Base's generic read! implementation already supports mutable byte views like @view bytes[2:5] in addition to plain vectors.
Use readbytes! or readavailable when you want a count-returning read that may stop early.
Base.readbytes! — Method
readbytes!(conn, buf, nb=length(buf); all::Bool=true) -> IntRead up to nb bytes into buf, returning the byte count.
Unlike read!(conn, buf), this API may return after a short read or EOF. It is the count-returning read entrypoint for a plain socket stream.
If all is true (the default), the call keeps reading until nb bytes have been transferred, EOF is reached, or an error occurs. If all is false, at most one underlying socket read is performed.
Resizable Vector{UInt8} buffers grow when needed, matching Julia's standard readbytes! behavior. Fixed-size contiguous byte views must satisfy nb <= length(buf).
Base.readavailable — Method
readavailable(conn) -> Vector{UInt8}Read and return the bytes that are currently ready without requiring a full-buffer exact read.
Reseau.NetCommon.tryread! — Function
tryread!(conn, buf) -> Union{Int, Nothing}Copy currently available bytes into a nonempty contiguous mutable byte buffer. Return the byte count, 0 at EOF (including a locally closed connection), or nothing if no bytes are ready or another reader owns the connection. Never wait for network input or for the read lock. A short read is not EOF.
Read deadlines and transport errors apply as for ordinary reads. The caller owns the returned bytes; subsequent reads continue after them. Use read! or readbytes! when waiting for input is intended.
Base.isopen — Method
isopen(conn) -> BoolReturn true while conn still owns an open socket.
Base.isopen — Method
isopen(listener) -> BoolReturn true while listener still owns an open listening socket.
Base.write — Method
write(conn, buf) -> IntWrite all bytes from buf and return the number of bytes written.
On success, the return value is always length(buf). If the socket cannot currently accept data, the call waits for write readiness and resumes until the entire buffer has been written or an error/deadline interrupts the operation.
Base.close — Method
close(conn)Close the connection. Repeated closes are treated as no-ops.
Base.close — Method
close(listener)Close the listening socket. Repeated closes are treated as no-ops.
Reseau.TCP.NetClosingError — Type
NetClosingErrorRaised when a TCP operation encounters a locally closed connection or listener, including a pending operation woken by close from another task.
Catch TCP.NetClosingError during deliberate connection or listener shutdown. This aliases the underlying poller exception without requiring callers to use Reseau.IOPoll. Peer EOF and deadline expiry have separate error behavior.
Reseau.NetCommon.closeread — Function
closeread(conn)Shut down the read side of the connection.
Base.closewrite — Method
closewrite(conn)Shut down the write side of the connection.
Deadlines, Socket Options, and Address Inspection
Reseau.NetCommon.set_deadline! — Function
set_deadline!(conn, deadline_ns)Set both the read and write deadline of conn to deadline_ns, an absolute timestamp on the time_ns() clock. 0 clears them.
Once a deadline passes, pending and later reads and writes throw DeadlineExceededError, even when data is ready, until the deadline is cleared or moved. A deadline at or before time_ns() applies immediately.
set_deadline!(listener, deadline_ns)Set the accept deadline on listener.
deadline_nsuses the same absolute monotonictime_ns()clock as connection deadlines.deadline_ns == 0disables accept timeouts.deadline_ns <= time_ns()causes the next blockingacceptto time out immediately.
This affects accept(listener) only.
Reseau.NetCommon.set_read_deadline! — Function
set_read_deadline!(conn, deadline_ns)Set the read deadline of conn (absolute, time_ns() clock; 0 clears it). Once it passes, pending and later reads, including tryread! and eof, throw DeadlineExceededError even when data is ready, until the deadline is cleared or moved.
Reseau.NetCommon.set_write_deadline! — Function
set_write_deadline!(conn, deadline_ns)Set the write deadline of conn (absolute, time_ns() clock; 0 clears it). Once it passes, pending and later writes throw DeadlineExceededError, even when the socket could accept data, until the deadline is cleared or moved.
Reseau.TCP.DeadlineExceededError — Type
DeadlineExceededErrorRaised when blocking TCP I/O or accept(listener) exceeds the active deadline.
Catch TCP.DeadlineExceededError when a deadline set by set_deadline!, set_read_deadline!, or set_write_deadline! expires. This aliases the underlying poller timeout type so downstream code does not need to depend on Reseau.IOPoll directly.
Reseau.TCP.set_nodelay! — Function
set_nodelay!(conn, enabled=true)Enable or disable TCP_NODELAY on conn.
Reseau.TCP.set_keepalive! — Function
set_keepalive!(conn, enabled=true; idle_secs=nothing, interval_secs=nothing, count=nothing)Enable or disable SO_KEEPALIVE on conn, optionally tuning the probe schedule (the shape of Go's KeepAliveConfig):
idle_secs: idle time before the first probe (TCP_KEEPIDLE;TCP_KEEPALIVEon Darwin)interval_secs: time between unanswered probes (TCP_KEEPINTVL)count: unanswered probes before the connection is dropped (TCP_KEEPCNT)
Tuning values are applied only when provided. Platforms without a given knob surface the kernel's SystemError (notably OpenBSD, and Windows releases before Server 2016 / Windows 10 1709).
Reseau.TCP.set_quickack! — Function
set_quickack!(conn, enabled=true)Toggle TCP_QUICKACK (Linux). On other platforms this is a silent no-op, matching Sockets.quickack, so cross-platform callers can set it unconditionally. The kernel may clear the flag again after some transfers; latency-sensitive callers re-assert it as needed.
Reseau.TCP.set_linger! — Function
set_linger!(conn, timeout_secs)Configure SO_LINGER, following Go's SetLinger: a negative timeout disables lingering (close returns immediately and the OS flushes in the background — the default), 0 discards unsent data on close with a RST, and a positive timeout asks the OS to keep sending in the background. On some systems, including Linux, a positive timeout may block close until data is sent or discarded. Remaining data may be discarded after the timeout on some systems. Nonnegative timeouts must not exceed 65535 seconds.
Reseau.TCP.set_read_buffer! — Function
set_read_buffer!(conn, nbytes)Set the kernel receive buffer size (SO_RCVBUF). The kernel may round the value, enforce minimums, or (on Linux) double it to leave bookkeeping room.
Reseau.TCP.set_write_buffer! — Function
set_write_buffer!(conn, nbytes)Set the kernel send buffer size (SO_SNDBUF). The kernel may round the value, enforce minimums, or (on Linux) double it to leave bookkeeping room.
Reseau.TCP.listenany — Function
listenany(hint::Integer; backlog=128, reuseaddr=true) -> (UInt16, Listener)
listenany(hint::SocketAddr; backlog=128, reuseaddr=true) -> (UInt16, Listener)Bind a listener on the first available port at or above hint's port, returning the bound port and the listener (the Sockets.listenany idiom). The integer form binds to the IPv4 loopback address.
Ports that are in use (EADDRINUSE) or forbidden (EACCES) are skipped by incrementing the port; running out of ports rethrows the last error. A hint port of 0 binds an ephemeral port directly.
reuseaddr follows listen semantics, including its Windows no-op: exclusive Windows binds are exactly what keeps EADDRINUSE (and therefore this availability probe) reliable there.
Reseau.NetCommon.rawfd — Function
rawfd(conn) -> RawFD or Base.WindowsRawSocketReturn the OS-level socket descriptor backing conn (a RawFD on POSIX, a Base.WindowsRawSocket on Windows) for FFI and interop.
Reseau retains ownership: the descriptor is non-blocking and registered with the internal poller; callers must not close it, change its flags, or use it after close(conn). The result is a borrowed snapshot. Keep conn reachable, for example with GC.@preserve, and prevent a concurrent close(conn) for the full external operation. Throws NetClosingError if the socket is already closing.
rawfd(listener) -> RawFD or Base.WindowsRawSocketListener variant of rawfd. The same ownership rules apply.
Reseau.TCP.local_addr — Function
local_addr(conn) -> Union{Nothing, SocketAddr}Return the cached local endpoint for conn, if known.
local_addr(listener) -> Union{Nothing, SocketAddr}Return the listener's bound local endpoint.
This is an alias for addr(listener).
Reseau.TCP.remote_addr — Function
remote_addr(conn) -> Union{Nothing, SocketAddr}Return the cached remote endpoint for conn, if known.
Reseau.TCP.addr — Function
addr(listener) -> Union{Nothing, SocketAddr}Return the listener's bound local endpoint, if known.
Unix Socket Clients
Reseau.Unix.Conn — Type
Conn <: IOA connected filesystem Unix-domain byte stream. Use connect to create one. close releases the descriptor, wakes pending operations, and leaves the server's filesystem path intact.
Reseau.Unix.connect — Function
connect(path::AbstractString; timeout_ns=0, deadline_ns=0) -> ConnConnect to a filesystem Unix-domain stream socket on Linux, macOS or FreeBSD. The path is used as given, including relative paths. Empty paths, embedded NUL and paths exceeding the platform's byte limit are rejected before opening a socket. Linux abstract names and Windows named pipes are not supported.
timeout_ns is a relative connect budget in nanoseconds. deadline_ns is an absolute monotonic timestamp on the time_ns() clock. Zero disables either limit; when both are set, the earlier deadline applies. Relative addition saturates at typemax(Int64). Negative budgets and elapsed deadlines fail with DeadlineExceededError. Both inputs must fit in Int64.
The connect deadline is cleared on success. Use set_read_deadline!, set_write_deadline! or set_deadline! for subsequent operations. Native connection failures throw SystemError with the original OS error code. Unsupported platforms throw ArgumentError without opening a descriptor.
Reseau.Unix.DeadlineExceededError — Type
DeadlineExceededErrorRaised when a Unix connect, read or write exceeds its active deadline.
Reseau.Unix.NetClosingError — Type
NetClosingErrorRaised when an operation encounters a locally closed Unix connection, including a pending operation woken by close from another task.
Unix connections use the shared stream IO, deadline, half-close and borrowed descriptor methods documented above. See Unix Socket Clients for path limits and lifecycle details.
UDP
Connections and Datagram I/O
Reseau.UDP.Conn — Type
ConnUser-facing UDP socket.
One type serves both modes, mirroring Go's net.UDPConn:
- an unconnected socket (from
listen) exchanges datagrams with any peer viasendtoandrecvfrom/recvfrom! - a connected socket (from
connect) has a fixed peer, usessendandrecv/recv!, and surfaces ICMP errors (e.g.ECONNREFUSED) on subsequent operations
recv-family calls work on both modes; send requires a connected socket and sendto an unconnected one. Conn is not an IO: datagrams are messages, not a byte stream.
Reseau.UDP.listen — Function
listenBind an unconnected UDP socket from a concrete SocketAddr or a string-address overload added later in the file load order.
Reseau.UDP.connect — Function
connectCreate a connected UDP socket from a concrete SocketAddr or a string-address overload added later in the file load order.
Reseau.UDP.send — Function
send(conn::Conn, data) -> NothingSend data as one datagram to the connected peer.
Throws ArgumentError if conn is unconnected (use sendto). data may be a byte vector or a string; an empty payload sends a valid empty datagram. Payloads are limited to the UDP maximum (65,507 bytes); oversized sends surface the kernel's EMSGSIZE as a SystemError and leave the socket usable.
Reseau.UDP.sendto — Function
sendto(conn::Conn, data, addr::SocketAddr) -> NothingSend data as one datagram to addr on an unconnected socket.
Throws ArgumentError if conn is connected (Go's ErrWriteToConnected semantics; use send) or if addr's family does not match the socket's.
Reseau.UDP.recv — Function
recv(conn::Conn; maxsize=65535) -> Vector{UInt8}Receive one datagram, allocating a right-sized result vector and discarding the sender address. See recvfrom for maxsize semantics.
Reseau.UDP.recv! — Function
recv!(conn::Conn, buf; allow_truncate=false) -> IntReceive one datagram into buf and return the byte count, discarding the sender address. Works on connected and unconnected sockets alike; truncation behaves as in recvfrom!.
Reseau.UDP.recvfrom — Function
recvfrom(conn::Conn; maxsize=65535) -> (data::Vector{UInt8}, addr)Receive one datagram, allocating a right-sized result vector.
The default maxsize holds any UDP datagram, so the default call never truncates. A smaller maxsize throws TruncatedDatagramError for longer datagrams.
Reseau.UDP.recvfrom! — Function
recvfrom!(conn::Conn, buf; allow_truncate=false) -> (nread, addr)Receive one datagram into buf, returning the byte count and the sender's address.
Blocks until a datagram arrives (or the read deadline expires). If the datagram is longer than buf, the excess is discarded by the kernel and, with allow_truncate=false (the default), a TruncatedDatagramError is thrown; with allow_truncate=true the truncated prefix is returned silently (Go semantics). A zero-byte result is a valid empty datagram, never EOF.
Reseau.UDP.TruncatedDatagramError — Type
TruncatedDatagramErrorRaised by recv!/recvfrom! (and the allocating forms with a small maxsize) when an incoming datagram was longer than the destination buffer and allow_truncate=false (the default). nread is the number of bytes that were delivered; the rest of the datagram is discarded by the kernel. The socket remains usable.
Deadlines, Socket Options, and Address Inspection
Reseau.UDP.DeadlineExceededError — Type
DeadlineExceededErrorRaised when blocking UDP I/O exceeds the active deadline.
Catch UDP.DeadlineExceededError when a deadline set by set_deadline!, set_read_deadline!, or set_write_deadline! expires. This aliases the underlying poller timeout type so downstream code does not need to depend on Reseau.IOPoll directly.
Reseau.UDP.set_deadline! — Function
set_deadline!(conn::Conn, deadline_ns::Integer)Set both the read and write deadline to the absolute monotonic timestamp deadline_ns (the time_ns() clock). 0 clears; a value <= time_ns() expires immediately, waking any parked operation with UDP.DeadlineExceededError.
Reseau.UDP.set_read_deadline! — Function
set_read_deadline!(conn::Conn, deadline_ns::Integer)Set the deadline for recv-family operations. See set_deadline!.
Reseau.UDP.set_write_deadline! — Function
set_write_deadline!(conn::Conn, deadline_ns::Integer)Set the deadline for send-family operations. See set_deadline!.
Reseau.UDP.set_broadcast! — Function
set_broadcast!(conn::Conn, enabled=true)Toggle SO_BROADCAST. Broadcast is enabled by default on every UDP socket (Go parity); use set_broadcast!(conn, false) to disable it.
Reseau.UDP.set_ttl! — Function
set_ttl!(conn::Conn, ttl::Integer)Set the unicast time-to-live (IPv4 IP_TTL) or hop limit (IPv6 IPV6_UNICAST_HOPS) for outgoing datagrams.
Reseau.UDP.set_read_buffer! — Function
set_read_buffer!(conn::Conn, nbytes::Integer)Set the kernel receive buffer size (SO_RCVBUF). Kernels may round the value (Linux doubles it). Datagrams that arrive while the buffer is full are dropped, so servers expecting bursts should raise this.
Reseau.UDP.set_write_buffer! — Function
set_write_buffer!(conn::Conn, nbytes::Integer)Set the kernel send buffer size (SO_SNDBUF). Kernels may round the value (Linux doubles it).
Reseau.UDP.local_addr — Function
local_addr(conn::Conn) -> Union{Nothing, SocketAddr}The socket's bound local address, cached at listen/connect time.
Reseau.UDP.remote_addr — Function
remote_addr(conn::Conn) -> Union{Nothing, SocketAddr}The connected peer address, or nothing for unconnected sockets.
TLS
Configuration, State, and Errors
Reseau.TLS.ClientAuthMode — Module
ClientAuthModeServer-side client certificate policy for native TLS handshakes.
The values intentionally mirror Go's client-auth policy surface: callers pick a policy up front in Config, then the TLS 1.2/1.3 server handshakes interpret that policy consistently when deciding whether to request, require, and verify client certificates.
Reseau.TLS.Config — Type
Config(; ...)
Config(cfg::Config; ...)Reusable TLS configuration for client and server sessions.
Keyword arguments:
server_name: hostname or IP literal used for certificate verification. For clients, this also drives SNI when it is a hostname. If omitted,connectwill try to derive it from the dial target.verify_peer: whether to validate the remote certificate chain against trusted roots.verify_hostname: whether to validate the remote peer name against the presented leaf certificate. This defaults toverify_peer, but can be enabled separately.client_auth: server-side client certificate policy.cert_file/key_file: PEM-encoded certificate chain and private key. Servers must provide both; clients may provide both for mutual TLS.key_passphrase: passphrase for an encryptedkey_file. It cannot contain null characters, and an unencrypted key ignores it. The key is loaded at the first handshake that needs it, not byConfigorlisten, so a server with a wrong or missing passphrase still listens and each handshake throwsTLSError. A client loads its key only when the server asks for a certificate.ca_file: CA bundle or CA directory used to verify remote servers.ca_dir: additional CA directory used together withca_file. Each explicit source must contain usable PEM certificates. If both are omitted, client verification usesNetworkOptions.ca_roots_path(). An explicit source replaces that default.client_ca_file/client_ca_dir: CA bundle or directory, and optional additional directory, used by servers to verify client certificates. At least one is required for server configs that verify presented client certs. Directory entries are read as PEM files; hashed filenames are accepted but are not required.alpn_protocols: ordered ALPN protocol preference list.curve_preferences: ordered native ECDHE group preferences for TLS 1.2/1.3. When empty, native handshakes default to[TLS.X25519, TLS.P256, TLS.P384, TLS.P521].handshake_timeout_ns: optional cap, in monotonic nanoseconds, applied only while the handshake is running. Existing transport deadlines still win if they are earlier.min_version/max_version: TLS protocol version bounds. Only TLS 1.2 and TLS 1.3 are supported;nothingleaves the bound unset.
Copy an existing config with Config(cfg::Config; kwargs...), passing only the settings above that should change. The copy shares cfg's session caches, session-ticket keys, and loaded local identity, so a per-connection copy that only sets server_name or handshake_timeout_ns keeps resuming sessions; changing cert_file, key_file, or key_passphrase gives the copy its own identity state. Use this instead of rebuilding a Config field by field: the private fields and their order are not part of the API. The copy keywords take exactly the field types (String rather than any AbstractString), which keeps a copy built from another config's fields resolvable under --trim.
Returns a reusable immutable Config.
Throws ConfigError if the keyword combination is internally inconsistent.
Reseau.TLS.ConnectionState — Type
ConnectionStateSnapshot of negotiated TLS connection state.
Fields:
handshake_complete: whether the TLS handshake has finished successfully.version: negotiated TLS protocol version string.alpn_protocol: negotiated ALPN protocol, ornothingif ALPN was not used.cipher_suite: negotiated cipher suite name, ornothingif it is not available.using_native_tls13: whether the connection is using the native TLS 1.3 path.did_resume: whether the connection resumed a previously cached TLS session.did_hello_retry_request: whether the handshake observed a TLS 1.3 HelloRetryRequest.has_resumable_session: whether this connection currently has a cached resumable native TLS session.curve: negotiated native TLS key share group name, ornothingif it is not available.
Reseau.TLS.Conn — Type
ConnTLS stream wrapper over one TCP.Conn.
Conn is safe for one concurrent reader and one concurrent writer. Handshake, read, and write all have separate locks so lazy handshakes and shutdown can coordinate cleanly across the native TLS state machine. Because Conn <: IO, standard Base stream helpers like read, read!, readbytes!, eof, and write apply directly to decrypted application data.
Reseau.TLS.Listener — Type
ListenerTLS listener wrapper over TCP.Listener.
Accepted connections are wrapped in server-side TLS state but are not handshaken until handshake! or the first read/write call.
Reseau.TLS.ConfigError — Type
ConfigErrorRaised when TLS configuration is invalid.
This is thrown before any network I/O starts, typically while normalizing a Config or preparing a TLS connection/listener.
Reseau.TLS.TLSError — Type
TLSErrorRaised when TLS handshake/read/write/close operations fail.
code is 0 for pure Julia-side failures and may be nonzero when the OpenSSL-backed primitive layer reports a backend error. cause preserves the underlying Julia-side exception when the failure originated in the transport/poller layer or a higher-level TLS check.
Reseau.TLS.TLSHandshakeTimeoutError — Type
TLSHandshakeTimeoutErrorRaised when handshake exceeds the configured timeout.
This is kept separate from TLSError because handshake timeouts are often configured and handled distinctly from generic TLS failures.
Reseau.TLS.DeadlineExceededError — Type
DeadlineExceededErrorAlias for the transport deadline timeout type used by TLS.
Catch TLS.DeadlineExceededError for direct listener accept timeouts and when inspecting TLSError.cause. Higher-level TLS operations may wrap deadline expiry in TLSError or TLSHandshakeTimeoutError so callers can keep operation-specific handling.
Client and Server Construction
Reseau.TLS.client — Function
client(tcp, config) -> ConnWrap an established TCP.Conn in client-side TLS state.
The handshake is deferred until handshake! or the first read/write operation.
Throws ConfigError or TLSError if the TLS state cannot be initialized.
Reseau.TLS.server — Function
server(tcp, config) -> ConnWrap an established TCP.Conn in server-side TLS state.
The handshake is deferred until handshake! or the first read/write operation.
Throws ConfigError or TLSError if the TLS state cannot be initialized.
Reseau.TLS.connect — Function
connect(remote_addr; kwargs...) -> Conn
connect(remote_addr, local_addr; kwargs...) -> ConnConnect to a concrete TCP.SocketAddr, negotiate TLS, and return a fully handshaken client connection.
This is the direct-address counterpart to the string-address connect(network, address; ...) overloads. The underlying socket setup is delegated to TCP.connect, after which the returned transport is wrapped in TLS and handshaken immediately.
TLS keyword arguments are forwarded to Config. If server_name is omitted, it is inferred from the concrete remote address when possible so peer verification and SNI can follow the same rules as the string-address client path.
connect(network, address; kwargs...) -> ConnConnect to address, negotiate TLS, and return a fully handshaken client connection.
Network-resolution keyword arguments are:
timeout_nsdeadline_nslocal_addrfallback_delay_nsresolverpolicy
TLS keyword arguments are forwarded to Config:
server_nameverify_peerclient_authcert_filekey_fileca_file/ca_dirclient_ca_file/client_ca_diralpn_protocolshandshake_timeout_nsmin_versionmax_version
If server_name is omitted, it is derived from address when possible so SNI and peer verification use the dial target's host name automatically.
connect(address; kwargs...) -> ConnConvenience shorthand for connect("tcp", address; kwargs...).
Reseau.TLS.listen — Function
listen(network, address, config; backlog=128, reuseaddr=true) -> ListenerCreate a TLS listener by first creating a TCP listener and then associating a server Config with accepted connections.
Accepted Conns are returned in lazy-handshake form.
Throws ConfigError if the server config is invalid and propagates any listener creation errors from TCP.listen.
listen(local_addr, config; backlog=128, reuseaddr=true) -> ListenerCreate a TLS listener from a concrete local TCP.SocketAddr.
This is the direct-address counterpart to listen(network, address, config; ...). The underlying TCP listener is created with TCP.listen, then accepted connections are wrapped in lazy-handshake TLS state.
Reseau.TLS.accept — Function
accept(listener) -> ConnAccept one inbound TCP connection and wrap it in server-side TLS state.
The returned Conn has not handshaken yet. If the listener deadline expires, accept(listener) throws DeadlineExceededError.
Reseau.TLS.handshake! — Function
handshake!(conn)Run the TLS handshake to completion if it has not already finished.
This method is idempotent. Concurrent callers serialize through handshake_lock, so only one task drives the native TLS state machine while the others observe the completed state afterward.
Returns nothing.
Throws:
TLSHandshakeTimeoutErrorwhenconfig.handshake_timeout_nsexpiresTLSErrorfor TLS or transport failuresEOFErrorif the peer closes cleanly during the handshakeInterruptExceptionif the waiting task is interrupted; later calls throw aTLSError
I/O, Lifecycle, Deadlines, and Inspection
Base.read! — Method
read!(conn, buf) -> bufRead exactly length(buf) decrypted bytes into buf or throw EOFError.
Because Conn <: IO, Base's generic read! implementation already supports mutable byte views like @view bytes[2:5] in addition to plain vectors.
Use readbytes! or readavailable when you want a count-returning read that may stop early.
Base.readbytes! — Method
readbytes!(conn, buf, nb=length(buf); all::Bool=true) -> IntRead up to nb decrypted bytes into buf, returning the byte count.
If all is true (the default), the call keeps reading until nb bytes have been transferred, EOF is reached, or an error occurs. If all is false, at most one underlying TLS read is performed.
Resizable Vector{UInt8} buffers grow when needed, matching Julia's standard readbytes! behavior. Fixed-size contiguous byte views must satisfy nb <= length(buf).
Base.readavailable — Method
readavailable(conn) -> Vector{UInt8}Read and return decrypted plaintext that is ready without requiring a full-buffer exact read.
Base.eof — Method
eof(conn) -> BoolWait until decrypted data is available or the stream has ended, and return true if it has ended: the peer sent close_notify, the transport reached EOF at a record boundary (as read treats it), or conn was closed locally, including while waiting. A record cut off by EOF throws TLSError.
Reseau.TLS.tryread! — Function
tryread!(conn, buf) -> Union{Int, Nothing}Copy available decrypted application bytes into a nonempty contiguous mutable byte buffer. Return a byte count, 0 at EOF (including local close), or nothing when no plaintext is returned in this attempt. An attempt processes at most 16 records; partial input and a busy read lock also return nothing. Call handshake! first. This operation does not wait for network input, acquire a busy read lock, or send TLS records.
Incomplete encrypted records remain buffered for the next tryread!, read, or eof. Complete records are authenticated before plaintext is returned. TLS 1.3 key-update replies are deferred until the next ordinary read or write, before further application output. Protocol and transport failures throw; read deadlines retain their ordinary meaning.
Base.isopen — Method
isopen(conn) -> BoolReturn true while both the TLS state and underlying TCP transport remain open.
Base.isopen — Method
isopen(listener) -> BoolReturn true while the wrapped TCP listener remains open.
Base.write — Method
write(conn, buf) -> Int
write(conn, buf, nbytes) -> IntWrite plaintext application bytes through the TLS connection.
write(conn, buf) attempts to write the entire buffer. The fixed-size byte-buffer overload allows callers to cap the write at nbytes.
Base.close — Method
close(conn)Close the TLS connection and the underlying TCP transport.
If the handshake completed and no write is in progress, this sends a TLS close_notify alert first, waiting at most 5 seconds for the transport to accept it. A task blocked reading conn does not prevent the alert; it wakes with a closed-connection error. The method is idempotent and returns nothing.
Base.close — Method
close(listener)Close the underlying TCP listener. Repeated closes are treated as no-ops.
Base.closewrite — Method
closewrite(conn)Send TLS shutdown on the write side and mark future writes as permanently failed.
This is the TLS analogue of half-closing a TCP socket. It requires the handshake to have completed because the TLS close-notify alert is itself a TLS record.
Returns nothing.
Throws TLSError if the TLS shutdown path fails.
Reseau.TLS.set_deadline! — Function
set_deadline!(conn, deadline_ns)Set both read and write deadlines on the underlying transport.
deadline_ns is interpreted using the same monotonic-clock convention as TCP and IOPoll: 0 clears the deadline, negative values mean the deadline has already expired, and positive values are absolute time_ns() values.
set_deadline!(listener, deadline_ns)Set the accept deadline on the underlying TCP listener.
This affects accept(listener) only. The returned Conn still uses its own connection and handshake deadlines afterward. Expired accept waits throw DeadlineExceededError.
Reseau.TLS.set_read_deadline! — Function
set_read_deadline!(conn, deadline_ns)Set the read deadline on the underlying transport. See set_deadline! for the timestamp convention.
Reseau.TLS.set_write_deadline! — Function
set_write_deadline!(conn, deadline_ns)Set the write deadline on the underlying transport. See set_deadline! for the timestamp convention.
Reseau.TLS.local_addr — Function
local_addr(conn)Return the local TCP.SocketAddr for the wrapped transport.
local_addr(listener)Return the local listening address for the wrapped TCP listener.
This is an alias for addr(listener).
Reseau.TLS.remote_addr — Function
remote_addr(conn)Return the remote TCP.SocketAddr for the wrapped transport.
Reseau.TLS.net_conn — Function
net_conn(conn) -> TCP.ConnExpose the underlying TCP connection.
Callers that need transport-level inspection can reach through the TLS wrapper without reconstructing the socket state.
Reseau.TLS.connection_state — Function
connection_state(conn) -> ConnectionStateReturn a snapshot of the currently negotiated TLS state.
This does not force a handshake; if the handshake has not yet run, the returned ConnectionState reports handshake_complete=false.
Reseau.TLS.addr — Function
addr(listener)Return the local listening address for the wrapped TCP listener.
Internal Support Layers
These modules power the public transport surface and are documented here for completeness, but they are not the primary public entrypoints.
Reseau.SocketOps — Module
SocketOpsCross-platform socket syscall facade and sockaddr helpers.
This module is intentionally lower level than TCP: it exposes thin wrappers around the OS socket APIs, normalizes the most important portability differences, and leaves policy decisions to higher layers.
A few conventions are worth keeping in mind when reading the code:
- successful mutating operations usually return
nothing - operations that need to preserve transient errno values often return the raw integer error code instead of throwing immediately
- wrappers aim to look POSIX-like even on Windows so the polling and transport layers can share most control flow
- address helpers always build or decode structs in network byte order so callers can treat the Julia-level tuples as ordinary host-order values
Reseau.IOPoll — Module
IOPollInternal readiness polling and deadline management for network descriptors.
IOPoll owns:
- one dedicated native poller thread plus the platform backend integration
- descriptor registration and readiness waiters
- read/write deadlines and poller-managed timers
- the low-level
FDwrapper used by higher transport layers
Higher layers call register!, prepareread, preparewrite, waitread, waitwrite, and timer helpers instead of interacting with backend-specific handles directly.
Reseau.IOPoll.PollMode — Module
PollModeBitmask enum used for read, write, and combined read/write readiness and deadline directions within IOPoll.
Reseau.NetCommon — Module
NetCommonShared socket-address types and the internal FD (netFD) owner used by the TCP, UDP and Unix transport layers.
This mirrors Go's net package structure, where one netFD and one set of sockaddr conversion helpers back every socket type. Public API surfaces live in the transport modules; TCP and UDP re-expose the address types here so the documented names (TCP.SocketAddrV4, ...) keep working unchanged.
Reseau.HostResolvers — Module
HostResolversAddress parsing, name resolution, and TCP string-address helpers.
This layer is the bridge between string-oriented user input like "example.com:443" and the lower-level TCP primitives that operate on concrete socket addresses. It is responsible for:
- parse and canonicalize host/port strings
- resolve hostnames according to a resolver policy
- attempt connections serially or in a Happy Eyeballs-style race
- wrap failures in an operation-specific error that preserves context
The public-facing string overloads for TCP.connect and TCP.listen are implemented here so users can stay on the TCP surface while the host/service resolution logic remains factored into its own file.
Reseau.SOCKS — Module
SOCKSInternal SOCKS5 (RFC 1928) client helpers layered on TCP.Conn, including username/password authentication (RFC 1929).
Reseau.SOCKS.BoundAddr — Type
BoundAddrSOCKS proxy bound address returned by a successful command reply.
Reseau.SOCKS.TargetAddressError — Type
TargetAddressErrorRaised when a SOCKS command target cannot be encoded.
Reseau.SOCKS.ProtocolError — Type
ProtocolErrorRaised when the SOCKS proxy sends malformed protocol bytes.
Reseau.SOCKS.AuthenticationError — Type
AuthenticationErrorRaised when SOCKS authentication negotiation fails.
Reseau.SOCKS.ReplyError — Type
ReplyErrorRaised when a SOCKS command reply has a non-success status.
Reseau.SOCKS.connect! — Function
connect!(conn, target_address; username=nothing, password=nothing, deadline_ns=0)Perform a SOCKS5 (RFC 1928) CONNECT handshake over conn and return the proxy bound address as a BoundAddr. On success, conn is the established stream to target_address, a "host:port" (or "[ipv6]:port") string.
When username is provided, username/password authentication (RFC 1929) is offered alongside no-auth and performed if the proxy selects it. username must be 1-255 bytes, password at most 255 bytes, and a password without a username is rejected.
A nonzero deadline_ns (absolute monotonic nanoseconds on the time_ns() clock) sets the read and write deadlines on conn for the duration of the handshake and clears them on exit, overwriting any deadlines previously set on conn. With deadline_ns == 0, existing deadlines are left untouched.
Target and credential validation failures (TargetAddressError, AuthenticationError) are thrown before any proxy I/O. During the handshake, AuthenticationError, ReplyError, ProtocolError, EOFError, or TCP.DeadlineExceededError may be thrown; after any error the proxy stream state is indeterminate and conn should be closed.
Docstring Index
Reseau.HostResolversReseau.IOPollReseau.NetCommonReseau.SOCKSReseau.SocketOpsReseau.TCPReseau.TLSReseau.UDPReseau.UnixReseau.TCP.ConnReseau.TCP.DeadlineExceededErrorReseau.TCP.ListenerReseau.TCP.NetClosingErrorReseau.TCP.acceptReseau.TCP.addrReseau.TCP.connectReseau.TCP.listenReseau.TCP.listenanyReseau.TCP.local_addrReseau.TCP.remote_addrReseau.TCP.set_keepalive!Reseau.TCP.set_linger!Reseau.TCP.set_nodelay!Reseau.TCP.set_quickack!Reseau.TCP.set_read_buffer!Reseau.TCP.set_write_buffer!Reseau.TLS.ClientAuthModeReseau.TLS.ConfigReseau.TLS.ConfigErrorReseau.TLS.ConnReseau.TLS.ConnectionStateReseau.TLS.DeadlineExceededErrorReseau.TLS.ListenerReseau.TLS.TLSErrorReseau.TLS.TLSHandshakeTimeoutErrorReseau.TLS.acceptReseau.TLS.addrReseau.TLS.clientReseau.TLS.connectReseau.TLS.connection_stateReseau.TLS.handshake!Reseau.TLS.listenReseau.TLS.local_addrReseau.TLS.net_connReseau.TLS.remote_addrReseau.TLS.serverReseau.TLS.set_deadline!Reseau.TLS.set_read_deadline!Reseau.TLS.set_write_deadline!Reseau.TLS.tryread!