Skip to content

Equals/GetHashCode for UnixDomainSocketEndPoint #69488

Closed

Description

@sakno

Background and motivation

My network framework uses EndPoint class as abstraction layer to represent the peer address. It is easy to determine whether the two endpoints represent the same address using Equals method. However, UnixDomainSocketEndPoint doesn't override necessary methods in contrast to IPEndPoint and DnsEndPoint.

API Proposal

namespace System.Net.Sockets;

public sealed class UnixDomainSocketEndPoint : EndPoint
{
  public override bool Equals(object? other);
  public override int GetHashCode();
}

API Usage

var set = new HashSet();

set.Add(new UnixDomainSocketEndPoint("@abstract"));
set.Contains(new UnixDomainSocketEndPoint("@abstract"));

Alternative Designs

Implement custom equality logic:

static bool EndPointsAreEqual(EndPoint x, EndPoint y)
{
  if (x is UnixDomainSocketEndPoint uds1)
    return y is UnixDomainSocketEndPoint uds2 && string.Equals(uds1.ToString(), uds2.ToString(), StringComparison.Ordinal);

  return object.Equals(x, y);
}

Risks

Breaks behavior of default implementation of Equals and GetHashCode.

Activity

  1. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on May 18, 2022
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on May 18, 2022
  3. stephentoub commented on May 18, 2022

    @stephentoub
    Member

    Given that both IPEndPoint and DnsEndPoint override these, it's reasonable for UnixDomainSocketEndPoint to as well. I don't think this really needs to be considered an API proposal. Technically it could break someone relying on Equals providing reference equality, but the chances of that are slim, especially since that's not what it means generally when using the base EndPoint.

  4. removed
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on May 18, 2022
  5. sakno commented on May 18, 2022

    @sakno
    ContributorAuthor

    @stephentoub , if so, I'm ready to make a PR.

  6. changed the title [-][API Proposal]: Equals/GetHashCode for UnixDomainSocketEndPoint[/-] [+]Equals/GetHashCode for UnixDomainSocketEndPoint[/+] on May 18, 2022
  7. CarnaViire commented on May 19, 2022

    @CarnaViire
    Member

    Triage: that makes sense; we would gladly accept the contribution @sakno
    Moving to Future as it's not a priority

  8. removed
    untriagedNew issue has not been triaged by the area owner
    on May 19, 2022
  9. added this to the Future milestone on May 19, 2022
  10. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on May 24, 2022
  11. sakno commented on May 25, 2022

    @sakno
    ContributorAuthor

    @CarnaViire , PR is ready for review.

  12. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 8, 2022
  13. ghost locked as resolved and limited conversation to collaborators on Jul 8, 2022
  14. modified the milestones: Future, 7.0.0 on Jul 19, 2022
  15. added
    in-prThere is an active PR which will close this issue when it is merged
    on Oct 16, 2026
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

    area-System.Netin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions