Skip to content

Commit

Permalink
improved the masking for empty package
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Aug 30, 2024
1 parent 3343067 commit acb215a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/SuperSocket.WebSocket/WebSocketEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ private int EncodeFinalFragment(IBufferWriter<byte> writer, byte opCode, ReadOnl
{
var totalWritten = 0;

// writer should not be touched for now, because head has not been written yet.
encodingContext = CreateDataEncodingContext(null);

if (encoder != null)
{
// writer should not be touched for now, because head has not been written yet.
encodingContext = CreateDataEncodingContext(null);

var fragementSize = (text.Length > 0 ? encoder.GetByteCount(text, true) : 0) + unwrittenBytes.Count;

if (fragementSize == 0)
Expand Down
8 changes: 2 additions & 6 deletions src/SuperSocket.WebSocket/WebSocketMaskedEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ protected override object CreateDataEncodingContext(IBufferWriter<byte> writer)

protected override Span<byte> WriteHead(IBufferWriter<byte> writer, long length, out int headLen)
{
var head = base.WriteHead(writer, length, out headLen);

// We don't mask data for empty package
if (length > 0)
head[1] = (byte)(head[1] | 0x80);

var head = base.WriteHead(writer, length, out headLen);
head[1] = (byte)(head[1] | 0x80);
return head;
}

Expand Down

0 comments on commit acb215a

Please sign in to comment.