From 1949b8f0446c4ca9b352a7437580bf263052013c Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 4 Sep 2017 07:15:49 +0200 Subject: [PATCH] afd: use windows (and not winsock) error codes --- src/afd.c | 38 ++++++++++---------------------------- src/epoll.c | 13 +++---------- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/afd.c b/src/afd.c index b0bd09c..82c6572 100644 --- a/src/afd.c +++ b/src/afd.c @@ -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)); } diff --git a/src/epoll.c b/src/epoll.c index e4d6b25..9844857 100644 --- a/src/epoll.c +++ b/src/epoll.c @@ -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;