From 70ec5def9cc7f02580f33dbef65815f0d7ac2229 Mon Sep 17 00:00:00 2001
From: Fruityloops <73552844+fruityloops1@users.noreply.github.com>
Date: Thu, 14 Jul 2022 09:47:25 +0000
Subject: [PATCH] BSD: Allow use of DontWait flag in Receive (#3462)

---
 .../Sockets/Bsd/Impl/ManagedSocket.cs         | 21 +++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs
index 43172ab4cf..b9adb5cc77 100644
--- a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs
+++ b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs
@@ -184,18 +184,35 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
 
         public LinuxError Receive(out int receiveSize, Span<byte> buffer, BsdSocketFlags flags)
         {
+            LinuxError result;
+
+            bool shouldBlockAfterOperation = false;
+
             try
             {
+                if (Blocking && flags.HasFlag(BsdSocketFlags.DontWait))
+                {
+                    Blocking = false;
+                    shouldBlockAfterOperation = true;
+                }
+
                 receiveSize = Socket.Receive(buffer, ConvertBsdSocketFlags(flags));
 
-                return LinuxError.SUCCESS;
+                result = LinuxError.SUCCESS;
             }
             catch (SocketException exception)
             {
                 receiveSize = -1;
 
-                return WinSockHelper.ConvertError((WsaError)exception.ErrorCode);
+                result = WinSockHelper.ConvertError((WsaError)exception.ErrorCode);
             }
+
+            if (shouldBlockAfterOperation)
+            {
+                Blocking = true;
+            }
+
+            return result;
         }
 
         public LinuxError ReceiveFrom(out int receiveSize, Span<byte> buffer, int size, BsdSocketFlags flags, out IPEndPoint remoteEndPoint)