Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Sources/NIOPosix/SelectableEventLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ import NIOConcurrencyHelpers
import NIOCore
import _NIODataStructures

private func printError(_ string: StaticString) {
string.withUTF8Buffer { buf in
var buf = buf
while buf.count > 0 {
// 2 is stderr
let rc = write(2, buf.baseAddress, buf.count)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use STDERR_FILENO instead of the hardcoded int

if rc < 0 {
let err = errno
if err == EINTR { continue }
fatalError("Unexpected error writing: \(err)")
}
buf = .init(rebasing: buf.dropFirst(Int(rc)))
}
}
}

/// Execute the given closure and ensure we release all auto pools if needed.
@inlinable
internal func withAutoReleasePool<T>(_ execute: () throws -> T) rethrows -> T {
Expand Down Expand Up @@ -438,12 +454,11 @@ internal final class SelectableEventLoop: EventLoop, @unchecked Sendable {
if Self.strictModeEnabled {
fatalError("Cannot schedule tasks on an EventLoop that has already shut down.")
}
fputs(
printError(
"""
ERROR: Cannot schedule tasks on an EventLoop that has already shut down. \
This will be upgraded to a forced crash in future SwiftNIO versions.\n
""",
stderr
"""
)
return false
}
Expand Down
Loading