Add ProxyManager

This commit is contained in:
TSR Berry 2024-07-28 23:27:02 +02:00
parent aea32c29aa
commit 49acca8cf7
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2
2 changed files with 52 additions and 4 deletions

View file

@ -1,6 +1,7 @@
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl; using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types; using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types;
using Ryujinx.Memory; using Ryujinx.Memory;
using System; using System;
@ -95,10 +96,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
} }
} }
ISocket newBsdSocket = new ManagedSocket(netDomain, (SocketType)type, protocol) ISocket newBsdSocket = ProxyManager.GetSocket(netDomain, (SocketType)type, protocol);
{ newBsdSocket.Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking);
Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking),
};
LinuxError errno = LinuxError.SUCCESS; LinuxError errno = LinuxError.SUCCESS;

View file

@ -0,0 +1,49 @@
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy
{
public static class ProxyManager
{
private static readonly Dictionary<string, EndPoint> _proxyEndpoints = new();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string GetKey(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
{
return string.Join("-", new[] { (int)addressFamily, (int)socketType, (int)protocolType });
}
internal static ISocket GetSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
{
// TODO: Return proxy socket if AddressFamily, SocketType and ProtocolType match.
return new ManagedSocket(addressFamily, socketType, protocolType);
}
public static void AddOrUpdate(EndPoint endPoint,
AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
{
_proxyEndpoints[GetKey(addressFamily, socketType, protocolType)] = endPoint;
}
public static void AddOrUpdate(IPAddress address, int port,
AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
{
_proxyEndpoints[GetKey(addressFamily, socketType, protocolType)] = new IPEndPoint(address, port);
}
public static void AddOrUpdate(string host, int port,
AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
{
_proxyEndpoints[GetKey(addressFamily, socketType, protocolType)] = new DnsEndPoint(host, port);
}
public static bool Remove(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
{
return _proxyEndpoints.Remove(GetKey(addressFamily, socketType, protocolType));
}
}
}