Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Assert for TlsHandler.MediationStream #51

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ partial class MediationStream

public void SetSource(in ReadOnlyMemory<byte> source)
{
Debug.Assert(SourceReadableBytes == 0);
_input = source;
_inputOffset = 0;
_inputLength = 0;
}

public void ResetSource()
{
Debug.Assert(SourceReadableBytes == 0);
_input = null;
_inputOffset = 0;
_inputLength = 0;
}

Expand All @@ -60,6 +63,7 @@ public void ExpandSource(int count)
if (sslBuffer.IsEmpty)
{
// there is no pending read operation - keep for future
Debug.Assert(_readCompletionSource == null);
Copy link
Collaborator Author

@yyjdelete yyjdelete May 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadAsync can also be called with zero length array, and it should be finished if any data is available.

Copy link
Owner

@cuteant cuteant May 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

真是仔细啊, 👍

return;
}
_sslOwnedBuffer = default;
Expand Down Expand Up @@ -87,6 +91,7 @@ public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken
return new ValueTask<int>(read);
}

Debug.Assert(_readCompletionSource == null);
Debug.Assert(_sslOwnedBuffer.IsEmpty);
// take note of buffer - we will pass bytes there once available
_sslOwnedBuffer = buffer;
Expand Down
3 changes: 3 additions & 0 deletions src/DotNetty.Handlers/Tls/TlsHandler.MediationStream.NetFx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ partial class MediationStream

public void SetSource(byte[] source, int offset)
{
Debug.Assert(SourceReadableBytes == 0);
_input = source;
_inputStartOffset = offset;
_inputOffset = 0;
Expand All @@ -53,7 +54,9 @@ public void SetSource(byte[] source, int offset)

public void ResetSource()
{
Debug.Assert(SourceReadableBytes == 0);
_input = null;
_inputOffset = 0;
_inputLength = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ partial class MediationStream

public void SetSource(byte[] source, int offset)
{
Debug.Assert(SourceReadableBytes == 0);
_input = source;
_inputStartOffset = offset;
_inputOffset = 0;
Expand All @@ -47,7 +48,9 @@ public void SetSource(byte[] source, int offset)

public void ResetSource()
{
Debug.Assert(SourceReadableBytes == 0);
_input = null;
_inputOffset = 0;
_inputLength = 0;
}

Expand Down