From bd27d3bd9b6eb535b9e8c9b2f0f56e9fdc678c75 Mon Sep 17 00:00:00 2001 From: jonathan pickett Date: Tue, 23 Sep 2014 15:28:38 -0700 Subject: [PATCH] Restoring the ability to compile without IOCP. To do so remove the WIN32_IOCP definition in the C/C++\Preporcessor\Preprocessor Definitions in all projects. Performance is 30-40% better with IOCP. --- msvs/RedisCheckDump/RedisCheckDump.vcxproj | 7 +++-- msvs/RedisCli/RedisCli.vcxproj | 7 +++-- msvs/RedisServer.vcxproj | 5 +-- msvs/hiredis/hiredis.vcxproj | 7 +++-- msvs/lua/lua/lua.vcxproj | 6 ++-- .../documentation/Redis Release Notes.docx | Bin 13549 -> 13549 bytes src/Win32_Interop/Win32_FDAPI.cpp | 29 +++++++++++++++--- src/Win32_Interop/Win32_FDAPI.h | 3 ++ src/Win32_Interop/Win32_Interop.vcxproj | 7 +++-- src/anet.c | 2 +- 10 files changed, 52 insertions(+), 21 deletions(-) diff --git a/msvs/RedisCheckDump/RedisCheckDump.vcxproj b/msvs/RedisCheckDump/RedisCheckDump.vcxproj index 24eb391c..8faaa383 100644 --- a/msvs/RedisCheckDump/RedisCheckDump.vcxproj +++ b/msvs/RedisCheckDump/RedisCheckDump.vcxproj @@ -83,7 +83,7 @@ Level3 Disabled - WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);NO_QFORKIMPL;WIN32_IOCP + WIN32_IOCP;WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);NO_QFORKIMPL MultiThreadedDebug 4996 $(SolutionDir)..\deps\lua\src @@ -119,13 +119,14 @@ Level3 - MaxSpeed + Full true true - WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);WIN32_IOCP;WIN32_IOCP;NO_QFORKIMPL + WIN32_IOCP;WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);NO_QFORKIMPL MultiThreaded 4996 $(SolutionDir)..\deps\lua\src + true true diff --git a/msvs/RedisCli/RedisCli.vcxproj b/msvs/RedisCli/RedisCli.vcxproj index ef19f465..8f569b8f 100644 --- a/msvs/RedisCli/RedisCli.vcxproj +++ b/msvs/RedisCli/RedisCli.vcxproj @@ -84,7 +84,7 @@ Level3 Disabled $(SolutionDir)..\deps\hiredis;$(SolutionDir)..\deps\linenoise;$(SolutionDir)..\deps\lua\src - WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);NO_QFORKIMPL;WIN32_IOCP + WIN32_IOCP;WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);NO_QFORKIMPL MultiThreadedDebug 4996 @@ -121,13 +121,14 @@ Level3 - MaxSpeed + Full true true $(SolutionDir)..\deps\hiredis;$(SolutionDir)..\deps\linenoise;$(SolutionDir)..\deps\lua\src - WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);WIN32_IOCP;WIN32_IOCP;NO_QFORKIMPL + WIN32_IOCP;WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);NO_QFORKIMPL MultiThreaded 4996 + true true diff --git a/msvs/RedisServer.vcxproj b/msvs/RedisServer.vcxproj index 66118f78..fc9cbe07 100644 --- a/msvs/RedisServer.vcxproj +++ b/msvs/RedisServer.vcxproj @@ -84,7 +84,7 @@ - WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;_DEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions);USE_DLMALLOC;WIN32_IOCP + WIN32_IOCP;WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;_DEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions);USE_DLMALLOC $(SolutionDir)..\deps\lua\src;$(SolutionDir)..\deps\hiredis MultiThreadedDebug Level3 @@ -126,13 +126,14 @@ - _WIN32IOCP;WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;NDEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions);WIN32_IOCP;USE_DLMALLOC + WIN32_IOCP;WIN32;USE_DL_PREFIX;LACKS_STDLIB_H;NDEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions);USE_DLMALLOC $(SolutionDir)..\deps\lua\src;$(SolutionDir)..\deps\hiredis MultiThreaded Level3 ProgramDatabase 4996;4146 true + Full true diff --git a/msvs/hiredis/hiredis.vcxproj b/msvs/hiredis/hiredis.vcxproj index ff9ca00e..8dfaa11b 100644 --- a/msvs/hiredis/hiredis.vcxproj +++ b/msvs/hiredis/hiredis.vcxproj @@ -83,7 +83,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);WIN32_IOCP + WIN32_IOCP;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) MultiThreadedDebug 4996 @@ -110,12 +110,13 @@ Level3 NotUsing - MaxSpeed + Full true true - WIN32;%(PreprocessorDefinitions);WIN32_IOCP;WIN32_IOCP + WIN32_IOCP;WIN32;%(PreprocessorDefinitions) MultiThreaded 4996 + true Windows diff --git a/msvs/lua/lua/lua.vcxproj b/msvs/lua/lua/lua.vcxproj index 9e634f0a..972213a7 100644 --- a/msvs/lua/lua/lua.vcxproj +++ b/msvs/lua/lua/lua.vcxproj @@ -89,7 +89,7 @@ Level3 Disabled - WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);WIN32_IOCP + WIN32_IOCP;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) NotUsing MultiThreadedDebug 4244;4018 @@ -118,10 +118,12 @@ Level3 - WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);WIN32_IOCP;WIN32_IOCP + WIN32_IOCP;WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) NotUsing MultiThreaded 4244;4018 + Full + true true diff --git a/msvs/setups/documentation/Redis Release Notes.docx b/msvs/setups/documentation/Redis Release Notes.docx index 4e8991bee7f3fa1f33011a5890a18bd6196959b8..f1a62dd56cfab9d77115f97a3e2a581de9e336cb 100644 GIT binary patch delta 24 ecmaEx`8IRIG)?A{+2)&PYI1Xf7?YQqxB&o9|~On diff --git a/src/Win32_Interop/Win32_FDAPI.cpp b/src/Win32_Interop/Win32_FDAPI.cpp index 38bc1d85..6074f86a 100644 --- a/src/Win32_Interop/Win32_FDAPI.cpp +++ b/src/Win32_Interop/Win32_FDAPI.cpp @@ -84,6 +84,7 @@ redis_ntohs ntohs = NULL; redis_freeaddrinfo freeaddrinfo = NULL; redis_getaddrinfo getaddrinfo = NULL; redis_inet_ntop inet_ntop = NULL; +redis_FD_ISSET FD_ISSET = NULL; } auto f_WSAStartup = dllfunctor_stdcall("ws2_32.dll", "WSAStartup"); @@ -344,7 +345,8 @@ int redis_accept_impl(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { } else { errno = WSAGetLastError(); if((errno==ENOENT)||(errno==WSAEWOULDBLOCK)) { - errno=EAGAIN; + errno = EAGAIN; + return RFDMap::invalidRFD; } } } @@ -407,8 +409,27 @@ int redis_fcntl_impl(int fd, int cmd, int flags = 0 ) { return -1; } -#undef FD_ISSET +static auto f_WSAFDIsSet = dllfunctor_stdcall("ws2_32.dll", "__WSAFDIsSet"); #define FD_ISSET(fd, set) f_WSAFDIsSet((SOCKET)(fd), (fd_set *)(set)) +int redis_FD_ISSET_impl(int fd, fd_set* pSet) { + fd_set copy; + FD_ZERO(©); + for (u_int n = 0; n < pSet->fd_count; n++) { + SOCKET s = RFDMap::getInstance().lookupSocket((RFD)(pSet->fd_array[n])); + if (s == INVALID_SOCKET) { + errno = EBADF; + return -1; + } + FD_SET(s, ©); + } + SOCKET s = RFDMap::getInstance().lookupSocket(fd); + if (s == INVALID_SOCKET) { + errno = EBADF; + return -1; + } + return f_WSAFDIsSet(s, ©); +} + int redis_poll_impl(struct pollfd *fds, nfds_t nfds, int timeout) { try { struct pollfd* pollCopy = new struct pollfd[nfds]; @@ -441,8 +462,6 @@ int redis_poll_impl(struct pollfd *fds, nfds_t nfds, int timeout) { return ret; } else { - static auto f_WSAFDIsSet = dllfunctor_stdcall("ws2_32.dll", "__WSAFDIsSet"); - int ret; fd_set readSet; fd_set writeSet; @@ -1113,6 +1132,8 @@ private: freeaddrinfo = redis_freeaddrinfo_impl; getaddrinfo = redis_getaddrinfo_impl; inet_ntop = redis_inet_ntop_impl; + FD_ISSET = redis_FD_ISSET_impl; + accept = redis_accept_impl; } ~Win32_FDSockMap() { diff --git a/src/Win32_Interop/Win32_FDAPI.h b/src/Win32_Interop/Win32_FDAPI.h index f886e74a..ffab1f5c 100644 --- a/src/Win32_Interop/Win32_FDAPI.h +++ b/src/Win32_Interop/Win32_FDAPI.h @@ -39,6 +39,7 @@ typedef int ssize_t; #define INCL_WINSOCK_API_PROTOTYPES 0 // Important! Do not include Winsock API definitions to avoid conflicts with API entry points defnied below. #include +#undef FD_ISSET #include #include @@ -185,6 +186,7 @@ typedef int (*redis_isatty)(int fd); typedef int (*redis_access)(const char *pathname, int mode); typedef u_int64 (*redis_lseek64)(int fd, u_int64 offset, int whence); typedef intptr_t (*redis_get_osfhandle)(int fd); +typedef int(*redis_FD_ISSET)(int fd, fd_set *); // access() mode definitions #define X_OK 0 @@ -240,6 +242,7 @@ extern redis_get_osfhandle fdapi_get_osfhandle; extern redis_freeaddrinfo freeaddrinfo; extern redis_getaddrinfo getaddrinfo; extern redis_inet_ntop inet_ntop; +extern redis_FD_ISSET FD_ISSET; // other FD based APIs BOOL SetFDInformation(int FD, DWORD mask, DWORD flags); diff --git a/src/Win32_Interop/Win32_Interop.vcxproj b/src/Win32_Interop/Win32_Interop.vcxproj index f35eaf32..6c7b863d 100644 --- a/src/Win32_Interop/Win32_Interop.vcxproj +++ b/src/Win32_Interop/Win32_Interop.vcxproj @@ -130,7 +130,7 @@ rc.exe -foresources/EventLog.res resources/EventLog.rc Level3 Disabled - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);USE_DL_PREFIX;LACKS_STDLIB_H;USE_DLMALLOC;_CRT_SECURE_NO_WARNINGS;WIN32_IOCP;PSAPI_VERSION=1 + WIN32_IOCP;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);USE_DL_PREFIX;LACKS_STDLIB_H;USE_DLMALLOC;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1 $(ProjectDir)..\..\deps\lua\src MultiThreadedDebug @@ -169,12 +169,13 @@ rc.exe -foresources/EventLog.res resources/EventLog.rc Level3 - MaxSpeed + Full true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);_WIN32IOCP;USE_DL_PREFIX;LACKS_STDLIB_H;USE_DLMALLOC;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1 + WIN32_IOCP;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);USE_DL_PREFIX;LACKS_STDLIB_H;USE_DLMALLOC;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1 $(ProjectDir)..\..\deps\lua\src MultiThreaded + true Windows diff --git a/src/anet.c b/src/anet.c index b9bcd404..9efd37e8 100644 --- a/src/anet.c +++ b/src/anet.c @@ -457,7 +457,7 @@ static int anetListen(char *err, int s, struct sockaddr *sa, socklen_t len, int return ANET_ERR; } -#ifdef _WIN32 +#ifdef WIN32_IOCP if (aeWinListen(s, backlog) == SOCKET_ERROR) { #else if (listen(s, backlog) == -1) {