feat: bump max receive size to 1 MiB

This commit is contained in:
Anna 2022-07-30 00:37:06 -04:00
parent 1854c165d4
commit 6649efc232
1 changed files with 7 additions and 6 deletions

View File

@ -16,19 +16,20 @@ public static class Ext {
}
public static async Task<ResponseContainer> ReceiveMessage(this ClientWebSocket client) {
var bytes = new ArraySegment<byte>(new byte[2048]);
var bytes = new List<byte>(2048);
var buffer = new ArraySegment<byte>(new byte[2048]);
WebSocketReceiveResult result;
var i = 0;
do {
result = await client.ReceiveAsync(bytes[i..], CancellationToken.None);
i += result.Count;
result = await client.ReceiveAsync(buffer, CancellationToken.None);
bytes.AddRange(buffer[..result.Count]);
if (i >= bytes.Count) {
// 1 MiB
if (bytes.Count > 1_048_576) {
throw new Exception();
}
} while (!result.EndOfMessage);
return MessagePackSerializer.Deserialize<ResponseContainer>(bytes[..i]);
return MessagePackSerializer.Deserialize<ResponseContainer>(bytes.ToArray());
}
}