Skip to content

Commit

Permalink
Comments from code review (#55819)
Browse files Browse the repository at this point in the history
* Comments

* Update src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicStream.cs

* Update src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicStream.cs

Co-authored-by: Natalia Kondratyeva <knatalia@microsoft.com>

Co-authored-by: Natalia Kondratyeva <knatalia@microsoft.com>
  • Loading branch information
ManickaP and CarnaViire authored Jul 19, 2021
1 parent b5ef659 commit 1d14423
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal sealed class MsQuicStream : QuicStreamProvider
// Delegate that wraps the static function that will be called when receiving an event.
internal static readonly StreamCallbackDelegate s_streamDelegate = new StreamCallbackDelegate(NativeCallbackHandler);

// The state is passed to msquic and then it's passed back by msquic to the callback handler.
private readonly State _state = new State();

private readonly bool _canRead;
Expand All @@ -31,6 +32,8 @@ internal sealed class MsQuicStream : QuicStreamProvider
private sealed class State
{
public SafeMsQuicStreamHandle Handle = null!; // set in ctor.
// Roots the state in GC and it won't get collected while this exist.
// It must be kept alive until we receive SHUTDOWN_COMPLETE event
public GCHandle StateGCHandle;

public MsQuicStream? Stream; // roots the stream in the pinned state to prevent GC during an async read I/O.
Expand Down Expand Up @@ -71,6 +74,7 @@ private sealed class State
public readonly TaskCompletionSource ShutdownWriteCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

public ShutdownState ShutdownState;
// The value makes sure that we release the handles only once.
public int ShutdownDone;

// Set once stream have been shutdown.
Expand Down Expand Up @@ -769,6 +773,10 @@ private void EnableReceive()
QuicExceptionHelpers.ThrowIfFailed(status, "StreamReceiveSetEnabled failed.");
}

/// <summary>
/// Callback calls for a single instance of a stream are serialized by msquic.
/// They happen on a msquic thread and shouldn't take too long to not to block msquic.
/// </summary>
private static uint NativeCallbackHandler(
IntPtr stream,
IntPtr context,
Expand Down

0 comments on commit 1d14423

Please sign in to comment.