From 0ae9524ca89d339d0f503799084ffdb8df09f89a Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 30 Sep 2020 02:32:52 -0700 Subject: [PATCH] NIO: invalid sockets are not `-1` but `INVALID_SOCKET` (#1660) Adjust the sentinel indicating an invalid socket. Co-authored-by: Cory Benfield --- Sources/NIO/BaseSocket.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/NIO/BaseSocket.swift b/Sources/NIO/BaseSocket.swift index 0ebd2fba8..db217f012 100644 --- a/Sources/NIO/BaseSocket.swift +++ b/Sources/NIO/BaseSocket.swift @@ -475,7 +475,11 @@ class BaseSocket: BaseSocketProtocol { /// - throws: An `IOError` if the operation failed. final func takeDescriptorOwnership() throws -> NIOBSDSocket.Handle { return try self.withUnsafeHandle { +#if os(Windows) + self.descriptor = INVALID_SOCKET +#else self.descriptor = -1 +#endif return $0 } }