bitflying/swift-nio
31.0
Weak · 22 September 2026
37.3k
lines of production code
Swift
primary language
6
measurements over time
What this system is
This system is a high-performance, cross-platform networking library for Swift, providing low-level I/O primitives and high-level protocol support. It implements core networking features including HTTP/1.1, WebSocket, and TLS negotiation, alongside platform-specific C shims for Linux, Windows, and Darwin. The codebase also includes a comprehensive test suite for validating memory allocation, concurrency primitives, and protocol handlers across multiple operating systems.
How it got here
2017 — HTTP/1.1 and TLS support
16 changes.
This period focused on implementing core HTTP/1.1 handling, including encoding, decoding, and pipeline management, alongside the introduction of TLS negotiation features like ALPN and SNI. The work also expanded the codebase with new concurrency primitives, a C-based HTTP parser, and comprehensive test coverage for Linux and other platforms.
2018 — Platform support and WebSocket expansion
16 changes.
This period focused on extending SwiftNIO's platform support by adding Darwin and Linux C shims for system calls like sendmmsg and socket operations. It also introduced the NIOWebSocket module with full client and server implementations, alongside comprehensive integration and performance testing infrastructure.
2019–2020 — Testing infrastructure and platform support
14 changes.
This period focused on expanding the project's testing capabilities and platform compatibility. New test utilities, integration test frameworks, and crash-testing tools were introduced to improve code coverage and reliability. Additionally, backward compatibility shims and Windows-specific implementations were added to support existing codebases and broaden platform support.
Features
Add ALPN, SNI, and TLS event types for TLS negotiation
Introduces new channel handlers and types to support TLS application-layer protocol negotiation (ALPN) and server name indication (SNI). The \ApplicationProtocolNegotiationHandler\ allows the pipeline to be reconfigured based on the result of an ALPN negotiation, while the \SNIHandler\ parses the TLS Client Hello to extract the requested hostname. These handlers work with the new \TLSUserEvent\ enum, which exposes common TLS lifecycle events such as \handshakeCompleted\ and \shutdownCompleted\ to application code.
Sources/NIOTLS · high confidence
Add AddressedEnvelope and BSD Socket API abstractions
Introduced the AddressedEnvelope struct to carry source/destination address metadata for datagram channels, including support for Explicit Congestion Notification (ECN) states. Added the NIOBSDSocket namespace with type-safe wrappers for socket options, address families, and protocol families, providing a unified interface for BSD socket operations across POSIX and Windows platforms.
Sources/NIO · high confidence
Add HTTP/1.1 client example application
A new sample application, NIOHTTP1Client, has been added to demonstrate how to build an HTTP/1.1 client using SwiftNIO. The example implements a simple echo client that sends a basic HTTP request and processes the server's response, supporting connections via IP address, port, or Unix domain sockets.
Sources/NIOHTTP1Client · high confidence
Add NIOChatServer example application
A new sample application, NIOChatServer, has been added to demonstrate a multi-user chat server using SwiftNIO. The implementation includes a line-delimiter codec for buffering inbound data and a thread-safe ChatHandler that manages connected clients and broadcasts messages. The server supports binding to an IP address and port, or a Unix domain socket, with command-line arguments to configure the binding target.
(repo-wide) · high confidence
Add NIOEchoServer example with Unix domain socket support
The NIOEchoServer sample application has been added, providing a simple echo server that sends clients back whatever data they send it. Users can now run the server by specifying an IP address and port, a Unix domain socket path, or just a port number. The server supports binding to IPv4/IPv6 addresses or Unix domain sockets, with the latter enabled via the new \bind(unixDomainSocketPath:)\ API.
Sources/NIOEchoServer · high confidence
Add NIOHTTP1Server sample application with HTTP/1.1 support
Introduces the NIOHTTP1Server example application, which provides a functional HTTP/1.1 server implementation. The server supports various query methods for testing, including serving static files via sendfile and non-blocking file IO, echoing request bodies, and handling HTTP keep-alive connections. It exposes multiple endpoints for diagnostics, continuous data streaming, and dynamic content generation, serving as a reference implementation for building HTTP servers with SwiftNIO.
Sources/NIOHTTP1Server · high confidence
Add NIOWebSocketServer sample application
A new sample application demonstrating a WebSocket server is added to the repository. The server handles HTTP GET requests to serve a test page, upgrades to WebSocket, and processes message opcodes including connection close, ping/pong, and text messages. The implementation includes an HTTP handler for the initial connection and a WebSocket handler that responds to specific frame types while ignoring others.
Sources/NIOWebSocketServer · high confidence
Add UDP Echo Client example
A new example application, NIOUDPEchoClient, has been added to demonstrate a simple UDP echo client. The client connects to a UDP echo server, sends a line of text, and waits for a response. It supports connecting to an IP address or a Unix domain socket, with configurable server and listening ports.
Sources/NIOUDPEchoClient · high confidence
Add WebSocket codec and HTTP upgraders for client and server
Introduces a new NIOWebSocket module providing a full WebSocket implementation. This includes a \WebSocketFrame\ struct and encoder/decoder handlers for serializing and parsing WebSocket frames. It also adds \NIOWebSocketClientUpgrader\ and \NIOWebSocketServerUpgrader\ to handle the HTTP upgrade handshake, allowing existing HTTP pipelines to be upgraded to WebSocket connections. The module also includes support for base64 encoding, SHA1 hashing for the handshake, and error code handling.
Sources/NIOWebSocket · high confidence
Add Windows-specific CNIOWindows header and module map
A new header file, CNIOWindows.h, is introduced to provide Windows-specific implementations of BSD socket APIs (such as send, recv, sendto, and recvfrom) and control message handling functions (CMSG\_DATA, CMSG\_FIRSTHDR, etc.). The file also defines the mmsghdr struct and stubs for sendmmsg and recvmmsg. A corresponding module.map file is added to expose the header to the Swift module. This change adds the necessary C bindings and wrappers to support Windows networking capabilities within the NIO framework.
Sources/CNIOWindows/include · high confidence
Add Windows-specific CNIOWindows shim and startup code
The CNIOWindows module now includes new C source files (WSAStartup.c and shim.c) that initialize Winsock on Windows and provide stubs for sendmmsg and recvmmsg, alongside wrappers for control message handling. This adds the necessary Windows-specific implementation details for network operations on that platform.
Sources/CNIOWindows · high confidence
Add allocation counter test framework with malloc/free hooking
The integration test suite now includes a new allocation counter framework that tracks memory allocations and frees. This is achieved by hooking standard C allocation functions (malloc, free, calloc, realloc, etc.) on both Darwin and Unix platforms. The framework provides C headers and source files to count allocations and total bytes allocated, and includes Swift scaffolding to measure and report these metrics during tests.
IntegrationTests/allocation-counter-tests-framework/template · medium confidence
Add allocation counting integration tests for performance regression tracking
A new allocation counting test framework has been added to the \IntegrationTests/tests\_04\_performance/test\_01\_resources\ directory. This includes a shell script (\run-nio-alloc-counter-tests.sh\) and a shared Swift module that hooks memory allocation functions (\malloc\/\free\) to count allocations during performance benchmarks. The directory now contains multiple test cases measuring allocations for scenarios such as 1000 TCP/UDP connections, HTTP/1 requests, WebSocket frame encoding/decoding, and task scheduling, allowing developers to track memory allocation stability across commits.
_IntegrationTests/tests\_04\_performance/test\_01\resources · high confidence
Add direct JSON Codable support for ByteBuffer
The NIOFoundationCompat module now provides direct JSON encoding and decoding for \ByteBuffer\ via new \getJSONDecodable\ and \writeJSONEncodable\ methods. Users can decode JSON into Swift \Decodable\ types and encode \Encodable\ types to JSON within a \ByteBuffer\ using \JSONDecoder\ and \JSONEncoder\. Additionally, \ByteBuffer\ gains \readData\ and \getData\ methods that support a \ByteTransferStrategy\ (copy, noCopy, or automatic) to control whether bytes are copied or referenced from the underlying storage.
Sources/NIOFoundationCompat · high confidence
Added C atomic operations library for SwiftNIO
The CNIOAtomics module now provides a comprehensive set of C-based atomic operations for various integer types, including bool, char, short, int, long, long long, and their signed/unsigned variants, as well as intptr\_t and uintptr\t. The implementation uses a macro to generate both a wrapper-based API (catmc\\*) and a native C11 \_Atomic-based API (catmc\nio\\*), supporting operations like compare-and-swap, add, subtract, exchange, load, and store. This adds new capabilities for low-level memory synchronization in SwiftNIO.
Sources/CNIOAtomics · high confidence
Added CNIODarwin shim for sendmmsg and cmsghdr helpers
Introduced a new C module, CNIODarwin, providing a Darwin-specific implementation of sendmmsg that wraps sendmsg calls and returns a short count on partial failures, alongside helper functions for cmsghdr manipulation (CMSG\_FIRSTHDR, CMSG\_NXTHDR, CMSG\_DATA, CMSG\_LEN, CMSG\_SPACE) and ECN constants, enabling SwiftNIO to use sendmmsg on macOS.
Sources/CNIODarwin · high confidence
Added NIOUDPEchoServer sample application
A new sample application, NIOUDPEchoServer, has been added to demonstrate a simple UDP echo server. The server binds to an IP address or Unix domain socket and echoes back data sent by clients. It supports optional gathering reads via the \--enable-gathering-reads\ flag to improve performance for multiple datagrams.
Sources/NIOUDPEchoServer · high confidence
Added crash tester suite for NIO
A new crash-testing tool has been added to the NIO project. This utility, located in the Sources/NIOCrashTester directory, is designed to verify that specific crash conditions (such as preconditions and assertions) are triggered as expected. The suite includes dedicated test cases for EventLoop, ByteBuffer, HTTP, and System components, ensuring that the library fails safely and predictably under error conditions.
Sources/NIOCrashTester · high confidence
Added memory allocation debugging and project scaffolding utilities
Added several new scripts in the dev/ directory to aid in debugging memory allocations and scaffolding Swift Package Manager projects. The new dtrace scripts (malloc-aggregation.d, boxed-existentials.d) and the Python stack-diffing script (stackdiff-dtrace.py) allow developers to capture and compare memory allocation stacks to identify changes or leaks. Additionally, the make-single-file-spm script provides a way to quickly generate a complete SwiftPM package structure from a single file containing module and dependency annotations, and a git commit template was added to standardize commit messages.
dev · high confidence
Added test utilities: ByteToMessageDecoderVerifier, EventCounterHandler, and NIOHTTP1TestServer
The NIOTestUtils module now includes three new test helpers: a \ByteToMessageDecoderVerifier\ for validating \ByteToMessageDecoder\ implementations by simulating various input scenarios; an \EventCounterHandler\ that counts and exposes counts of all channel pipeline events for verifying handler behavior; and an \NIOHTTP1TestServer\ that acts as a mock HTTP/1.1 server to facilitate testing of HTTP clients by allowing controlled responses and request inspection.
Sources/NIOTestUtils · high confidence
Adds Linux-specific C shims for socket, thread, and control message operations
Introduces CNIOLinux.h and shim.c to provide C-level wrappers for Linux-specific APIs. This includes shims for sendmmsg/recvmmsg (addressing Swift interop limitations), accept4, pthread thread naming and affinity (with Android-specific implementations for getname/setaffinity), and cmsghdr helper functions. These changes enable Swift code to utilize these Linux kernel features directly.
Sources/CNIOLinux · high confidence
HTTP parser implementation and licensing
The HTTP parser source code, header, and associated license and authorship files have been added to the project. The C implementation is prefixed with 'c\nio\' to prevent symbol clashes with other libraries, and the MIT license and AUTHORS file are included to properly attribute the original contributors.
Sources/CNIOHTTPParser · high confidence
Introduce HTTP/1.1 encoding, decoding, and pipeline setup handlers
Adds the core HTTP/1.1 channel handlers to SwiftNIO, including \HTTPRequestEncoder\ and \HTTPResponseEncoder\ for serializing HTTP messages, and \HTTPRequestDecoder\ and \HTTPResponseDecoder\ for parsing them. The update also introduces \HTTPServerPipelineHandler\ to manage HTTP pipelining and \HTTPServerUpgradeHandler\ to support protocol upgrades, along with a \HTTPServerProtocolErrorHandler\ to automatically return 400 Bad Request responses for malformed requests. These components are wired together via new \addHTTPClientHandlers\ and \configureHTTPServerPipeline\ convenience methods on \ChannelPipeline\.
Sources/NIOHTTP1 · high confidence
Introduce NIO 1 API shims for backward compatibility
A new \\_NIO1APIShims\ module has been added to provide backward compatibility with NIO 1 APIs. This includes deprecated type aliases (e.g., \FileHandle\ for \NIOFileHandle\), extension methods on \ChannelPipeline\ and \EventLoop\ that map to newer NIO 2 methods, and wrapper methods on \EventLoopFuture\ (such as \then\ and \mapIfError\) that delegate to the corresponding \flatMap\ and \recover\ functions. These shims allow existing code using the older API to continue functioning while encouraging migration to the current NIO 2 interfaces.
_Sources/\NIO1APIShims · high confidence
Introduce NIOPerformanceTester for benchmarking SwiftNIO components
Adds a new performance testing suite (NIOPerformanceTester) that provides benchmarks for key SwiftNIO components, including ByteBuffer, ChannelPipeline, and WebSocket frame encoding/decoding, enabling users to measure and compare performance characteristics of these features.
Sources/NIOPerformanceTester · high confidence
Introduce new atomic and locking primitives in NIOConcurrencyHelpers
The NIOConcurrencyHelpers module now includes new implementations for atomic operations and thread-safe locking. This adds the \NIOAtomic\ protocol and \UnsafeEmbeddedAtomic\ struct to provide fast, lock-free atomic operations for integer types (Bool, Int8-64, UInt8-64) and platform-specific pointer-sized integers. It also introduces a new \Lock\ class wrapping \pthread\_mutex\_t\ or Windows \SRWLOCK\, along with a \ConditionLock\ for state-based waiting. These changes provide a modernized, cross-platform foundation for concurrency primitives within the library.
Sources/NIOConcurrencyHelpers · high confidence
New allocation-counter integration test framework
A new shell-based test harness (run-allocation-counter.sh) and supporting C templates (AtomicCounter, HookedFunctions) have been added to the IntegrationTests/allocation-counter-tests-framework directory. This framework enables integration tests to track and verify memory allocation counters, providing a reusable structure for validating allocation behavior in Swift packages.
IntegrationTests/allocation-counter-tests-framework · high confidence
New scripts for API breakage checks, podspec generation, and performance analysis
Added several new scripts to the scripts/ directory to support development and release workflows. A new check\_no\_api\_breakages.sh script uses swift api-digester to detect public API changes between versions. A build\_podspecs.sh script generates and optionally uploads CocoaPods podspecs for SwiftNIO modules. An analyze\_performance\_results.rb script processes and compares performance metrics. Additional scripts include compare\_perf\_of\_swift\_versions.sh for comparing Swift versions, generate\_contributors\_list.sh for updating the contributors file, generate\_docs.sh for building documentation, generate\_linux\_tests.rb for generating Linux test runners, integration\_tests.sh for running integration tests, list\_topsorted\_dependencies.sh for listing module dependencies, and sanity.sh for checking license headers and unacceptable language.
scripts · high confidence
Behavioural changes
Added repository configuration and contributor attribution files
Added .gitattributes to mark vendored source files (CNIOHTTPParser, CNIOSHA1, CNIOLinux) as linguist-vendored, .gitignore to exclude build artifacts and IDE files, .mailmap to normalize contributor email addresses, and updated CONTRIBUTORS.txt and NOTICE.txt to reflect current contributor lists and license attributions.
(repo-wide) · high confidence
Integration test now expects a crash on double-lock
The integration test for the system call wrapper now verifies that the lock implementation crashes (SIGILL) when attempting to lock an already-locked resource, rather than exhibiting undefined behavior. This change ensures the test suite explicitly validates the new crash behavior.
_IntegrationTests/tests\_05\assertions · high confidence
New integration test infrastructure with structured output and debug mode
The integration test suite has been restructured with new helper scripts and plugins. A new 'echo' plugin provides human-readable console output for test results, while a 'junit\_xml' plugin generates JUnit-compatible XML reports for CI integration. The test runner now supports a 'debug' mode that preserves temporary files for inspection, and a 'show\_info' mode that displays informational messages during execution. These changes improve the visibility and debugging experience for integration tests.
IntegrationTests · high confidence
Updated HTTP parser to version 2.9.3
The vendored HTTP parser library has been updated to version 2.9.3, which includes a security fix for a vulnerability in the original http-parser project. The update also includes Swift-specific adaptations, such as a C++ wrapper header (CNIOHTTPParser.h) that provides a Swift-friendly inline function to execute the parser, and the addition of an umbrella header to simplify inclusion of the C module.
Sources/CNIOHTTPParser/include · high confidence
Updated SHA1 implementation for improved portability
The SHA1 C implementation in Sources/CNIOSHA1 has been updated to improve portability. The code now includes platform-specific headers for Android (sys/endian.h) and Linux (sys/types.h), and defines bzero and bcopy as inline macros where they are not already present. All symbols are prefixed with 'c\nio\' to avoid namespace collisions, and the code no longer relies on the \_KERNEL include guards, making it more suitable for general use.
Sources/CNIOSHA1 · high confidence
Test coverage
Add HTTP/1.1 integration tests for the NIO HTTP server; Add allocation counting integration test; Add crash tester test suite for debug binary checks; Added Linux test registration files for NIO HTTP/1 components; Added Linux test runner for SwiftNIO; Added XCTest-compatible test suite for NIOConcurrencyHelpers; Added comprehensive test coverage for NIOWebSocket components; Added integration tests for syscall wrappers; Added test coverage for NIOTestUtils components; Added tests for ByteBuffer data protocol and Codable support; Added tests for SNI and ALPN handlers; Expanded test coverage for core NIO components.
Dependencies
Upgrade to Swift 5.0 and add new NIO modules
The project has been upgraded to Swift tools-version 5.0. New libraries and targets have been added to the package, including NIOWebSocket, NIOTestUtils, and NIOFoundationCompat, alongside various internal targets like CNIOWindows and CNIOSHA1. The NIOHTTP1 module no longer depends on CNIOZlib, and the NIOPriorityQueue module has been removed in favor of the standard library's collections. Additionally, a new \_NIO1APIShims library is exposed to maintain compatibility with older APIs.
(dependencies) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
This is the PUBLIC form of this artifact. Findings are listed in full, but the details of SECURITY findings — which rule fired, in which file, on which line, and how to fix it — are deliberately withheld, and any secret-scanner results are excluded entirely. Where detail is absent here it was REMOVED FOR PUBLICATION; it is not missing from the analysis. The complete artifact is available from the repository owner.
Score
- CAI 46 → 31 (-15.0)
- Rubric changed (rubric-2026.08.19 → rubric-2026.09.15) — scores are not directly comparable.
Lenses
- Code Health 94 → 93 (-1.5)
- Architecture 98 → 97 (-1.1)
- Maturity 43 → 56 (+13.5)
- Readiness 26 → 31 (+5.4)
- Security 69 → 58 (-10.8)
- Event-Driven 10 (new)
Resolved (20)
- Change coupling: DeadChannel.swift ↔ Embedded.swift (Sources/NIO/DeadChannel.swift)
- Change coupling: DeadChannel.swift ↔ SocketChannel.swift (Sources/NIO/DeadChannel.swift)
- Change coupling: Selectable.swift ↔ Socket.swift (Sources/NIO/Selectable.swift)
- Coverage not included — suite not readable by the collector
- Dependency hygiene not measured — dependency manifest found but not parsed for hygiene
- FileTooLong: NIOPerformanceTester/main.swift (Sources/NIOPerformanceTester/main.swift)
- High IaC: DS-0029 (docker/Dockerfile)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- High: security finding (details withheld)
- LLM evaluation failed
- Medium IaC: CKV_DOCKER_3 (docker/Dockerfile)
- Medium IaC: CKV_DOCKER_7 (docker/Dockerfile)
- No exposed public API
- Test reliability not included
- complexity unreadable for .py, .rb, .swift — churn × complexity hotspots could not be measured
- dormant codebase — no living knowledge left to concentrate
New (298)
- BaseSocketChannel.flushNow (cognitive 25) (Sources/NIO/BaseSocketChannel.swift)
- BaseSocketChannel.flushNow (cyclomatic 17) (Sources/NIO/BaseSocketChannel.swift)
- BaseSocketChannel.readable0 (cognitive 21) (Sources/NIO/BaseSocketChannel.swift)
- BaseStreamSocketChannel.close0 (cognitive 16) (Sources/NIO/BaseStreamSocketChannel.swift)
- BaseStreamSocketChannel.readFromSocket (cognitive 20) (Sources/NIO/BaseStreamSocketChannel.swift)
- ByteToMessageDecoderVerifier.verifyDecoder (cognitive 40) (Sources/NIOTestUtils/ByteToMessageDecoderVerifier.swift)
- ByteToMessageDecoderVerifier.verifyDecoder (cyclomatic 19) (Sources/NIOTestUtils/ByteToMessageDecoderVerifier.swift)
- ByteToMessageHandler.decodeLoop (cognitive 16) (Sources/NIO/Codec.swift)
- Change coupling: main.swift ↔ main.swift (Sources/NIOEchoClient/main.swift)
- Coverage not measured — Swift suite
- DatagramChannel.singleReadFromSocket (cognitive 16) (Sources/NIO/SocketChannel.swift)
- DatagramChannel.vectorReadFromSocket (cognitive 17) (Sources/NIO/SocketChannel.swift)
- Dependency hygiene PARTLY measured — SwiftPM pinning read, dependency currency NOT established
- Documentation: no project overview (README.md)
- Duplicated block (10–11 lines × 2) (Sources/NIO/Selector.swift)
- Duplicated block (11 lines × 2) (Sources/NIO/EventLoopFuture.swift)
- Duplicated block (11 lines × 2) (Sources/NIOHTTP1Client/main.swift)
- Duplicated block (11 lines × 3) (Sources/NIOTestUtils/ByteToMessageDecoderVerifier.swift)
- Duplicated block (12 lines × 2) (Sources/NIOHTTP1/NIOHTTPObjectAggregator.swift)
- Duplicated block (122 lines × 2) (Sources/NIOHTTP1/HTTPEncoder.swift)
- …and 278 more
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
bitflying/swift-nio was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 22 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 4853e910e8aca4e65f92b2d335a59da337bd3730 — the exact code this score is about.
- Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-821afab8930d.