Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Http/Streams/HttpWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ internal HttpWebSocket ( HttpServerEngineWebSocket ctx, HttpRequest req, string?
private async ValueTask<WebSocketMessage?> ReceiveInternalAsync ( CancellationToken cancellation ) {
ArraySegment<byte> buffer = new ArraySegment<byte> ( receiveBuffer );
ValueWebSocketReceiveResult result;
long maxMessageLength = request.baseServer.ServerConfiguration.MaximumContentLength <= 0
? Int32.MaxValue
: request.baseServer.ServerConfiguration.MaximumContentLength;

if (IsClosed)
return null;
Expand All @@ -137,6 +140,11 @@ internal HttpWebSocket ( HttpServerEngineWebSocket ctx, HttpRequest req, string?

do {
result = await ctx.ReceiveAsync ( buffer, cancellation );
if ((ms.Length + result.Count) > maxMessageLength) {
await ctx.CloseOutputAsync ( WebSocketCloseStatus.MessageTooBig, null, cancellation );
await CloseAsync ( cancellation );
return null;
}
ms.Write ( buffer.Array!, buffer.Offset, result.Count );
} while (!result.EndOfMessage);

Expand Down
6 changes: 5 additions & 1 deletion src/Http/Streams/HttpWebSocketConnectionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal void RegisterWebSocket ( HttpWebSocket src ) {
// close another websockets with same identifier
HttpWebSocket [] wsId = Find ( s => s == src._identifier );
foreach (HttpWebSocket ws in wsId) {
_ws.Remove ( ws );
ws.Dispose ();
}
_ws.Add ( src );
Expand Down Expand Up @@ -96,7 +97,10 @@ public HttpWebSocket [] All () {
/// </summary>
public void DropAll () {
lock (_ws) {
foreach (HttpWebSocket es in _ws)
HttpWebSocket [] allWs = _ws.ToArray ();
_ws.Clear ();

foreach (HttpWebSocket es in allWs)
es.Dispose ();
}
}
Expand Down
Loading