From bc07bc482d172744a143a5f060076ff8f400b757 Mon Sep 17 00:00:00 2001 From: Vudjun Date: Sun, 16 Feb 2025 08:26:37 +0000 Subject: [PATCH] Gracefully handle errors in socket creation (#662) 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 --- .../HOS/Services/Sockets/Bsd/IClient.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs index b8deb2c45..0a592d542 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs @@ -101,12 +101,21 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd } } - 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);