Big msgpack woes (#448)

Big msgpack woes
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
LemonBoy 2018-03-10 20:57:52 +01:00 committed by The Dlang Bot
parent a6804db037
commit ea15ae4c15
1 changed files with 21 additions and 10 deletions

View File

@ -129,7 +129,7 @@ struct AutocompleteResponse
/** /**
* The kind of the item. Will be char.init for calltips. * The kind of the item. Will be char.init for calltips.
*/ */
char kind; ubyte kind;
/** /**
* Definition for a symbol for a completion including attributes or the arguments for calltips. * Definition for a symbol for a completion including attributes or the arguments for calltips.
*/ */
@ -149,7 +149,7 @@ struct AutocompleteResponse
deprecated("Use identifier (or definition for calltips) instead") string compatibilityContent() const deprecated("Use identifier (or definition for calltips) instead") string compatibilityContent() const
{ {
if (kind == char.init) if (kind == ubyte.init)
return definition; return definition;
else else
return identifier; return identifier;
@ -241,15 +241,26 @@ bool sendRequest(Socket socket, AutocompleteRequest request)
*/ */
AutocompleteResponse getResponse(Socket socket) AutocompleteResponse getResponse(Socket socket)
{ {
ubyte[1024 * 24] buffer; ubyte[1024 * 16] buffer;
auto bytesReceived = socket.receive(buffer); ptrdiff_t bytesReceived = 0;
auto unpacker = StreamingUnpacker([]);
do {
bytesReceived = socket.receive(buffer);
if (bytesReceived == Socket.ERROR) if (bytesReceived == Socket.ERROR)
throw new Exception(lastSocketError); throw new Exception(lastSocketError);
if (bytesReceived == 0) if (bytesReceived == 0)
break;
unpacker.feed(buffer[0..bytesReceived]);
} while (bytesReceived == buffer.length);
if (unpacker.size == 0)
throw new Exception("Server closed the connection, 0 bytes received"); throw new Exception("Server closed the connection, 0 bytes received");
AutocompleteResponse response;
msgpack.unpack(buffer[0..bytesReceived], response); if (!unpacker.execute())
return response; throw new Exception("Could not unpack the response");
return unpacker.purge().value.as!AutocompleteResponse;
} }
/** /**