Bsd: Implement Select (#4017)
* bsd: Add gdkchan's Select implementation Co-authored-by: TSRBerry <20988865+tsrberry@users.noreply.github.com> * bsd: Fix Select() causing a crash with an ArgumentException .NET Sockets have to be used for the Select() call * bsd: Make Select more generic * bsd: Adjust namespaces and remove unused imports * bsd: Fix NullReferenceException in Select Co-authored-by: gdkchan <gab.dark.100@gmail.com>
This commit is contained in:
parent
403e67d983
commit
ba5c0cf5d8
28 changed files with 263 additions and 43 deletions
|
@ -1,5 +1,8 @@
|
|||
using System.Collections.Concurrent;
|
||||
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
||||
{
|
||||
|
@ -41,6 +44,27 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
return null;
|
||||
}
|
||||
|
||||
public List<IFileDescriptor> RetrieveFileDescriptorsFromMask(ReadOnlySpan<byte> mask)
|
||||
{
|
||||
List<IFileDescriptor> fds = new();
|
||||
|
||||
for (int i = 0; i < mask.Length; i++)
|
||||
{
|
||||
byte current = mask[i];
|
||||
|
||||
while (current != 0)
|
||||
{
|
||||
int bit = BitOperations.TrailingZeroCount(current);
|
||||
current &= (byte)~(1 << bit);
|
||||
int fd = i * 8 + bit;
|
||||
|
||||
fds.Add(RetrieveFileDescriptor(fd));
|
||||
}
|
||||
}
|
||||
|
||||
return fds;
|
||||
}
|
||||
|
||||
public int RegisterFileDescriptor(IFileDescriptor file)
|
||||
{
|
||||
lock (_lock)
|
||||
|
@ -61,6 +85,16 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
}
|
||||
}
|
||||
|
||||
public void BuildMask(List<IFileDescriptor> fds, Span<byte> mask)
|
||||
{
|
||||
foreach (IFileDescriptor descriptor in fds)
|
||||
{
|
||||
int fd = _fds.IndexOf(descriptor);
|
||||
|
||||
mask[fd >> 3] |= (byte)(1 << (fd & 7));
|
||||
}
|
||||
}
|
||||
|
||||
public int DuplicateFileDescriptor(int fd)
|
||||
{
|
||||
IFileDescriptor oldFile = RetrieveFileDescriptor(fd);
|
||||
|
@ -147,4 +181,4 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
|
|||
return processContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue