Emulating socketPair on Windows
kazu-yamamoto opened this issue · 7 comments
@Misuke socketPair
call error
since Windows does not provide socketpair(2)
.
The following code could emulate socketPair
on Windows when we support AF_UNIX
.
What do you think?
sockpair :: IO (Socket, Socket)
sockpair = withSystemTempFile "temp-for-pair" $ \file hdl -> do
hClose hdl
removeFile file
listenSock <- socket AF_UNIX Stream defaultProtocol
bind listenSock $ SockAddrUnix file
listen listenSock 10
clientSock <- socket AF_UNIX Stream defaultProtocol
connect clientSock $ SockAddrUnix file
(serverSock, _) <- accept listenSock
close listenSock
return (clientSock, serverSock)
@Mistuke If you agree, I will implement socketPair
based on AF_UNIX
for Windows.
@kazu-yamamoto yeah that looks like a good workaround. Sorry I had missed that you had assigned this to me.
Can I clarify, is network-3.1.3.0
broken on Windows? I tried moving the Stack project from lts-20.21
(network-3.1.2.9
) to lts-20.22
(network-3.1.3.0
) and it now it fails to build with:
persistent-sqlite> ghc-9.2.7.exe: | C:\sr\snapshots\1cf8fbfe\lib\x86_64-windows-ghc-9.2.7\network-3.1.3.0-whnRyKC8v07Jg7Mne1eCa\HSnetwork-3.1.3.0-whnRyKC8v07Jg7Mne1eCa.o: unknown symbol `socketpair'
persistent-sqlite> ghc-9.2.7.exe: Could not load Object Code C:\sr\snapshots\1cf8fbfe\lib\x86_64-windows-ghc-9.2.7\network-3.1.3.0-whnRyKC8v07Jg7Mne1eCa\HSnetwork-3.1.3.0-whnRyKC8v07Jg7Mne1eCa.o.
persistent-sqlite>
persistent-sqlite> ghc-9.2.7.exe: unable to load unit `network-3.1.3.0'
Searching, I came across this issue.
@mpilgrem What about network-3.1.4.0?
@kazu-yamamoto, thanks - all good with network-3.1.4.0
. I'll wait for Stackage's LTS-20 series to catch up.
How did it happen though? c_socketpair
is only defined on !windows.
I'm also confused how the CI didn't catch it. Looks like the error is from the runtime linker, so I guess we didn't have a socketpair test?