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

bsd_close_socket preserves the error code #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,17 @@ LIBUS_SOCKET_DESCRIPTOR bsd_create_socket(int domain, int type, int protocol) {
}

void bsd_close_socket(LIBUS_SOCKET_DESCRIPTOR fd) {
// errno is rewritten by close(fd), and the actual error number is lost.
#ifdef _WIN32
DWORD error;
error = GetLastError();
closesocket(fd);
SetLastError(error);
#else
int error;
error = errno;
close(fd);
errno = error;
#endif
}

Expand Down