From d378fc8ede4e5ba95ec1e129ff9e1f1c74e3d187 Mon Sep 17 00:00:00 2001 From: lateralusX Date: Thu, 14 Sep 2017 11:06:38 +0200 Subject: [PATCH] Fix sporadic failures in MonoTests.System.Net.HttpRequestStreamTest on x64 Windows. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit MonoTests.System.Net.HttpRequestStreamTest suite has sporadic failures on Windows x64 with following exception: System.Net.Sockets.SocketException : An operation was attempted on something that is not a socket. This happens due to a data type and constant size mismatch. w32socket.h defines INVALID_SOCKET and SOCKET_ERROR for all platforms. On Windows x64, SOCKET is defined by winsock2.h as 64-bit type as well as INVALID_SOCKET constant, but above code will define INVALID_SOCKET as a 32-bit constant value. This will in turn cause code to sporadically fail to detect invalid sockets as returned by win32 API's. This will in turn cause the socket exception when code continues to use socket as argument to win32 socket API’s. Current “invalid” x64 codegen for expression: if (sock == INVALID_SOCKET) mov eax,0FFFFFFFFh cmp rsi,rax and with fixed defines, correct 64-bit cmp instruction: cmp rsi,0FFFFFFFFFFFFFFFFh Fix makes sure we get the defines of INVALID_SOCKET and SOCKET_ERROR from winsock2.h on Windows platforms to be consistent with define of SOCKET type. --- mono/metadata/w32socket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mono/metadata/w32socket.h b/mono/metadata/w32socket.h index 5d5aa4adc53..b03ac936738 100644 --- a/mono/metadata/w32socket.h +++ b/mono/metadata/w32socket.h @@ -16,10 +16,10 @@ #include +#ifndef HOST_WIN32 #define INVALID_SOCKET ((SOCKET)(guint32)(~0)) #define SOCKET_ERROR (-1) -#ifndef HOST_WIN32 typedef gint SOCKET; typedef struct { -- 2.25.1