UnixDomainSocketEndPoint no longer constructable on iOS (.NET 8)
#96.143 aperta il 18 dic 2023
Metriche repository
- Star
- (17.886 star)
- Metriche merge PR
- (Merge medio 12g 11h) (661 PR mergiate in 30 g)
Descrizione
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.