Skip to content

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

Closed

Description

@deeprobin

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

Activity

  1. added
    api-suggestion
    on Mar 28, 2022
  2. ghost added
    untriaged
    on Mar 28, 2022
  3. added
    api-approved
    and removed
    api-suggestion
    on Mar 28, 2022
  4. danmoseley commented on Mar 28, 2022

    @danmoseley
    Contributor

    Updated to match what was approved.

  5. added
    help wanted
    on Mar 28, 2022
  6. deeprobin commented on Mar 28, 2022

    @deeprobin
    ContributorAuthor

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

  7. removed
    untriaged
    on Mar 28, 2022
  8. teo-tsirpanis commented on Mar 28, 2022

    @teo-tsirpanis
    Contributor

    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);
    }
  9. rhuijben commented on May 8, 2022

    @rhuijben
    Contributor

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

  10. added this to the Future milestone on Jun 6, 2022
  11. sakno commented on Jun 8, 2022

    @sakno
    Contributor

    IMO, this proposal can be combined with #34856

  12. deeprobin commented on Jun 8, 2022

    @deeprobin
    ContributorAuthor

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

  13. madelson commented on Jul 15, 2022

    @madelson
    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.

  14. deeprobin commented on Jul 15, 2022

    @deeprobin
    ContributorAuthor

    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.

  15. added a commit that references this issue on Jul 17, 2022
    1fc763f
  16. ghost added
    in-pr
    on Jul 17, 2022
  17. ghost removed
    in-pr
    on Aug 30, 2022
  18. modified the milestones: Future, 8.0.0 on Sep 3, 2022
  19. ghost locked as resolved and limited conversation to collaborators on Oct 3, 2022
  20. added a commit that references this issue on Apr 22, 2024
    e00bd40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Nethelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions