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

Comments from code review #55819

Merged
merged 4 commits into from
Jul 19, 2021
Merged
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
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