Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WSA_FLAG_NO_HANDLE_INHERIT on Windows for cloexec sockets #910

Commits on Mar 28, 2022

  1. Windows: replace calls to socket with WSASocket

    The call to
    
        socket(domain, type, protocol);
    
    is equivalent to
    
        WSASocket(domain, type, protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
    
    the latter offering more (needed) control over the creation of
    sockets.
    MisterDA committed Mar 28, 2022
    Configuration menu
    Copy the full SHA
    1948bd7 View commit details
    Browse the repository at this point in the history
  2. Use WSA_FLAG_NO_HANDLE_INHERIT on Windows for cloexec sockets

    On Windows, in order to mark sockets non-inheritable (close-on-exec),
    it is sometimes not sufficient to use SetHandleInformation. There's
    some explanation why in [1] and [KB2398202].
    
    Introduced in the hotfix [KB2398202] and supported on Windows 7 with
    SP1, Windows Server 2008 R2 with SP1, and later, the flag
    WSA_FLAG_NO_HANDLE_INHERIT can be used with WSASocket to create a
    non-inheritable socket.
    
    We can still call SetHandleInformation to clear the inheritable flag
    on the socket in case the flag isn't supported (running on an early
    Windows Vista or 7).
    
    Related OCaml PR:
    - ocaml/ocaml#10809.
    
    [1]: https://stackoverflow.com/questions/12058911/can-tcp-socket-handles-be-set-not-inheritable
    [KB2398202]: https://support.microsoft.com/en-us/topic/an-application-may-stop-responding-when-the-application-closes-a-socket-connection-or-shuts-down-41321a1f-d80c-6975-98df-ae499d63133c
    MisterDA committed Mar 28, 2022
    Configuration menu
    Copy the full SHA
    e47ee13 View commit details
    Browse the repository at this point in the history