Auto merge of #4216 - str4d:4214-windows-fix, r=mdr0id

Cast uint8* in InterruptibleRecv to char* for recv

Fixes a Windows-specific compile bug introduced in #4212.
Closes #4214.
This commit is contained in:
Homu 2019-11-11 10:52:47 -08:00
commit f859ae0067
1 changed files with 7 additions and 1 deletions

View File

@ -254,7 +254,13 @@ bool static InterruptibleRecv(uint8_t* data, size_t len, int timeout, SOCKET& hS
// to break off in case of an interruption.
const int64_t maxWait = 1000;
while (len > 0 && curTime < endTime) {
ssize_t ret = recv(hSocket, data, len, 0); // Optimistically try the recv first
// Optimistically try the recv first.
//
// POSIX recv() does not require a cast, as it takes a void *buf:
// ssize_t recv(int sockfd, void *buf, size_t len, int flags);
// However Windows explicitly requires a char *buf:
// int recv(SOCKET s, char *buf, int len, int flags);
ssize_t ret = recv(hSocket, reinterpret_cast<char*>(data), len, 0);
if (ret > 0) {
len -= ret;
data += ret;