Skip to content

Commit

Permalink
Fixed Socket.read possible failure if not all can be read at once
Browse files Browse the repository at this point in the history
  • Loading branch information
aslze committed May 16, 2024
1 parent 073d576 commit 81e9c9c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,25 +581,29 @@ String Socket_::readLine()

int Socket_::read(void* data, int size)
{
if(_blocking) {
int s = 0;
do {
if (_blocking)
{
int s = 0, size0 = size;
do
{
#ifdef _WIN32
int n = recv(_handle, (char*)data, size, 0);
#else
int n = ::read(_handle, (char*)data, size);
#endif
if (n <= 0) {
if (n <= 0)
{
_error = SOCKET_BAD_RECV;
break;
}
data = (char*)data + n;
s += n;
size -= n;
} while (s < size);
} while (s < size0);
return s;
}
else {
else
{
#ifdef _WIN32
return recv(_handle, (char*)data, size, 0);
#else
Expand Down

0 comments on commit 81e9c9c

Please sign in to comment.