Skip to content

Commit

Permalink
Gracefully handle errors in socket creation (#662)
Browse files Browse the repository at this point in the history
In all other calls, exceptions are handled within the ManagedSocket
class, this can't easily be done here as the exception is thrown from
the constructor, so the exception is handled in ISocket and the correct
error is passed to the application.

This should fix #660
  • Loading branch information
Vudjun authored Feb 16, 2025
1 parent 61975ca commit bc07bc4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,21 @@ private ResultCode SocketInternal(ServiceCtx context, bool exempt)
}
}

ISocket newBsdSocket = new ManagedSocket(netDomain, (SocketType)type, protocol, context.Device.Configuration.MultiplayerLanInterfaceId)
{
Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking),
};

LinuxError errno = LinuxError.SUCCESS;
ISocket newBsdSocket;

try
{
newBsdSocket = new ManagedSocket(netDomain, (SocketType)type, protocol, context.Device.Configuration.MultiplayerLanInterfaceId)
{
Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking),
};
}
catch (SocketException exception)
{
LinuxError errNo = WinSockHelper.ConvertError((WsaError)exception.ErrorCode);
return WriteBsdResult(context, 0, errNo);
}

int newSockFd = _context.RegisterFileDescriptor(newBsdSocket);

Expand Down

0 comments on commit bc07bc4

Please sign in to comment.