Skip to content

preserve errno/GetLastError() in bsd_close_socket() so as not to thash errors raised by listen() etc.#254

Open
georg-emg wants to merge 1 commit into
uNetworking:masterfrom
xentara:preserve-error-on-socket-close
Open

preserve errno/GetLastError() in bsd_close_socket() so as not to thash errors raised by listen() etc.#254
georg-emg wants to merge 1 commit into
uNetworking:masterfrom
xentara:preserve-error-on-socket-close

Conversation

@georg-emg

Copy link
Copy Markdown

When an error occurrs in many operations, the function bsd_close_socket() is called to close the socket before returning an error code. Unfortunately, the call to close()/closesocket() inside bsd_close_socket() will overwrite the value of errno/GetLastError(), making it difficult to determine the original error. For example, if I try to listen on a port that is already in use, the error (EADDRINUSE) get thrashed by the call to bsd_close_socket(), making it pretty much impossible to output/log the correct error.

This small PR saves the value of errno/GetLastError() inside bsd_close_coket() before calling close()/closesocket(), and restores it afterwards. This allows the error raised by the actual action (e.g. listen()) to be read by the caller.

NOTE: We submitted a pull request for this some time ago ( #196), but I think something went wrong there. I rebased the change on the latest revision and am creating a new PR. #196 is defunct and can be closed. Sorry about that.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant