This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Enable custom socket end points and allow Unix Domain Sockets #5051
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,28 +9,65 @@ internal static class IPEndPointExtensions | |
| { | ||
| public static Internals.SocketAddress Serialize(EndPoint endpoint) | ||
| { | ||
| Debug.Assert(endpoint is IPEndPoint); | ||
| Debug.Assert(!(endpoint is DnsEndPoint)); | ||
|
|
||
| return new Internals.SocketAddress(((IPEndPoint)endpoint).Address, ((IPEndPoint)endpoint).Port); | ||
| var ipEndPoint = endpoint as IPEndPoint; | ||
| if (ipEndPoint != null) | ||
| { | ||
| return new Internals.SocketAddress(ipEndPoint.Address, ipEndPoint.Port); | ||
| } | ||
|
|
||
| System.Net.SocketAddress address = endpoint.Serialize(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would this work for a DnsEndPoint? Please add a test.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are already existing tests for DnsEndpoint. The code checks if it's DNS end point before it calls IPEndPointExtensions. |
||
| return GetInternalSocketAddress(address); | ||
| } | ||
|
|
||
| public static EndPoint Create(this EndPoint thisObj, Internals.SocketAddress socketAddress) | ||
| { | ||
| if (socketAddress.Family != thisObj.AddressFamily) | ||
| AddressFamily family = socketAddress.Family; | ||
| if (family != thisObj.AddressFamily) | ||
| { | ||
| throw new ArgumentException(SR.Format(SR.net_InvalidAddressFamily, socketAddress.Family.ToString(), thisObj.GetType().FullName, thisObj.AddressFamily.ToString()), "socketAddress"); | ||
| throw new ArgumentException(SR.Format(SR.net_InvalidAddressFamily, family.ToString(), thisObj.GetType().FullName, thisObj.AddressFamily.ToString()), "socketAddress"); | ||
| } | ||
| if (socketAddress.Size < 8) | ||
|
|
||
| if (family == AddressFamily.InterNetwork || family == AddressFamily.InterNetworkV6) | ||
| { | ||
| throw new ArgumentException(SR.Format(SR.net_InvalidSocketAddressSize, socketAddress.GetType().FullName, thisObj.GetType().FullName), "socketAddress"); | ||
| if (socketAddress.Size < 8) | ||
| { | ||
| throw new ArgumentException(SR.Format(SR.net_InvalidSocketAddressSize, socketAddress.GetType().FullName, thisObj.GetType().FullName), "socketAddress"); | ||
| } | ||
|
|
||
| return socketAddress.GetIPEndPoint(); | ||
| } | ||
|
|
||
| return socketAddress.GetIPEndPoint(); | ||
| System.Net.SocketAddress address = GetNetSocketAddress(socketAddress); | ||
| return thisObj.Create(address); | ||
| } | ||
|
|
||
| internal static IPEndPoint Snapshot(this IPEndPoint thisObj) | ||
| { | ||
| return new IPEndPoint(thisObj.Address.Snapshot(), thisObj.Port); | ||
| } | ||
|
|
||
| private static Internals.SocketAddress GetInternalSocketAddress(System.Net.SocketAddress address) | ||
| { | ||
| var result = new Internals.SocketAddress(address.Family, address.Size); | ||
| for (int index = 0; index < address.Size; index++) | ||
| { | ||
| result[index] = address[index]; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| private static System.Net.SocketAddress GetNetSocketAddress(Internals.SocketAddress address) | ||
| { | ||
| var result = new System.Net.SocketAddress(address.Family, address.Size); | ||
| for (int index = 0; index < address.Size; index++) | ||
| { | ||
| result[index] = address[index]; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your comment below:
Please update this assert instead of removing it. (as
Debug.Assert(!(endpoint is DnsEndpoint)))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense