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

[API Proposal]: Add Ping.SendPingAsync overloads with CancellationToken #67260

Closed
deeprobin opened this issue Mar 28, 2022 · 9 comments · Fixed by #72338
Closed

[API Proposal]: Add Ping.SendPingAsync overloads with CancellationToken #67260

deeprobin opened this issue Mar 28, 2022 · 9 comments · Fixed by #72338
Labels
api-approved API was approved in API review, it can be implemented area-System.Net help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@deeprobin
Copy link
Contributor

deeprobin commented Mar 28, 2022

Background and motivation

This was already approved in #14336, but reverted in #67253 because this requires some more work.

See #64860 (comment)

API Proposal

namespace System.Net.NetworkInformation {
    public class Ping {
        public Task<PingReply> SendPingAsync(IPAddress address, TimeSpan timeout, byte[]? buffer = null, PingOptions? options = null, CancellationToken cancellationToken = default);
        public Task<PingReply> SendPingAsync(string hostNameOrAddress, TimeSpan timeout, byte[]? buffer = null, PingOptions? options = null, CancellationToken cancellationToken = default);
    }
}

/cc @danmoseley
/cc @stephentoub

@deeprobin deeprobin added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Mar 28, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Net untriaged New issue has not been triaged by the area owner labels Mar 28, 2022
@ghost
Copy link

ghost commented Mar 28, 2022

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

Issue Details

Background and motivation

This was already approved in #14336, but reverted in #67253 because this requires some more work.

See #64860 (comment)

API Proposal

namespace System.Net.NetworkInformation {
    public class Ping {
       public Task<PingReply> SendPingAsync(IPAddress address, TimeSpan timeout, byte[]? buffer, PingOptions? options, CancellationToken cancellationToken);
       public Task<PingReply> SendPingAsync(string hostNameOrAddress, TimeSpan timeout, byte[]? buffer, PingOptions? options, CancellationToken cancellationToken);
    }
}

API Usage

Alternative Designs

No response

Risks

No response

Author: deeprobin
Assignees: -
Labels:

api-suggestion, area-System.Net, untriaged

Milestone: -

@danmoseley danmoseley added api-approved API was approved in API review, it can be implemented and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Mar 28, 2022
@danmoseley
Copy link
Member

Updated to match what was approved.

@danmoseley danmoseley added the help wanted [up-for-grabs] Good issue for external contributors label Mar 28, 2022
@deeprobin
Copy link
Contributor Author

@danmoseley Thanks. I removed the trailing +. Can you remove the untriaged label?

@danmoseley danmoseley removed the untriaged New issue has not been triaged by the area owner label Mar 28, 2022
@teo-tsirpanis
Copy link
Contributor

teo-tsirpanis commented Mar 28, 2022

How about returning ValueTask or accepting Memory<byte>? In the latter case PingReply.Buffer might need taking a look at. I haven't understood whether it contains the original buffer passed to the method. If it does, we can ignore it when constructing the resulting ping reply.

namespace System.Net.NetworkInformation;

public class Ping {
    public ValueTask<PingReply> SendPingAsync(IPAddress address, TimeSpan timeout, Memoty<byte> buffer = default, PingOptions? options = null, CancellationToken cancellationToken = default);
    public ValueTask<PingReply> SendPingAsync(string hostNameOrAddress, TimeSpan timeout, Memory<byte> buffer = default, PingOptions? options = null, CancellationToken cancellationToken = default);
}

@rhuijben
Copy link

rhuijben commented May 8, 2022

Ping will almost always wait, so I think Task<> is fine. No need to optimize the no wait case

@MihaZupan MihaZupan added this to the Future milestone Jun 6, 2022
@sakno
Copy link
Contributor

sakno commented Jun 8, 2022

IMO, this proposal can be combined with #34856

@deeprobin
Copy link
Contributor Author

@sakno Could be. But this is already approved and #34856 is not.

@madelson
Copy link
Contributor

I have some interest in working on this.

One thought: could TimeSpan timeout be changed to TimeSpan? timeout = null? This would allow you to fall back to the default timeout as is possible with the int timeout APIs.

@deeprobin
Copy link
Contributor Author

deeprobin commented Jul 15, 2022

I have some interest in working on this.

@danmoseley can you assign this issue to him?

One thought: could TimeSpan timeout be changed to TimeSpan? timeout = null? This would allow you to fall back to the default timeout as is possible with the int timeout APIs.

@rhuijben Any thoughts? If we want to change the API shape, this API must be re-reviewed.

madelson added a commit to madelson/runtime that referenced this issue Jul 17, 2022
…work).

Provides "true" cancellation for async ping methods using either a token or
the existing SendAsyncCancel() API.

Fix dotnet#67260
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 17, 2022
@rzikm rzikm closed this as completed in e00bd40 Aug 30, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 30, 2022
@karelz karelz modified the milestones: Future, 8.0.0 Sep 3, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Oct 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Net help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants