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

implement cancellation support for SendFileAsync and DisconnectAsync #53062

Merged
merged 3 commits into from
May 27, 2021

Conversation

geoffkizer
Copy link
Contributor

Also rework some internal async logic to support this and reduce code duplication.

Fixes #51452
Fixes #42591

@antonfirsov @stephentoub

… and rework some internal async logic to support this and reduce code duplication
@ghost
Copy link

ghost commented May 21, 2021

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Also rework some internal async logic to support this and reduce code duplication.

Fixes #51452
Fixes #42591

@antonfirsov @stephentoub

Author: geoffkizer
Assignees: -
Labels:

area-System.Net.Sockets

Milestone: -

@geoffkizer
Copy link
Contributor Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

/// <param name="overlapped">The overlapped that was used for this operation. Will be freed if the operation result will be handled synchronously.</param>
/// <param name="cancellationToken">The cancellation token to use to cancel the operation.</param>
/// <returns>The result status of the operation.</returns>
private unsafe SocketError ProcessIOCPResultWithCancellation(bool success, int bytesTransferred, NativeOverlapped* overlapped, CancellationToken cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this method is identical to the one above except that it doesn't do _singleBufferHandle = _buffer.Pin();? There's no way to consolidate them? Note that default(Memory<T>).Pin() should be very cheap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you're right. I will consolidate them.

I could either pass default(Memory) or make the param nullable and pass null here.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure how would it look by passing Memory as an arg, but it can be also a bool arg:

private unsafe SocketError ProcessIOCPResultWithCancellation(
    bool success, 
    int bytesTransferred,
    NativeOverlapped* overlapped,
    bool pinBuffer, // omit "_singleBufferHandle = _buffer.Pin();" if false
    CancellationToken cancellationToken)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to use this for cancellable Accept in the future, and I think that will work better if the buffer is passed in (it's not always just _buffer in the Accept case).

{
// Note: We need to dispose of the overlapped iff the operation completed synchronously,
// and if we do, we must do so before we mark the operation as completed.
// Note: We need to dispose of the overlapped iff the operation result will be handled synchronously.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Note: We need to dispose of the overlapped iff the operation result will be handled synchronously.
// Note: We need to dispose of the overlapped if the operation result will be handled synchronously.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually intentional. "iff" is a bit obscure, mostly used in math contexts. If you think it's too obscure I can change it.

https://www.merriam-webster.com/dictionary/iff

Copy link
Member

@antonfirsov antonfirsov May 25, 2021

Choose a reason for hiding this comment

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

Wasn't aware of this abbreviation, leave it as is, thanks for clarifying!

geoffkizer and others added 2 commits May 25, 2021 10:15
….Tasks.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
…OCPResultWithCancellation into single method
@geoffkizer
Copy link
Contributor Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@geoffkizer geoffkizer merged commit bb38de7 into dotnet:main May 27, 2021
@geoffkizer geoffkizer deleted the socketcancellation branch May 27, 2021 06:01
@geoffkizer geoffkizer mentioned this pull request May 27, 2021
14 tasks
@ghost ghost locked as resolved and limited conversation to collaborators Jun 26, 2021
@karelz karelz added this to the 6.0.0 milestone Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement cancellation support for DisconnectAsync Add Task-based async API for Socket.SendFile
4 participants