NIO: ignore `SIGPIPE` on Windows (#1653)

Windows does not support Unix-style signals.  Simply exclude the SIGPIPE
path on Windows.

Co-authored-by: Cory Benfield <lukasa@apple.com>
This commit is contained in:
Saleem Abdulrasool 2020-09-30 02:13:10 -07:00 committed by GitHub
parent 2d913d65af
commit bc328cd3a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -351,7 +351,11 @@ class BaseSocket: BaseSocketProtocol {
do {
try self.ignoreSIGPIPE()
} catch {
#if os(Windows)
self.descriptor = INVALID_SOCKET // We have to unset the fd here, otherwise we'll crash with "leaking open BaseSocket"
#else
self.descriptor = -1 // We have to unset the fd here, otherwise we'll crash with "leaking open BaseSocket"
#endif
throw error
}
}

View File

@ -85,6 +85,7 @@ extension BaseSocketProtocol {
guard haveWeIgnoredSIGPIEThisIsHereToTriggerIgnoringIt else {
fatalError("BUG in NIO. We did not ignore SIGPIPE, this code path should definitely not be reachable.")
}
#elseif os(Windows)
#else
assert(fd >= 0, "illegal file descriptor \(fd)")
do {