Skip to content

Winsock Fixes - #3433

Merged
glbrntt merged 37 commits into
apple:mainfrom
Joannis:jo/winsock-fixes
Jul 7, 2026
Merged

glbrntt merged 37 commits into
apple:mainfrom
Joannis:jo/winsock-fixes

Conversation

@Joannis

@Joannis Joannis commented Nov 3, 2025 •

Copy link
Copy Markdown
Contributor

This PR gets TCP (Servers) on Windows mostly working. I'll annotate my PR for clarity.

The one bug:
If you open a TCP client connection to a Windows TCP server, it doesn't read/write yet until a second connection comes in. This happens because reregister0 is called after WSAPoll is called - but WSAPoll isn't woken up to know this so it doesn't know the new socket requests read/writes/...

Also the EventLoop cannot be woken up during el.execute { .. } because SleepEx isn't running. WSAPoll doesn't respond to this signal it seems.

This makes the TCP server functionality not yet usable, but I thought with this draft we could figure out what I'm missing.

Alternative considered: We can make WSAPoll limited to wake up every 1 ms for example, that way we can still get to these events at some point.

This results in a partially working winsock
BUG: A connection currently only becomes communicative after a new connection comes in. But Windows TCP is working after that.
Comment on lines +48 to +57
var realHandle: HANDLE? = nil
let success = DuplicateHandle(
GetCurrentProcess(), // Source process
GetCurrentThread(), // Source handle (pseudo-handle)
GetCurrentProcess(), // Target process
&realHandle, // Target handle (real handle)
0, // Desired access (0 = same as source)
false, // Inherit handle
DWORD(DUPLICATE_SAME_ACCESS) // Options
)

@Joannis Joannis Nov 3, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Windows gives pseudo handles by default, so they're always correct for the current thread. However, when spawning work on another thread, this handle results in getting the incorrect ThreadID, causing QueueUserAPC to notify the wrong (or non-existing) thread. This in turn prevents SleepEx from waking up the eventloop

@fabianfett fabianfett Feb 3, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't use QueueUserAPC anymore. However the general statement remains true. Maybe we can rework the comments, to be less about QueueUserAPC. We maybe also want to document somewhere why QueueUserAPC is not an option.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved β€” these comments were reworked away from QueueUserAPC; the rationale for why APCs are not usable now lives in the selector wakeup section in SelectorWSAPoll.swift.


