浏览代码

Merge PR #1317: Mayaqua/Network.c: Always use fcntl() to toggle socket non-blocking mode (UNIX)

Davide Beatrici 4 年之前
父节点
当前提交
3e17c818a6
共有 1 个文件被更改,包括 3 次插入24 次删除
  1. 3 24
      src/Mayaqua/Network.c

+ 3 - 24
src/Mayaqua/Network.c

@@ -8029,38 +8029,17 @@ bool IsSubnetMask32(UINT ip)
 // Turn on and off the non-blocking mode of the socket
 // Turn on and off the non-blocking mode of the socket
 void UnixSetSocketNonBlockingMode(int fd, bool nonblock)
 void UnixSetSocketNonBlockingMode(int fd, bool nonblock)
 {
 {
-	UINT flag = 0;
 	// Validate arguments
 	// Validate arguments
 	if (fd == INVALID_SOCKET)
 	if (fd == INVALID_SOCKET)
 	{
 	{
 		return;
 		return;
 	}
 	}
 
 
-	if (nonblock)
+	const int flags = fcntl(fd, F_GETFL, 0);
+	if (flags != -1)
 	{
 	{
-		flag = 1;
+		fcntl(fd, F_SETFL, nonblock ? flags | O_NONBLOCK : flags & ~O_NONBLOCK);
 	}
 	}
-
-#ifdef	FIONBIO
-	ioctl(fd, FIONBIO, &flag);
-#else	// FIONBIO
-	{
-		int flag = fcntl(fd, F_GETFL, 0);
-		if (flag != -1)
-		{
-			if (nonblock)
-			{
-				flag |= O_NONBLOCK;
-			}
-			else
-			{
-				flag = flag & ~O_NONBLOCK;
-
-				fcntl(fd, F_SETFL, flag);
-			}
-		}
-	}
-#endif	// FIONBIO
 }
 }
 
 
 // Do Nothing
 // Do Nothing