Skip to content

Commit 8419393

Browse files
committed
Process: disable Nagle on Windows
Windows does not have a native `socketpair` interface and so we emulate that locally. Furthermore, the use of `socketpair` on the other platforms uses an `AF_UNIX` (Unix Domain Socket) which is not guaranteed to be available on Windows. As a result, we workaround that by using an `AF_INET` address family socket. This will by default have Nagle enabled which can potentially cause some delays when processing a message. We have observed occasional hangs in the process handling which may be possibly be attributed to the buffering. Disable nagle on the sender side in the hopes of a more reliable connection.
1 parent f3f3a73 commit 8419393

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/Foundation/Process.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,13 @@ open class Process: NSObject {
452452
return (first: INVALID_SOCKET, second: INVALID_SOCKET)
453453
}
454454

455+
var option: CInt = 1
456+
if setsockopt(first, IPPROTO_TCP.rawValue, TCP_NODELAY, &option,
457+
CInt(MemoryLayout.size(ofValue: option))) == SOCKET_ERROR {
458+
closesocket(first)
459+
return (first: INVALID_SOCKET, second: INVALID_SOCKET)
460+
}
461+
455462
let second: SOCKET = accept(listener, nil, nil)
456463
if second == INVALID_SOCKET {
457464
closesocket(first)

0 commit comments

Comments
 (0)