diff --git a/src/common/base.cpp b/src/common/base.cpp index 57d08592da60db2b28624127fedf6435d62fc9c1..02f9832f5ecbcaf57527f5443271f2de70ce698e 100644 --- a/src/common/base.cpp +++ b/src/common/base.cpp @@ -2325,12 +2325,23 @@ void CloseOpenFd(void) DWORD bytesRead = 0; OVERLAPPED ov = {}; SOCKET s = fd; - BOOL bWriteStat = ReadFile((HANDLE)s, buf, count, &bytesRead, &ov); - if (bWriteStat) { + BOOL bRead = ReadFile((HANDLE)s, buf, count, &bytesRead, &ov); + if (bRead) { return bytesRead; - } else { + } + DWORD error = GetLastError(); + if (error != ERROR_IO_PENDING) { + WRITE_LOG(LOG_DEBUG, "ReadFile error:%d", error); return -1; } + constexpr int ms = 3000; + bRead = GetOverlappedResultEx((HANDLE)s, &ov, &bytesRead, ms, FALSE); + if (bRead) { + return bytesRead; + } + error = GetLastError(); + WRITE_LOG(LOG_DEBUG, "read GetOverlappedResult error:%d", error); + return -1; #else return TEMP_FAILURE_RETRY(read(fd, buf, count)); #endif @@ -2342,12 +2353,23 @@ void CloseOpenFd(void) DWORD bytesWrite = 0; OVERLAPPED ov = {}; SOCKET s = fd; - BOOL bWriteStat = WriteFile((HANDLE)s, buf, count, &bytesWrite, &ov); - if (bWriteStat) { + BOOL bWrite = WriteFile((HANDLE)s, buf, count, &bytesWrite, &ov); + if (bWrite) { return 1; - } else { + } + DWORD error = GetLastError(); + if (error != ERROR_IO_PENDING) { + WRITE_LOG(LOG_DEBUG, "WriteFile error:%d", error); return -1; } + constexpr int ms = 3000; + bWrite = GetOverlappedResultEx((HANDLE)s, &ov, &bytesWrite, ms, FALSE); + if (bWrite) { + return 1; + } + error = GetLastError(); + WRITE_LOG(LOG_DEBUG, "write GetOverlappedResult error:%d", error); + return -1; #else return TEMP_FAILURE_RETRY(write(fd, buf, count)); #endif