Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Common/Cpp/Sockets/ClientSocket_WinSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ size_t ClientSocket_WinSocket::send(const void* data, size_t bytes, std::chrono:
int current = (int)std::min<size_t>(bytes, BLOCK_SIZE);
int current_sent = ::send(socket, ptr, current, 0);
if (current_sent != SOCKET_ERROR){
// A partial send is not an error: advance and keep looping
// until everything is written or the deadline/state ends
// the send, the same way the POSIX and Qt backends do.
sent += current_sent;
if (current_sent != current){
return sent;
}
ptr += current_sent;
bytes -= current_sent;
continue;
Expand Down
8 changes: 7 additions & 1 deletion Common/Cpp/Sockets/ServerSocket_WinSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <chrono>
#include <thread>
#include <iostream>
#include <algorithm>
#include <winsock2.h>
#include "Common/Cpp/Concurrency/ThreadPool.h"
#include "ServerSocket_WinSocket.h"
Expand Down Expand Up @@ -191,7 +192,12 @@ size_t ServerSocket_WinSocket::send(const void* data, size_t bytes, std::chrono:
return sent;
}

int current_sent = ::send(socket, ptr, (int)bytes, 0);
// "::send" takes an "int" length, so chunk the send the same
// way the WinSocket client does; sending a payload larger than
// 2 GiB in one call would wrap the length negative.
constexpr size_t BLOCK_SIZE = (size_t)1 << 30;
const int current = (int)std::min<size_t>(bytes, BLOCK_SIZE);
int current_sent = ::send(socket, ptr, current, 0);
if (current_sent != SOCKET_ERROR){
sent += (size_t)current_sent;
ptr += current_sent;
Expand Down
Loading