@@ -81,6 +81,15 @@ static Expected<int> getSocketFD(StringRef SocketPath) {
81
81
" Create socket failed" );
82
82
}
83
83
84
+ #ifdef __CYGWIN__
85
+ // On Cygwin, UNIX sockets involve a handshake between connect and accept
86
+ // to enable SO_PEERCRED/getpeereid handling. This necessitates accept being
87
+ // called before connect can return, but at least the tests in
88
+ // llvm/unittests/Support/raw_socket_stream_test do both on the same thread
89
+ // (first connect and then accept), resulting in a deadlock. This call turns
90
+ // off the handshake (and SO_PEERCRED/getpeereid support).
91
+ setsockopt (Socket, SOL_SOCKET, SO_PEERCRED, NULL , 0 );
92
+ #endif
84
93
struct sockaddr_un Addr = setSocketAddr (SocketPath);
85
94
if (::connect (Socket, (struct sockaddr *)&Addr, sizeof (Addr)) == -1 )
86
95
return llvm::make_error<StringError>(getLastSocketErrorCode (),
@@ -147,6 +156,15 @@ Expected<ListeningSocket> ListeningSocket::createUnix(StringRef SocketPath,
147
156
return llvm::make_error<StringError>(getLastSocketErrorCode (),
148
157
" socket create failed" );
149
158
159
+ #ifdef __CYGWIN__
160
+ // On Cygwin, UNIX sockets involve a handshake between connect and accept
161
+ // to enable SO_PEERCRED/getpeereid handling. This necessitates accept being
162
+ // called before connect can return, but at least the tests in
163
+ // llvm/unittests/Support/raw_socket_stream_test do both on the same thread
164
+ // (first connect and then accept), resulting in a deadlock. This call turns
165
+ // off the handshake (and SO_PEERCRED/getpeereid support).
166
+ setsockopt (Socket, SOL_SOCKET, SO_PEERCRED, NULL , 0 );
167
+ #endif
150
168
struct sockaddr_un Addr = setSocketAddr (SocketPath);
151
169
if (::bind (Socket, (struct sockaddr *)&Addr, sizeof (Addr)) == -1 ) {
152
170
// Grab error code from call to ::bind before calling ::close
0 commit comments