@@ -126,10 +126,8 @@ public struct Socket: Sendable, Hashable {
126
126
switch domain {
127
127
case AF_INET:
128
128
try setValue ( true , for: . packetInfoIP)
129
- #if !canImport(WinSDK)
130
129
case AF_INET6:
131
130
try setValue ( true , for: . packetInfoIPv6)
132
- #endif
133
131
default :
134
132
return
135
133
}
@@ -221,7 +219,7 @@ public struct Socket: Sendable, Hashable {
221
219
Socket . connect ( file. rawValue, $0, address. size)
222
220
}
223
221
guard result >= 0 || errno == EISCONN else {
224
- if errno == EINPROGRESS {
222
+ if errno == EINPROGRESS || errno == EWOULDBLOCK {
225
223
throw SocketError . blocked
226
224
} else {
227
225
throw SocketError . makeFailed ( " Connect " )
@@ -248,7 +246,7 @@ public struct Socket: Sendable, Hashable {
248
246
guard count > 0 else {
249
247
if errno == EWOULDBLOCK {
250
248
throw SocketError . blocked
251
- } else if errno == EBADF || count == 0 {
249
+ } else if errnoSignalsDisconnected ( ) || count == 0 {
252
250
throw SocketError . disconnected
253
251
} else {
254
252
throw SocketError . makeFailed ( " Read " )
@@ -275,7 +273,7 @@ public struct Socket: Sendable, Hashable {
275
273
guard count > 0 else {
276
274
if errno == EWOULDBLOCK {
277
275
throw SocketError . blocked
278
- } else if errno == EBADF || count == 0 {
276
+ } else if errnoSignalsDisconnected ( ) || count == 0 {
279
277
throw SocketError . disconnected
280
278
} else {
281
279
throw SocketError . makeFailed ( " RecvFrom " )
@@ -340,7 +338,7 @@ public struct Socket: Sendable, Hashable {
340
338
guard count > 0 else {
341
339
if errno == EWOULDBLOCK || errno == EAGAIN {
342
340
throw SocketError . blocked
343
- } else if errno == EBADF || count == 0 {
341
+ } else if errnoSignalsDisconnected ( ) || count == 0 {
344
342
throw SocketError . disconnected
345
343
} else {
346
344
throw SocketError . makeFailed ( " RecvMsg " )
@@ -365,7 +363,7 @@ public struct Socket: Sendable, Hashable {
365
363
guard sent > 0 else {
366
364
if errno == EWOULDBLOCK {
367
365
throw SocketError . blocked
368
- } else if errno == EBADF {
366
+ } else if errnoSignalsDisconnected ( ) {
369
367
throw SocketError . disconnected
370
368
} else {
371
369
throw SocketError . makeFailed ( " Write " )
@@ -568,10 +566,14 @@ public extension SocketOption where Self == BoolSocketOption {
568
566
BoolSocketOption ( level: Socket . ipproto_ip, name: Socket . ip_pktinfo)
569
567
}
570
568
571
- #if !canImport(WinSDK)
572
569
static var packetInfoIPv6 : Self {
573
570
BoolSocketOption ( level: Socket . ipproto_ipv6, name: Socket . ipv6_recvpktinfo)
574
571
}
572
+
573
+ #if canImport(WinSDK)
574
+ static var exclusiveLocalAddressReuse : Self {
575
+ BoolSocketOption ( name: ~ SO_REUSEADDR) // SO_EXCLUSIVEADDRUSE macro
576
+ }
575
577
#endif
576
578
577
579
#if canImport(Darwin)
@@ -627,6 +629,14 @@ package extension Socket {
627
629
}
628
630
}
629
631
632
+ fileprivate func errnoSignalsDisconnected( ) -> Bool {
633
+ #if canImport(WinSDK)
634
+ return errno == WSAENOTSOCK || errno == WSAENOTCONN || errno == WSAECONNRESET
635
+ #else
636
+ return errno == EBADF
637
+ #endif
638
+ }
639
+
630
640
#if !canImport(WinSDK)
631
641
fileprivate extension Socket {
632
642
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0138-unsaferawbufferpointer.md
0 commit comments