mirror of
https://github.com/apple/swift-nio-extras
synced 2026-11-30 05:28:45 +00:00
Motivation: The NIOPCAPRingBuffer can limit the number of fragment or the total number of bytes in its buffer or both. When configuring the buffer to limit only the maximum number of bytes it sets the maximum number of fragments allowed to `.max`. On `init` the buffer has enough capacity reserved to store tha maximum number of fragments. This would be a large and potentially totally unnecessary allocation. That is, if it didn't crash at runtime. It crashes at runtime as `CircularBuffer` converts the requested capacity to a `UInt32` which traps if you pass it an `Int.max`. Modifications: - Don't reserve capacity on init - Adjust the test which tests the byte limit to not set a capacity as well Result: - `NIOPCAPRingBuffer(maximumBytes:)` doesn't crash