Fix socket closing on shutdown

Previously, sockets were only ever closed when the game specifically requested it.

Thanks @comex on GitHub for the patch submitted via the issues page.

Co-Authored-By: comex <47517+comex@users.noreply.github.com>
This commit is contained in:
GreemDev 2025-11-04 20:48:36 -06:00
parent 2c9b193018
commit 234f7ca298
2 changed files with 31 additions and 6 deletions

View file

@ -7,7 +7,7 @@ using System.Threading;
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{ {
class BsdContext class BsdContext : IDisposable
{ {
private static readonly ConcurrentDictionary<ulong, BsdContext> _registry = new(); private static readonly ConcurrentDictionary<ulong, BsdContext> _registry = new();
@ -158,6 +158,20 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
return LinuxError.SUCCESS; return LinuxError.SUCCESS;
} }
public void Dispose()
{
int count;
lock (_lock)
{
count = _fds.Count;
}
for (int fd = 0; fd < count; fd++) {
CloseFileDescriptor(fd);
}
}
public static BsdContext GetOrRegister(ulong processId) public static BsdContext GetOrRegister(ulong processId)
{ {
BsdContext context = GetContext(processId); BsdContext context = GetContext(processId);
@ -174,12 +188,15 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
public static BsdContext GetContext(ulong processId) public static BsdContext GetContext(ulong processId)
{ {
if (!_registry.TryGetValue(processId, out BsdContext processContext)) return _registry.GetValueOrDefault(processId);
{ }
return null;
}
return processContext; public static void DeleteContext(ulong processId)
{
if (_registry.Remove(processId, out BsdContext context))
{
context.Dispose();
}
} }
} }
} }

View file

@ -1165,5 +1165,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
return WriteBsdResult(context, newSockFd, errno); return WriteBsdResult(context, newSockFd, errno);
} }
public override void DestroyAtExit()
{
if (_context != null) {
_context.Dispose();
}
}
} }
} }