Skip to content

Emulating socketPair on Windows #550

Description

@kazu-yamamoto

@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)

Activity

  1. kazu-yamamoto commented on May 17, 2023

    @kazu-yamamoto
    CollaboratorAuthor

    @Mistuke If you agree, I will implement socketPair based on AF_UNIX for Windows.

  2. Mistuke commented on May 18, 2023

    @Mistuke
    Collaborator

    @kazu-yamamoto yeah that looks like a good workaround. Sorry I had missed that you had assigned this to me.

  3. mpilgrem commented on May 24, 2023

    @mpilgrem
    Contributor

    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.

  4. kazu-yamamoto commented on May 25, 2023

    @kazu-yamamoto
    CollaboratorAuthor

    @mpilgrem What about network-3.1.4.0?

  5. mpilgrem commented on May 25, 2023

    @mpilgrem
    Contributor

    @kazu-yamamoto, thanks - all good with network-3.1.4.0. I'll wait for Stackage's LTS-20 series to catch up.

  6. Mistuke commented on May 25, 2023

    @Mistuke
    Collaborator

    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?

  7. kazu-yamamoto commented on May 26, 2023

    @kazu-yamamoto
    CollaboratorAuthor

    @mpilgrem Nice! Sorry for your inconvenience.
    @Mistuke I guess #556 fixes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions