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

WSA functions should be marked SetLastError where appropriate #1594

Closed
ansteele opened this issue Jun 20, 2023 · 4 comments
Closed

WSA functions should be marked SetLastError where appropriate #1594

ansteele opened this issue Jun 20, 2023 · 4 comments
Assignees
Labels
usability Touch-up to improve the user experience for a language projection

Comments

@ansteele
Copy link

Hello,

Many WSA functions call WSASetLastError as a means of returning error information.
I believe WSASet/GetLastError is simply an alias of the regular Set/GetLastError therefore it would make sense that WSA functions be marked as SetLastError = true.

Many thanks

@mikebattista mikebattista added the usability Touch-up to improve the user experience for a language projection label Jun 29, 2023
@mikebattista mikebattista self-assigned this Jun 29, 2023
@riverar
Copy link
Collaborator

riverar commented Jul 11, 2023

I was suspicious of this, so took a peek under the hood and, well, see for yourself. 😂

int __stdcall WSAGetLastError()
{
  return GetLastError();
}

void __stdcall WSASetLastError(int iError)
{
  SetLastError(iError);
}

@ChrisDenton
Copy link
Contributor

Aye, see also WSAWaitForMultipleEvents, WSASetEvent and probably others too. On the one hand it's possible they'd want to reserve the right to change it again the future. On the other hand I wouldn't be surprised if people have come to rely on it.

@riverar
Copy link
Collaborator

riverar commented Jul 11, 2023

Thankfully only NEMA 10-30 folks use winsock. 😂

image

@riverar
Copy link
Collaborator

riverar commented Jul 11, 2023

For those interested, I dug through some very old documentation and here are some clarifying details:

The use of the WSAGetLastError() function to retrieve the last error code, rather than relying on a global error variable (cf. errno), is required in order to provide compatibility with future multi-threaded environments.

Note that in a Win16 environment WSAGetLastError() is used to retrieve only Windows Sockets API errors. In a Win32 environment, WSAGetLastError() will invoke GetLastError(), which is used to retrieve the error status for all Win32 API functions on a per-thread basis. For portability, an application should use WSAGetLastError() immediately after the Windows Sockets API function which failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability Touch-up to improve the user experience for a language projection
Projects
None yet
Development

No branches or pull requests

4 participants