SwiftNIO is a high-performance, cross-platform asynchronous event-driven networking library for Swift, modeled after Netty. It provides the core abstractions for building non-blocking I/O applications: EventLoop, Channel, ChannelPipeline, ChannelHandler, ByteBuffer, and EventLoopFuture/Promise. The library includes in-tree protocol implementations for HTTP/1.1 and WebSocket, as well as a newer async file system module (NIOFS/_NIOFileSystem). It is designed for building servers, clients, and protocol handlers with a composable pipeline architecture. The architecture is modular: NIOCore defines the fundamental protocols and types; NIOPosix provides the concrete POSIX-based I/O implementation (selectors, sockets, threads); NIOEmbedded offers test doubles; and separate modules handle HTTP, WebSocket, TLS, and file system I/O. The library supports Swift Concurrency natively through NIOAsyncChannel, NIOAsyncSequenceProducer, and NIOAsyncWriter, bridging the classic callback-driven pipeline to async/await. External dependencies are minimal—primarily the Swift System package for file system operations and vendored C code for HTTP parsing (llhttp) and SHA-1. Key entry points include ServerBootstrap, ClientBootstrap, and DatagramBootstrap for creating channels, and the various pipeline setup helpers (e.g., configureHTTPServerPipeline). Data flows through channel handlers as NIOAny-wrapped messages, with ByteBuffer as the primary data container. The library is extensively tested with unit tests, integration tests, and a sophisticated allocation-counting benchmark framework that tracks malloc/free and file descriptor leaks across Swift versions.
SwiftNIO HTTP/2 is a Swift library providing HTTP/2 protocol support for SwiftNIO-based applications. It implements the HTTP/2 specification (RFC 7540) and HPACK header compression (RFC 7541) in pure Swift, with no external dependencies beyond SwiftNIO core. The library features a modular architecture separating frame handling, connection state management, stream multiplexing, and header compression. Key components include a connection state machine for managing HTTP/2 connection lifecycle, stream multiplexing logic for creating child channels per HTTP/2 stream, and an HPACK implementation with Huffman coding. The repository includes extensive unit tests, integration tests, performance benchmarks, and fuzz testing to ensure correctness and performance.