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.TLS — Module
TLSTLS client/server layer built on OpenSSL 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.TCP.SocketAddr — Type
SocketAddrAbstract network endpoint type for TCP socket addresses.
Reseau.TCP.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.TCP.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.TCP.loopback_addr — Function
loopback_addr(port) -> SocketAddrV4Convenience constructor for 127.0.0.1:port.
Reseau.TCP.any_addr — Function
any_addr(port) -> SocketAddrV4Convenience constructor for 0.0.0.0:port, typically used for wildcard binds.
Reseau.TCP.loopback_addr6 — Function
loopback_addr6(port; scope_id=0) -> SocketAddrV6Convenience constructor for [::1]:port.
Reseau.TCP.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 TCP read entrypoint once TCP.Conn follows Julia's IO contract.
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.
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.closeread — Function
closeread(conn)Shut down the read side of the TCP connection.
Base.closewrite — Method
closewrite(conn)Shut down the write side of the TCP connection.
Deadlines, Socket Options, and Address Inspection
Reseau.TCP.set_deadline! — Function
set_deadline!(conn, deadline_ns)Set both read and write deadlines on conn.
deadline_nsis an absolute monotonic timestamp in nanoseconds, using the same clock astime_ns().deadline_ns == 0disables both deadlines.deadline_ns <= time_ns()marks both sides as immediately timed out.
After the deadline is reached, blocking read!/write operations fail with DeadlineExceededError until the deadline is cleared or moved forward.
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.TCP.set_read_deadline! — Function
set_read_deadline!(conn, deadline_ns)Set only the read deadline on conn.
- Uses absolute monotonic nanoseconds (
time_ns()clock). deadline_ns == 0disables read timeouts.deadline_ns <= time_ns()causes read waits to time out immediately.
This affects read! wait paths only.
Reseau.TCP.set_write_deadline! — Function
set_write_deadline!(conn, deadline_ns)Set only the write deadline on conn.
- Uses absolute monotonic nanoseconds (
time_ns()clock). deadline_ns == 0disables write timeouts.deadline_ns <= time_ns()causes write waits to time out immediately.
This affects write wait paths only.
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)Enable or disable SO_KEEPALIVE on conn.
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.
TLS
Configuration, State, and Errors
Reseau.TLS.Config — Type
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 and peer name.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.ca_file: CA bundle or hashed CA directory used to verify remote servers. When omitted, client verification usesNetworkOptions.ca_roots_path().client_ca_file: CA bundle or hashed CA directory used by servers to verify client certificates. This is required for server configs that verify presented client certs.alpn_protocols: ordered ALPN protocol preference list.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.nothingleaves the bound unset.
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 as reported by OpenSSL.alpn_protocol: negotiated ALPN protocol, ornothingif ALPN was not used.
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 without corrupting the OpenSSL 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 constructing an SSL_CTX.
Reseau.TLS.TLSError — Type
TLSErrorRaised when TLS handshake/read/write/close operations fail.
code is usually an OpenSSL SSL_get_error result, though wrapper paths may set it to 0 when the failure is higher-level than one OpenSSL call. cause preserves the underlying Julia-side exception when the failure originated in the transport/poller layer instead of OpenSSL itself.
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_fileclient_ca_filealpn_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 OpenSSL while the others observe the completed state afterward.
Returns nothing.
Throws:
TLSHandshakeTimeoutErrorwhenconfig.handshake_timeout_nsexpiresTLSErrorfor OpenSSL or transport failuresEOFErrorif the peer closes cleanly during the handshake
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.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, this best-effort sends a TLS close_notify alert before closing the socket. 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 1.0 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.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.
Docstring Index
Reseau.HostResolversReseau.IOPollReseau.SocketOpsReseau.TCPReseau.TLSReseau.TCP.ConnReseau.TCP.DeadlineExceededErrorReseau.TCP.ListenerReseau.TCP.SocketAddrReseau.TCP.SocketAddrV4Reseau.TCP.SocketAddrV6Reseau.TCP.acceptReseau.TCP.addrReseau.TCP.any_addrReseau.TCP.any_addr6Reseau.TCP.closereadReseau.TCP.connectReseau.TCP.listenReseau.TCP.local_addrReseau.TCP.loopback_addrReseau.TCP.loopback_addr6Reseau.TCP.remote_addrReseau.TCP.set_deadline!Reseau.TCP.set_keepalive!Reseau.TCP.set_nodelay!Reseau.TCP.set_read_deadline!Reseau.TCP.set_write_deadline!Reseau.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!