Something went wrong. Try again.
QUIC for Zig 0.17: RFC 9000-9002 with TLS 1.3, as a sans-I/O core plus a socket layer, with datagrams, multipath and raw public keys.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! QUIC with the I/O put back, for callers who want a server rather than a//! state machine.//!//! The `quic` module beside this one is sans-I/O on purpose: it has no//! sockets, no clock and no addresses, which is what makes it testable at//! half a million inputs a second and what lets a caller drive it from//! whatever event loop it already has. That is the right shape for the//! library and the wrong shape for somebody who just wants to answer//! requests, because the loop it leaves you to write is not small — a UDP//! socket demultiplexing to many connections, a timer that has to fire while//! the socket is quiet, connection IDs to route by, Retry, stateless reset,//! and a table of all of it.//!//! This module is that loop, written once. It is a separate module rather//! than part of `quic` so that the core keeps its property: nothing in//! `quic` imports anything from here, and a caller who wants the state//! machine alone never compiles a socket.//!//! ## The shape of it//!//! An `Endpoint` owns the socket and the connection table. A `Session` is one//! connection, and a `Stream` is one stream on it, presented as an//! `Io.Reader` and an `Io.Writer` — so the code above looks like code that//! reads and writes, rather than code that pumps.//!//! ```//! Endpoint.pump() one task: socket in, timers, routing//! |//! +-- Session one task each: the application//! |//! +-- Stream Io.Reader / Io.Writer//! ```//!//! ## Who sends//!//! The awkward question in a design like this is how a task that has just//! written to a stream gets its octets onto a socket that another task is//! blocked reading. The usual answers are to poll on a short timeout, or to//! wake the reader with a self-pipe, and both are machinery in service of an//! arrangement nobody asked for.//!//! So neither. **Whatever changes a connection's state flushes that//! connection itself**, under that connection's own lock: the pump flushes//! after a datagram or a timer, and a writing task flushes after it writes.//! A UDP socket takes concurrent sends perfectly well, the lock is per//! connection rather than per endpoint, and there is no wakeup to miss//! because there is nothing waiting to be woken.
const std = @import("std");
pub const Endpoint = @import("Endpoint.zig");/// The end that dials: one connection to one server.pub const Client = @import("Client.zig");pub const Session = @import("Session.zig");pub const Stream = @import("Stream.zig");/// The IP header's ECN field, which §13.4 of RFC 9000 needs and a library/// with no sockets cannot reach. Exposed because it is the seam: a caller/// driving its own socket rather than this `Endpoint` still has to read the/// field and hand it to `Connection.receiveEcn`.pub const ecn = @import("ecn.zig");
test { refAllDeclsRecursive(@This(), "");}
/// `std.testing.refAllDecls`, carried down into every public type declared/// in this module -- so that a test written inside one, a doctest on a/// method above all, is compiled and run rather than silently left out. A/// test in a container nothing refers to is never analyzed, and 0.17 has no/// recursive form of its own.////// A type is followed only where it was declared: its name has to be the/// name of the decl holding it, under the name of the type holding that./// An alias -- `pub const Allocator = std.mem.Allocator`, a type re-exported/// from another file -- fails the test and is left alone, which is what/// stops this wandering into the standard library or round in a circle.fn refAllDeclsRecursive(comptime T: type, comptime prefix: []const u8) void { inline for (comptime std.meta.declarations(T)) |name| { const decl = &@field(T, name); if (@TypeOf(decl.*) != type) continue; const D = decl.*; switch (@typeInfo(D)) { .@"struct", .@"union", .@"enum", .@"opaque" => {}, else => continue, } if (comptime std.mem.eql(u8, @typeName(D), prefix ++ name)) refAllDeclsRecursive(D, @typeName(D) ++ "."); }}