static var currentThread: ThreadOpsSystem.ThreadHandle {
GetCurrentThread()
var realHandle: HANDLE? = nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Likewise here

Comment thread Sources/NIOPosix/SelectorWSAPoll.swift Outdated
registrationID: SelectorRegistrationID
) throws {
fatalError("TODO: Unimplemented")
if let index = self.pollFDs.firstIndex(where: { $0.fd == UInt64(fileDescriptor) }) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deregistering is just removing the FD. However, we can't just remove it here as we're iterating over the same pollFDs at the same time. deregister0 is called down the stack of try body((SelectorEvent(io: selectorEvent, registration: registration))). So the available indices of pollFDs changes causing a crash

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we add this comment to the local array that we use for this? so that we document what this array is used for?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved β€” pollFDs is now documented (together with its pollFDIndexes and deregisteredFDs companions) in SelectorGeneric.swift.

Comment thread Sources/NIOPosix/SelectorWSAPoll.swift Outdated
@@ -131,6 +133,19 @@ extension Selector: _SelectorBackendProtocol {

try body((SelectorEvent(io: selectorEvent, registration: registration)))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This line often calls deregister0 indirectly, so we effectively can't mutate pollFDs in deregister0

Comment thread Sources/NIOPosix/SelectorWSAPoll.swift Outdated
Comment on lines +137 to +148
// now clean up any deregistered fds
// In reverse order so we don't have to copy elements out of the array
// If we do in in normal order, we'll have to shift all elements after the removed one
for i in self.deregisteredFDs.indices.reversed() {
if self.deregisteredFDs[i] {
// remove this one
let fd = self.pollFDs[i].fd
self.pollFDs.remove(at: i)
self.deregisteredFDs.remove(at: i)
self.registrations.removeValue(forKey: Int(fd))
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do the deregister0 work of cleaning up after the polling is done

func initialiseState0() throws {
self.pollFDs.reserveCapacity(16)
self.deregisteredFDs.reserveCapacity(16)
self.lifecycleState = .open

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lifecycle never became open yet

Comment thread Sources/NIOPosix/SocketChannel.swift Outdated
Comment on lines +396 to +399
#if os(Windows)
case .winsock(WSAEWOULDBLOCK):
return false
#endif

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

accept returns WSAEWOULDBLOCK

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why doesn't the current logic for syscall(blocking: true) cover this?

@Joannis

Joannis commented Nov 3, 2025

Copy link
Copy Markdown
Contributor Author

CC @fabianfett and @zamderax

@Joannis
Joannis marked this pull request as ready for review November 3, 2025 14:22
This way new TCP connections will be functional
#if os(Windows)
if
let err = err as? IOError,
case .winsock(WSAEWOULDBLOCK) = err.error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How is this case reached?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What I've found is that when WSAPoll gives the server socket a .read event when a client is inbound:

  • Server accepts the client through readable() -> readable0() -> ServerSocketChannel.readFromSocket()
  • The socket.accept(..) finds a socket
  • SelectableEventLoop repeats this again again to get another read (see maxMessagesPerRead)
  • This time, socket.accept(..) runs into WinSDK.INVALID_SOCKET
  • Gets the error using WSAGetLastError()
  • The error ends up reaching .winsock(WSAEWOULDBLOCK)

In hindsight, I just noticed that accept() returns an optional so I'll leverage that instead.

Comment thread Sources/NIOPosix/SelectorWSAPoll.swift Resolved
Comment thread Sources/NIOPosix/SocketChannel.swift Outdated
Comment on lines +396 to +399
#if os(Windows)
case .winsock(WSAEWOULDBLOCK):
return false
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why doesn't the current logic for syscall(blocking: true) cover this?

Comment thread Sources/NIOPosix/SocketChannel.swift Resolved
Comment thread Sources/NIOPosix/SocketChannel.swift Resolved
@3a4oT

3a4oT commented Dec 15, 2025

Copy link
Copy Markdown
Contributor

Hey guys, is it something that can be accepted? What is the status of this PR? Can someone please share plans for the Windows support roadmap?

@Joannis
Joannis requested review from Lukasa and fabianfett December 18, 2025 18:04
@Joannis

Joannis commented Jan 19, 2026

Copy link
Copy Markdown
Contributor Author

@3a4oT this needs a proper review first. And there's one gaping hole in the implementation's polling still that needs fixing.
It uses a loopback socket so we can wake up the EventLoop, but that exposes a literal server socket as a temporary measure. I didn't find a way to use a pipe with WSAPoll yet, but IMO this is unacceptable to merge before we find a solution to that. You can rely on my branch for demo-level code to try out NIO on Windows.

Hopefully I'll figure that out soon.

Comment on lines +90 to 128
private static func createWakeupSocketPair() throws -> (NIOBSDSocket.Handle, NIOBSDSocket.Handle) {
// Create a UDP socket to receive wakeup signals
let readSocket = try NIOBSDSocket.socket(domain: .inet, type: .datagram, protocolSubtype: .default)

do {
// Bind to loopback on an ephemeral port
var addr = sockaddr_in()
addr.sin_family = ADDRESS_FAMILY(AF_INET)
addr.sin_addr.S_un.S_addr = WinSDK.htonl(UInt32(bitPattern: INADDR_LOOPBACK))
addr.sin_port = 0 // Let the system assign a port

try withUnsafeBytes(of: &addr) { addrPtr in
let socketPointer = addrPtr.baseAddress!.assumingMemoryBound(to: sockaddr.self)
try NIOBSDSocket.bind(socket: readSocket, address: socketPointer, address_len: socklen_t(MemoryLayout<sockaddr_in>.size))
}

// Get the assigned port
var boundAddr = sockaddr()
var size = Int32(MemoryLayout<sockaddr>.size)
try NIOBSDSocket.getsockname(socket: readSocket, address: &boundAddr, address_len: &size)

// Create the write socket
let writeSocket = try NIOBSDSocket.socket(domain: .inet, type: .datagram, protocolSubtype: .default)

do {
// Connect the write socket to the read socket's address
guard try NIOBSDSocket.connect(socket: writeSocket, address: &boundAddr, address_len: size) else {
throw IOError(winsock: WSAGetLastError(), reason: "connect")
}
return (readSocket, writeSocket)
} catch {
_ = try? NIOBSDSocket.close(socket: writeSocket)
throw error
}
} catch {
_ = try? NIOBSDSocket.close(socket: readSocket)
throw error
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the code that needs to be fixed.

Comment thread Sources/NIOPosix/System.swift Outdated

import CNIOWindows

let IPPROTO_UDP = Int32(17)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IPPROTO_UDP is of IPPROTO type on Windows. Windows has some weird mappings of POSIX constants

Comment thread Sources/NIOPosix/System.swift Outdated
static var UIO_MAXIOV: Int {
fatalError("unsupported OS")
// TODO: This is a placeholder value. Find the correct one for Windows.
return 64

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This variable doesn't formally exist on Windows, but vector writing does work on Windows. We should really make it unavailable for Windows, and update all dependencies that indirectly use this constant. I had a few places that were affected

Comment thread Sources/NIOPosix/SelectorGeneric.swift Outdated
Comment on lines +220 to +221
@usableFromInline
var deregisteredFDs = [Bool]()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make sense to just store indexes here? This would prevent us from linear searching the pollFDs. Please also add a comment what we use this array for.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved β€” there is now a pollFDIndexes map (fd β†’ index) so reregister0/deregister0 are O(1) instead of scanning pollFDs, and it is documented.

Comment thread Sources/NIOPosix/SelectorWSAPoll.swift Outdated

try withUnsafeBytes(of: &addr) { addrPtr in
let socketPointer = addrPtr.baseAddress!.assumingMemoryBound(to: sockaddr.self)
try NIOBSDSocket.bind(socket: readSocket, address: socketPointer, address_len: socklen_t(MemoryLayout<sockaddr_in>.size))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using sockaddr_in is weird, as we have previously cast the pointer to sockaddr.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved by the later redesign β€” the wakeup pair is AF_UNIX/sockaddr_un throughout now, so the odd sockaddr_in cast is gone.

@fabianfett

Copy link
Copy Markdown
Member

we will also need to make the CI green

@Joannis

Joannis commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

CC @fabianfett can I get a review? CI is failing on benchmark changes, which seem in favour of this PR actually πŸ˜… But the alloc count changed - I don't modify that though. I think it's better for you to make sure it's correct.

@rafaelcepeda

Copy link
Copy Markdown
Contributor

CC @fabianfett can I get a review? CI is failing on benchmark changes, which seem in favour of this PR actually πŸ˜… But the alloc count changed - I don't modify that though. I think it's better for you to make sure it's correct.

@Joannis I've asked @glbrntt to look into this soon. Fabian is away at the moment.

Comment thread Sources/NIOPosix/SelectorWSAPoll.swift Outdated
private static func generateUniqueSocketPath() throws -> String {
// Get the temp directory path
var tempPathBuffer = [CChar](repeating: 0, count: Int(MAX_PATH) + 1)
let tempPathLen = GetTempPathA(DWORD(tempPathBuffer.count), &tempPathBuffer)

@jakepetroules jakepetroules Jun 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should use GetTempPath2W -- the 'A' functions are not Unicode safe and there are numerous reasons this could be a path with Unicode characters in it, or a path longer than the 260-chars soft limit.

Take a look at https://github.com/swiftlang/swift-subprocess/blob/049ddf99c37c50411ce2997dc92a36eb74460b98/Sources/Subprocess/Platforms/Subprocess%2BWindows.swift#L1696, which helps fill an appropriately-sized buffer for you, up to the actual maximum supported by Windows (Int16.max). (please just copypaste this implementation, we'll want it in a bunch more places too, I'm sure)

Example usage here: https://github.com/swiftlang/swift-subprocess/blob/049ddf99c37c50411ce2997dc92a36eb74460b98/Sources/Subprocess/Platforms/Subprocess%2BWindows.swift#L775

Comment thread Sources/NIOPosix/SelectorWSAPoll.swift Outdated
let listenerSocket = try NIOBSDSocket.socket(domain: .unix, type: .stream, protocolSubtype: .default)
defer {
_ = try? NIOBSDSocket.close(socket: listenerSocket)
_ = socketPath.withCString { DeleteFileA($0) }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should use DeleteFileW; see other comment for why you can't guarantee this is ASCII, or less than 260 chars.

Comment on lines +20 to +22
#if os(Windows)
import WinSDK
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this import necessary?

Comment thread Sources/NIOCore/IO.swift
}

private let error: Error
package let error: Error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see you've opened this up to use in SocketChannel.swift and avoid the fatalError path in errnoCode. We'll need to think about how to handle that API a bit better in the future. For now could you document that calling errnoCode will fatalError on Windows?


static func joinThread(_ thread: ThreadOpsSystem.ThreadHandle) {
let dwResult: DWORD = WaitForSingleObject(thread, INFINITE)
let dwResult: DWORD = WaitForSingleObject(thread.handle, INFINITE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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


static var currentThread: ThreadOpsSystem.ThreadHandle {
GetCurrentThread()
var realHandle: HANDLE? = nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't this leaking handles? IIUC each "real" handle from DuplicateHandle is its own entity which needs a call to CloseHandle?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it also means Thread.currentThreadID won't return a stable value on Windows since each handle will have a different value despite pointing to the same underlying kernel resource. A quick search found this which seems more appropriate: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentthreadid

Comment thread Sources/NIOPosix/SelectorWSAPoll.swift Outdated
}

func close0() throws {
// Close the wakeup sockets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this func be acquiring the externalSelectorFDLock? Both the epoll and kqueue selectors do.

@jakepetroules

Copy link
Copy Markdown
Member

What's the latest status on this PR? Are we waiting for @Joannis to review @odrobnik's changes?

@odrobnik

odrobnik commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

I sent a PR to @Joannis fork with the review comments addressed. I wanted to be helpful to @Joannis but he didn't react to it yet.

@Joannis

Joannis commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Hey @odrobnik - I did reply on your messages actually! I was at an event in Munich which took a week out of my schedule (no Windows laptop with me).
I'm working on it today

Joannis and others added 4 commits July 3, 2026 14:21
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015AbqR9AdcXCNDegGY3fxpc
Address review feedback (jakepetroules): the ANSI GetTempPathA cannot
represent temp directories outside the active code page and is capped at
the 260-char MAX_PATH soft limit. Switch to the wide GetTempPath2W via a
buffer-filling helper (modeled on swift-subprocess) that grows up to
Int16.max, decoding the result as UTF-16.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015AbqR9AdcXCNDegGY3fxpc
Follow-up to the GetTempPath2W change, covering the rest of the
outstanding review comments on the Winsock Fixes PR (apple#3433):

- SelectorWSAPoll: delete the on-disk wakeup socket path with DeleteFileW
  instead of DeleteFileA, matching the Unicode/long-path safety of the
  GetTempPath2W lookup (jakepetroules).
- SelectorWSAPoll: take externalSelectorFDLock in close0, matching the
  epoll and kqueue selectors, so wakeup-socket teardown is serialized
  against wakeup0 (glbrntt).
- ThreadWindows.joinThread: CloseHandle the duplicated, owning thread
  handle after the join to stop leaking kernel handles (glbrntt).
- Thread.currentThreadID: on Windows use GetCurrentThreadId(), which is
  stable and allocation-free, instead of the value of a freshly
  DuplicateHandle'd HANDLE (unstable and leaked) (glbrntt).
- Thread.withCurrentThread: CloseHandle the current-thread handle that
  currentThread duplicated, on Windows (glbrntt).
- IOError.errnoCode: document that it traps on Windows when the error is
  in the windows/winsock domain rather than errno (glbrntt).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015AbqR9AdcXCNDegGY3fxpc
@odrobnik

odrobnik commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Hi @Joannis - my Claude noticed two items still unadressed, I've updated the PR 2

@jakepetroules

Copy link
Copy Markdown
Member

I also got a new Windows CI job spun up in #3644, and @glbrntt has marked that as required so we can guarantee no portion of the in-progress Windows build regresses as we continue to get more targets building successfully.

@Joannis since this PR gets NIOPosix and 16 other downstream targets successfully building, can you please add those to MATRIX_WINDOWS_COMMAND in the GitHub Actions as part of this PR so we can "lock them in"? Here's a diff which does that, feel free to pull it into your branch: ea9314b

odrobnik and others added 2 commits July 6, 2026 10:57
…hreadex handle leak)

Two fixes not covered by the direct review-feedback commits already on this branch:

- ThreadWindows.run: close the owning handle returned by `_beginthreadex`. The
  handle used to `join` the spawned thread is the one the thread duplicates for
  itself in `routine`; the `_beginthreadex` handle is never used, so it leaked one
  handle per spawned thread (and left an unused variable). Closing it does not
  affect the still-running thread.
- BaseSocketChannel: remove the unused `import WinSDK` (glbrntt review comment).

Also corrects a stale doc comment on `pollFDIndexes` to match the in-place
compaction that `whenReady0` performs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
With this branch's Winsock fixes, NIOPosix and everything that just
transitively depended on it now compiles cleanly on Windows. Extend
the Windows CI target list from 11 to 28: add NIO, NIOPosix,
NIOTestUtils, and all 14 example executables (NIOTCPEcho{Server,
Client}, NIOEcho{Server,Client}, NIOHTTP1{Server,Client},
NIOChat{Server,Client}, NIOWebSocket{Server,Client}, NIOMulticastChat,
NIOUDPEcho{Server,Client}, NIOAsyncAwaitDemo).

Still failing and therefore still excluded:
- NIOPerformanceTester (missing stdout in scope)
- NIOCrashTester (missing setenv in scope)
- NIOFS / NIOFileSystem family (POSIX file primitives via swift-system)
@gmondada

gmondada commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@jakepetroules, @odrobnik, I just pulled in your changes. There are no more open points, correct? Can someone trigger the CI? Thanks

@glbrntt glbrntt added the πŸ”¨ semver/patch No public API change. label Jul 6, 2026

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the format check has failed. Could you run the formatter?

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks to all involved in getting this over the line!

@glbrntt
glbrntt merged commit 419f57f into apple:main Jul 7, 2026
53 of 57 checks passed
@odrobnik

odrobnik commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Awesome, thanks to all involved in getting this over the line!

Thanks to Apple too for allowing it!

It's on main now. Now we are waiting for it to become a release right?

@weissi weissi mentioned this pull request Jul 11, 2026
MrMage pushed a commit to Timing-GmbH/swift-nio that referenced this pull request Oct 14, 2026
…no longer traps

Two winsock gaps that apple#3433 left:

1. A socket's pending error (`SO_ERROR`) is a winsock code on Windows, but the
   three places that read it (`BaseSocketChannel.reset()`,
   `Socket.finishConnect()`, `SocketChannel.error()`) filed it under `errno`.
   A refused connect therefore read "connection reset (error set): Unknown
   error) (errno: 10061)", and `shouldCloseOnErrnoCode` compared a winsock code
   with POSIX constants. They now go through `IOError(socketErrorCode:reason:)`,
   which files the code under its POSIX errno where one exists (ECONNREFUSED,
   "connection refused") and under `winsock` otherwise.

2. `IOError.errnoCode` called `fatalError` for a winsock or Windows code. Callers
   cannot know to check the domain first (NIO's own `BaseSocket` reads it after a
   failed `IPV6_V6ONLY`), and an app that shows a failed bind's
   `strerror(errnoCode)` died instead of reporting a taken port. It now returns
   the POSIX errno of the same meaning for a winsock code where there is one,
   else the code itself, which matches no POSIX constant.

The winsock-to-POSIX table spells the winsock codes as numbers so NIOCore keeps
its selective WinSDK imports. Everything is inside `#if os(Windows)`.

`WindowsPortTests/WinsockErrorTests` covers a refused connect, a bind on a taken
port and `errnoCode` itself; the refused-connect test fails on the previous
commit (10061 is not 107, "Unknown error").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MBLwkmBCzQTzq1itHKFmtH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

πŸ”¨ semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants