X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fwindows%2Fos-socket.h;h=5174cba1aaa5e5db4535a345a844c10d005d47b2;hb=ebefc26c10d68ba9ced2a30c896dccc81c6c2eeb;hp=5ea9c492491774a9acb2cb64cee445a1f67af066;hpb=642daae3aeaea71ee0e2444ee5ac46fe760a5b2b;p=deb_libcec.git diff --git a/src/lib/platform/windows/os-socket.h b/src/lib/platform/windows/os-socket.h index 5ea9c49..5174cba 100644 --- a/src/lib/platform/windows/os-socket.h +++ b/src/lib/platform/windows/os-socket.h @@ -34,7 +34,6 @@ #include "../os.h" #include "../util/timeutils.h" -#pragma comment(lib, "Ws2_32.lib") #include #include #include @@ -148,7 +147,7 @@ namespace PLATFORM ssize_t iReturn = send(socket, (char*)data, (int)len, 0); if (iReturn < (ssize_t)len) - *iError = errno; + *iError = GetSocketError(); return iReturn; } @@ -185,19 +184,28 @@ namespace PLATFORM FD_SET(socket, &fd_read); if (select((int)socket + 1, &fd_read, NULL, NULL, &tv) == 0) + { + *iError = ETIMEDOUT; return ETIMEDOUT; + } TcpSocketSetBlocking(socket, false); } ssize_t iReadResult = (iTimeoutMs > 0) ? - recv(socket, (char*)data + iBytesRead, (int)(len - iBytesRead), MSG_WAITALL) : + recv(socket, (char*)data + iBytesRead, (int)(len - iBytesRead), 0) : recv(socket, (char*)data, (int)len, MSG_WAITALL); *iError = GetSocketError(); + + if (iTimeoutMs > 0) + { + TcpSocketSetBlocking(socket, true); + iNow = GetTimeMs(); + } + if (iReadResult < 0) { - if (errno == EAGAIN && iTimeoutMs > 0) + if (*iError == EAGAIN && iTimeoutMs > 0) continue; - *iError = errno; return -1; } else if (iReadResult == 0 || (iReadResult != (ssize_t)len && iTimeoutMs == 0)) @@ -207,14 +215,12 @@ namespace PLATFORM } iBytesRead += iReadResult; - - if (iTimeoutMs > 0) - { - TcpSocketSetBlocking(socket, true); - iNow = GetTimeMs(); - } } - return 0; + + if (iBytesRead < (ssize_t)len && *iError == 0) + *iError = ETIMEDOUT; + + return iBytesRead; } inline bool TcpResolveAddress(const char *strHost, uint16_t iPort, int *iError, struct addrinfo **info) @@ -280,7 +286,7 @@ namespace PLATFORM } else { - *iError = errno; + *iError = GetSocketError(); } }