-
Notifications
You must be signed in to change notification settings - Fork 1.5k
add support for parsing and formatting unix domain sockets #1624
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||
| using System.Buffers.Text; | ||||||
| using System.Globalization; | ||||||
| using System.Net; | ||||||
| using System.Net.Sockets; | ||||||
| using System.Runtime.InteropServices; | ||||||
| using System.Text; | ||||||
|
|
||||||
|
|
@@ -78,17 +79,21 @@ internal static string ToString(object value) | |||||
|
|
||||||
| internal static string ToString(EndPoint endpoint) | ||||||
| { | ||||||
| if (endpoint is DnsEndPoint dns) | ||||||
| { | ||||||
| if (dns.Port == 0) return dns.Host; | ||||||
| return dns.Host + ":" + Format.ToString(dns.Port); | ||||||
| } | ||||||
| if (endpoint is IPEndPoint ip) | ||||||
| switch (endpoint) | ||||||
| { | ||||||
| if (ip.Port == 0) return ip.Address.ToString(); | ||||||
| return ip.Address + ":" + Format.ToString(ip.Port); | ||||||
| case DnsEndPoint dns: | ||||||
| if (dns.Port == 0) return dns.Host; | ||||||
| return dns.Host + ":" + Format.ToString(dns.Port); | ||||||
| case IPEndPoint ip: | ||||||
| if (ip.Port == 0) return ip.Address.ToString(); | ||||||
| return ip.Address + ":" + Format.ToString(ip.Port); | ||||||
| #if UNIX_SOCKET | ||||||
| case UnixDomainSocketEndPoint uds: | ||||||
| return "!" + uds.ToString(); | ||||||
| #endif | ||||||
| default: | ||||||
| return endpoint?.ToString() ?? ""; | ||||||
| } | ||||||
| return endpoint?.ToString() ?? ""; | ||||||
| } | ||||||
|
|
||||||
| internal static string ToStringHostOnly(EndPoint endpoint) | ||||||
|
|
@@ -233,6 +238,16 @@ internal static EndPoint TryParseEndPoint(string addressWithPort) | |||||
| string portPart = null; | ||||||
| if (string.IsNullOrEmpty(addressWithPort)) return null; | ||||||
|
|
||||||
| if (addressWithPort[0]=='!') | ||||||
| { | ||||||
| if (addressWithPort.Length == 1) return null; | ||||||
|
|
||||||
| #if UNIX_SOCKET | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| return new UnixDomainSocketEndPoint(addressWithPort.Substring(1)); | ||||||
| #else | ||||||
| throw new PlatformNotSupportedException("Unix domain sockets require .NET Core 3 or above"); | ||||||
| #endif | ||||||
| } | ||||||
| var lastColonIndex = addressWithPort.LastIndexOf(':'); | ||||||
| if (lastColonIndex > 0) | ||||||
| { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| <SignAssembly>true</SignAssembly> | ||
| <PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign> | ||
| <DefineConstants Condition="'$(TargetFramework)' != 'net461'">$(DefineConstants);VECTOR_SAFE</DefineConstants> | ||
| <DefineConstants Condition="'$(TargetFramework)' != 'net461' and '$(TargetFramework)' != 'net472' and '$(TargetFramework)' != 'netstandard2.0'">$(DefineConstants);UNIX_SOCKET</DefineConstants> | ||
|
Collaborator
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. Recommend we define |
||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
|
|
||
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.
Suggest: