Skip to content

Commit

Permalink
Add BeginRead/BeginWrite/EndRead/EndWrite overloads back to SslStream…
Browse files Browse the repository at this point in the history
… and underlying implementation. Unlike the default implementation in Stream it allows parallel read along with parallel write using the standard TaskToApm pattern (dotnet/runtime#33447). This reverts part of mono#17393 which could lead to deadlocks as reported in mono#18865.
  • Loading branch information
filipnavara authored and monojenkins committed Apr 8, 2020
1 parent 165f4b0 commit a6ff33e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,26 @@ public override Task WriteAsync (byte[] buffer, int offset, int count, Cancellat
return StartOperation (OperationType.Write, asyncRequest, cancellationToken);
}

public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return TaskToApm.Begin (ReadAsync (buffer, offset, count), callback, state);
}

public override int EndRead (IAsyncResult asyncResult)
{
return TaskToApm.End<int> (asyncResult);
}

public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return TaskToApm.Begin (WriteAsync (buffer, offset, count), callback, state);
}

public override void EndWrite (IAsyncResult asyncResult)
{
TaskToApm.End (asyncResult);
}

public bool CanRenegotiate {
get {
CheckThrow (true);
Expand Down
20 changes: 20 additions & 0 deletions mcs/class/System/System.Net.Security/SslStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,26 @@ public override Task WriteAsync (byte[] buffer, int offset, int count, Cancellat
return Impl.WriteAsync (buffer, offset, count, cancellationToken);
}

public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
{
return Impl.BeginRead (buffer, offset, count, asyncCallback, asyncState);
}

public override int EndRead (IAsyncResult asyncResult)
{
return Impl.EndRead (asyncResult);
}

public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
{
return Impl.BeginWrite (buffer, offset, count, asyncCallback, asyncState);
}

public override void EndWrite (IAsyncResult asyncResult)
{
Impl.EndWrite (asyncResult);
}

#else // !SECURITY_DEP
const string EXCEPTION_MESSAGE = "System.Net.Security.SslStream is not supported on the current platform.";

Expand Down

0 comments on commit a6ff33e

Please sign in to comment.