afd: use windows (and not winsock) error codes

This commit is contained in:
Bert Belder 2017-09-04 07:15:49 +02:00
parent e967c93dad
commit 1949b8f044
2 changed files with 13 additions and 38 deletions

View File

@ -18,7 +18,6 @@ int afd_poll(SOCKET socket, AFD_POLL_INFO* info, OVERLAPPED* overlapped) {
HANDLE event = NULL;
void* apc_context;
NTSTATUS status;
DWORD error;
if (overlapped != NULL) {
/* Overlapped operation. */
@ -37,9 +36,8 @@ int afd_poll(SOCKET socket, AFD_POLL_INFO* info, OVERLAPPED* overlapped) {
/* Blocking operation. */
iosb_ptr = &iosb;
event = CreateEventW(NULL, FALSE, FALSE, NULL);
if (event == NULL) {
return SOCKET_ERROR;
}
if (event == NULL)
return_error(-1);
apc_context = NULL;
}
@ -63,10 +61,9 @@ int afd_poll(SOCKET socket, AFD_POLL_INFO* info, OVERLAPPED* overlapped) {
DWORD r = WaitForSingleObject(event, INFINITE);
if (r == WAIT_FAILED) {
DWORD saved_error = GetLastError();
DWORD error = GetLastError();
CloseHandle(event);
WSASetLastError(saved_error);
return SOCKET_ERROR;
return_error(-1, error);
}
status = iosb_ptr->Status;
@ -75,25 +72,10 @@ int afd_poll(SOCKET socket, AFD_POLL_INFO* info, OVERLAPPED* overlapped) {
CloseHandle(event);
}
switch (status) {
case STATUS_SUCCESS:
error = ERROR_SUCCESS;
break;
case STATUS_PENDING:
error = WSA_IO_PENDING;
break;
default:
error = we_map_ntstatus_to_ws_error(status);
break;
}
WSASetLastError(error);
if (error == ERROR_SUCCESS) {
return 0;
} else {
return SOCKET_ERROR;
}
if (status == STATUS_SUCCESS)
return_success(0);
else if (status == STATUS_PENDING)
return_error(-1, ERROR_IO_PENDING);
else
return_error(-1, we_map_ntstatus_to_win_error(status));
}

View File

@ -345,7 +345,7 @@ int epoll_wait(epoll_t port_handle,
* is invalid. In this case we silently remove the socket from the
* epoll port. Other errors make epoll_wait() fail.
*/
if (WSAGetLastError() != WSAENOTSOCK)
if (GetLastError() == ERROR_INVALID_HANDLE)
return -1;
/* Skip to the next attention list item already, because we're about
@ -683,15 +683,8 @@ int epoll__submit_poll_req(epoll_port_data_t* port_data,
result =
afd_poll(sock_data->peer_sock, &io_req->poll_info, &io_req->overlapped);
if (result != 0) {
DWORD error = WSAGetLastError();
if (error != WSA_IO_PENDING) {
/* If this happens an error happened and no overlapped operation was
* started.
*/
return -1;
}
}
if (result != 0 && GetLastError() != ERROR_IO_PENDING)
return_error(-1);
sock_data->submitted_events = registered_events;
sock_data->io_req_generation = io_req->generation;