mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-12-12 07:36:59 +00:00
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:
parent
2c9b193018
commit
234f7ca298
2 changed files with 31 additions and 6 deletions
|
|
@ -7,7 +7,7 @@ using System.Threading;
|
|||
|
||||
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
{
|
||||
class BsdContext
|
||||
class BsdContext : IDisposable
|
||||
{
|
||||
private static readonly ConcurrentDictionary<ulong, BsdContext> _registry = new();
|
||||
|
||||
|
|
@ -158,6 +158,20 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
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)
|
||||
{
|
||||
BsdContext context = GetContext(processId);
|
||||
|
|
@ -174,12 +188,15 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
|
||||
public static BsdContext GetContext(ulong processId)
|
||||
{
|
||||
if (!_registry.TryGetValue(processId, out BsdContext processContext))
|
||||
{
|
||||
return null;
|
||||
return _registry.GetValueOrDefault(processId);
|
||||
}
|
||||
|
||||
return processContext;
|
||||
public static void DeleteContext(ulong processId)
|
||||
{
|
||||
if (_registry.Remove(processId, out BsdContext context))
|
||||
{
|
||||
context.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1165,5 +1165,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
|
||||
return WriteBsdResult(context, newSockFd, errno);
|
||||
}
|
||||
|
||||
|
||||
public override void DestroyAtExit()
|
||||
{
|
||||
if (_context != null) {
|
||||
_context.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue