Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/GameFrameX.SuperSocket.Connection/PipeConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,13 @@ protected override bool IsIgnorableException(Exception e)
/// <param name="cancellationToken">A token to monitor for cancellation requests.</param>
/// <returns>The total number of bytes read.</returns>
protected abstract ValueTask<int> FillInputPipeWithDataAsync(Memory<byte> memory, CancellationToken cancellationToken);

/// <summary>
/// Cancels the pending read on the output pipe reader so the send loop unblocks immediately when the connection is being closed.
/// </summary>
protected override void CancelOutputPendingRead()
{
this.Output.Reader.CancelPendingRead();
}
}
}
8 changes: 8 additions & 0 deletions src/GameFrameX.SuperSocket.Connection/PipeConnectionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ protected async Task CancelAsync()

_cts.Cancel();
await CompleteWriterAsync(OutputWriter, _isDetaching).ConfigureAwait(false);
CancelOutputPendingRead();
}

/// <summary>
Expand Down Expand Up @@ -579,6 +580,13 @@ protected virtual async ValueTask CompleteWriterAsync(PipeWriter writer, bool is
await writer.CompleteAsync().ConfigureAwait(false);
}

/// <summary>
/// Cancels the pending read on the output pipe reader so that the send loop (<see cref="PipeConnection.ProcessSends"/>) blocked on <c>ReadAsync</c> returns promptly during connection shutdown.
/// </summary>
protected virtual void CancelOutputPendingRead()
{
}

internal struct BufferFilterResult<TPackageInfo>
{
public Exception Exception { get; set; }
Expand Down