diff options
author | B. Stack <bgstack15@gmail.com> | 2023-07-24 15:08:16 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2023-07-24 15:08:16 -0400 |
commit | 69e12f5bd10459ff7c239b82519107ae2a755bc0 (patch) | |
tree | 8b22393241df7e46686c9426140582bd747a6d5a /zen/socket.h | |
parent | add upstream 12.4 (diff) | |
download | FreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.tar.gz FreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.tar.bz2 FreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.zip |
add upstream 12.5
Diffstat (limited to 'zen/socket.h')
-rw-r--r-- | zen/socket.h | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/zen/socket.h b/zen/socket.h index f706daab..c2fdb145 100644 --- a/zen/socket.h +++ b/zen/socket.h @@ -59,7 +59,6 @@ std::wstring formatGaiErrorCode(int ec) using SocketType = int; const SocketType invalidSocket = -1; inline void closeSocket(SocketType s) { ::close(s); } -warn_static("log on error!") void setNonBlocking(SocketType socket, bool value); //throw SysError @@ -194,8 +193,7 @@ size_t tryReadSocket(SocketType socket, void* buffer, size_t bytesToRead) //thro if (bytesReceived < 0) THROW_LAST_SYS_ERROR_WSA("recv"); - if (static_cast<size_t>(bytesReceived) > bytesToRead) //better safe than sorry - throw SysError(formatSystemError("recv", L"", L"Buffer overflow.")); + ASSERT_SYSERROR(makeUnsigned(bytesReceived) <= bytesToRead); //better safe than sorry return bytesReceived; //"zero indicates end of file" } @@ -218,11 +216,12 @@ size_t tryWriteSocket(SocketType socket, const void* buffer, size_t bytesToWrite } if (bytesWritten < 0) THROW_LAST_SYS_ERROR_WSA("send"); - if (bytesWritten > static_cast<int>(bytesToWrite)) - throw SysError(formatSystemError("send", L"", L"Buffer overflow.")); + if (bytesWritten == 0) throw SysError(formatSystemError("send", L"", L"Zero bytes processed.")); + ASSERT_SYSERROR(makeUnsigned(bytesWritten) <= bytesToWrite); //better safe than sorry + return bytesWritten; } } |