Skip to content

Commit e74e8ce

Browse files
authored
Merge pull request #2225 from gmittert/TookTimeToConnect
[Windows] Fix socket creation in Process.swift
2 parents 54c26b6 + 1944592 commit e74e8ce

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Foundation/Process.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,6 @@ open class Process: NSObject {
336336
return (first: INVALID_SOCKET, second: INVALID_SOCKET)
337337
}
338338

339-
var value: u_long = 1
340-
if ioctlsocket(first, FIONBIO, &value) == SOCKET_ERROR {
341-
closesocket(first)
342-
return (first: INVALID_SOCKET, second: INVALID_SOCKET)
343-
}
344-
345339
withUnsafePointer(to: &address) {
346340
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
347341
result = connect(first, $0, Int32(MemoryLayout<sockaddr_in>.size))
@@ -353,6 +347,12 @@ open class Process: NSObject {
353347
return (first: INVALID_SOCKET, second: INVALID_SOCKET)
354348
}
355349

350+
var value: u_long = 1
351+
if ioctlsocket(first, FIONBIO, &value) == SOCKET_ERROR {
352+
closesocket(first)
353+
return (first: INVALID_SOCKET, second: INVALID_SOCKET)
354+
}
355+
356356
let second: SOCKET = accept(listener, nil, nil)
357357
if second == INVALID_SOCKET {
358358
closesocket(first)

0 commit comments

Comments
 (0)