dcd.common.messages: Fix spurious "Could not unpack the response" errors

recv() is allowed to return less than the indicated buffer size, even
when more data may still become available. Exiting the read loop on
such conditions caused fragmented responses to be partially read, then
failing to decode. To read the entire response, we need to keep
reading until the connection is properly closed (recv() returns zero).
This commit is contained in:
Vladimir Panteleev 2019-01-05 19:48:13 +00:00
parent a163e33beb
commit d5e919f4cb
No known key found for this signature in database
GPG Key ID: 5004F0FAD051576D
1 changed files with 1 additions and 1 deletions

View File

@ -220,7 +220,7 @@ AutocompleteResponse getResponse(Socket socket)
if (bytesReceived == 0) if (bytesReceived == 0)
break; break;
unpacker.feed(buffer[0..bytesReceived]); unpacker.feed(buffer[0..bytesReceived]);
} while (bytesReceived == buffer.length); } while (true);
if (unpacker.size == 0) if (unpacker.size == 0)
throw new Exception("Server closed the connection, 0 bytes received"); throw new Exception("Server closed the connection, 0 bytes received");