Repository navigation
Prefer SetHandleInformation to DuplicateHandle in set_close_on_exec - #907
Merged
smorimoto merged 1 commit intoDec 3, 2021
Merged
Conversation
smorimoto
approved these changes
Dec 2, 2021
Member
|
Could you check this as well @raphael-proust? |
From [DuplicateHandle][]: > You should not use `DuplicateHandle` to duplicate handles to the following objects: > > - […] > - Sockets. No error is returned, but the duplicate handle may not be > recognized by Winsock at the target process. Also, using > `DuplicateHandle` interferes with internal reference counting on > the underlying object. To duplicate a socket handle, use the > `WSADuplicateSocket` function. and from [Inheriting Handles][]: > Use the `SetHandleInformation` function to control if an existing > handle is inheritable or not. and from [SetHandleInformation][]: > You can specify a handle to one of the following types of objects: > […], socket, […]. So `DuplicateHandle` shouldn't be used on sockets, and it's safe to replace it with `SetHandleInformation`. [DuplicateHandle]: https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-duplicatehandle#remarks [Inheriting Handles]: https://docs.microsoft.com/en-us/windows/win32/procthread/inheritance#inheriting-handles [SetHandleinformation]: https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-sethandleinformation#parameters
smorimoto
force-pushed
the
windows-duplicate-handle-socket
branch
from
December 2, 2021 13:18
3b6c723 to
2878a05
Compare
Contributor
Author
|
Related to this PR: ocaml/ocaml#10697. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From DuplicateHandle:
and from Inheriting Handles:
and from SetHandleInformation:
So
DuplicateHandleshouldn't be used on sockets, and it's safe toreplace it with
SetHandleInformation.