UnixDomainSocketEndPoint no longer constructable on iOS (.NET 8)
#96,143 建立於 2023年12月18日
倉庫指標
- Star
- (17,886 star)
- PR 合併指標
- (平均合併 12天 11小時) (30 天內合併 661 個 PR)
描述
Description
I work on an iOS app (currently Xamarin iOS/.NET 4.8) that uses unix domain sockets. Trying to port to .NET 8, I noticed that the constructor of UnixDomainSocketEndPoint now throws a PlatformNotSupportedException.
Reproduction Steps
var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
fullPath = Path.Join(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"my.sock");
if (File.Exists(fullPath))
File.Delete(fullPath);
var endpoint = new UnixDomainSocketEndPoint(fullPath); // throws PlatformNotSupportedException on .NET 8
socket.Bind(endpoint);
socket.Listen(10);
Expected behavior
Expected to get an instance of UnixDomainSocketEndPoint (as with the older framework)
Actual behavior
Thrown PlatformNotSupportedException
Regression?
Works on .NET 4.8/Xamarin.iOS
Known Workarounds
Pull a copy of the UnixDomainSocketEndPoint code into the project, then comment out the platform check (along with some other minor changes to make it compile) Verified that this works within my iOS app.
Configuration
net8.0-ios
Other information
SocketProtocolSupportPal.Unix.cs contains a comment about AF_UNIX sockets not working on iOS, then explicitly denies support:
internal static partial class SocketProtocolSupportPal
{
private const int DgramSocketType = 2;
private static unsafe bool IsSupported(AddressFamily af)
{
// Check for AF_UNIX on iOS/tvOS. The OS claims to support this, but returns EPERM on bind.
// We should explicitly set the return here to false, to avoid giving a false impression.
if (af == AddressFamily.Unix && (OperatingSystem.IsTvOS() || (OperatingSystem.IsIOS() && !OperatingSystem.IsMacCatalyst())))
{
return false;
}
That claim is not consistent with my experience.