From bf5e17e5c5c09c80cbdce0f9a5e2e0623bf3a42e Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 16 Nov 2018 23:46:08 -0800 Subject: [PATCH] sock: avoid a syscall when cancelling already-completed poll operation --- src/sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sock.c b/src/sock.c index 4678cbb..79cef2d 100644 --- a/src/sock.c +++ b/src/sock.c @@ -53,7 +53,8 @@ static int sock__cancel_poll(sock_state_t* sock_state) { /* CancelIoEx() may fail with ERROR_NOT_FOUND if the overlapped operation has * already completed. This is not a problem and we proceed normally. */ - if (!CancelIoEx(afd_helper_handle, &sock_state->overlapped) && + if (!HasOverlappedIoCompleted(&sock_state->overlapped) && + !CancelIoEx(afd_helper_handle, &sock_state->overlapped) && GetLastError() != ERROR_NOT_FOUND) return_map_error(-1);