3 ms·
To elaborate on this: I figured out the dup2 part of the solution a long time ago, but I was stuck on "how do we make sure the descriptor we closed is the one w
by cperciva 7y ago
To elaborate on this: I figured out the dup2 part of the solution a long time ago, but I was stuck on "how do we make sure the descriptor we closed is the one we dup2ed and not a different one"; the obvious answer of using stat only works if you can create a sentinel file.
So really the hard part was realizing that you can use MSG_PEEK since it's guaranteed to not have side effects (and with a random cookie can be used to identify whether a descriptor is "our" socket).