From 8cd3b1aa3c109dc8b8f1d9eccc46a404d85d1a7e Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Fri, 23 Sep 2011 14:25:22 +0000 Subject: [PATCH] THRIFT-1031 Patch to compile Thrift for vc++ 9.0 and 10.0 => some more improvements Patch: James Dickson git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1174801 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/compiler.sln | 20 +++ compiler/cpp/compiler.vcxproj | 157 ++++++++++++++++++++++ compiler/cpp/compiler.vcxproj.filters | 180 ++++++++++++++++++++++++++ lib/cpp/libthrift.vcxproj | 10 +- lib/cpp/src/Thrift.h | 4 + lib/cpp/src/transport/TSocket.cpp | 11 +- lib/cpp/src/windows/TargetVersion.h | 3 + lib/cpp/src/windows/config.h | 43 +++--- lib/cpp/src/windows/force_inc.h | 4 + 9 files changed, 406 insertions(+), 26 deletions(-) create mode 100644 compiler/cpp/compiler.sln create mode 100644 compiler/cpp/compiler.vcxproj create mode 100644 compiler/cpp/compiler.vcxproj.filters diff --git a/compiler/cpp/compiler.sln b/compiler/cpp/compiler.sln new file mode 100644 index 00000000..94961aae --- /dev/null +++ b/compiler/cpp/compiler.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compiler", "compiler.vcxproj", "{89975A1A-F799-4556-98B8-64E30AB39A90}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {89975A1A-F799-4556-98B8-64E30AB39A90}.Debug|Win32.ActiveCfg = Debug|Win32 + {89975A1A-F799-4556-98B8-64E30AB39A90}.Debug|Win32.Build.0 = Debug|Win32 + {89975A1A-F799-4556-98B8-64E30AB39A90}.Release|Win32.ActiveCfg = Release|Win32 + {89975A1A-F799-4556-98B8-64E30AB39A90}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/compiler/cpp/compiler.vcxproj b/compiler/cpp/compiler.vcxproj new file mode 100644 index 00000000..5f43577b --- /dev/null +++ b/compiler/cpp/compiler.vcxproj @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {89975A1A-F799-4556-98B8-64E30AB39A90} + Win32Proj + compiler + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + true + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(IncludePath) + thrift + + + false + $(ProjectDir)\src\;$(ProjectDir)\src\windows\;$(IncludePath) + thrift + + + + + + Level3 + Disabled + WIN32;MINGW;YY_NO_UNISTD_H;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + config.h + CompileAsCpp + + + Console + true + + + flex -o "src/thriftl.cc" src/thriftl.ll +bison -y -o "src/thrifty.cc" --defines="src/thrifty.h" src/thrifty.yy + + + + + Level3 + + + MaxSpeed + true + true + WIN32;MINGW;YY_NO_UNISTD_H;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + config.h + CompileAsCpp + + + Console + true + true + true + + + flex -o "src/thriftl.cc" src/thriftl.ll +bison -y -o "src/thrifty.cc" --defines="src/thrifty.h" src/thrifty.yy + + + + + + \ No newline at end of file diff --git a/compiler/cpp/compiler.vcxproj.filters b/compiler/cpp/compiler.vcxproj.filters new file mode 100644 index 00000000..16a690fa --- /dev/null +++ b/compiler/cpp/compiler.vcxproj.filters @@ -0,0 +1,180 @@ + + + + + + windows + + + windows + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + parse + + + generate + + + generate + + + generate + + + + + + generated + + + + + {ae9d0a15-57ae-4f01-87a4-81f790249b83} + + + {c9be9380-57bb-438a-a647-4a6943326d6b} + + + {79697fe7-fdf0-4ed4-bb4f-3128632c3446} + + + {5df016bb-591b-420a-a535-4330d9187fbf} + + + {b5c626af-afa5-433c-8e10-ee734533cb68} + + + + + + parse + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + generate + + + + generated + + + generated + + + generate + + + generate + + + + + resources + + + resources + + + + \ No newline at end of file diff --git a/lib/cpp/libthrift.vcxproj b/lib/cpp/libthrift.vcxproj index 0e4c9427..5896726c 100644 --- a/lib/cpp/libthrift.vcxproj +++ b/lib/cpp/libthrift.vcxproj @@ -35,8 +35,8 @@ _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - HAVE_GETTIMEOFDAY;%(PreprocessorDefinitions) - HAVE_GETTIMEOFDAY;%(PreprocessorDefinitions) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) @@ -217,7 +217,8 @@ NotUsing Level3 Disabled - WIN32;HAVE_CONFIG_H;NOMINMAX;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + force_inc.h;%(ForcedIncludeFiles) Windows @@ -231,7 +232,8 @@ MaxSpeed true true - WIN32;HAVE_CONFIG_H;NOMINMAX;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + force_inc.h;%(ForcedIncludeFiles) Windows diff --git a/lib/cpp/src/Thrift.h b/lib/cpp/src/Thrift.h index 97f79878..60a66f46 100644 --- a/lib/cpp/src/Thrift.h +++ b/lib/cpp/src/Thrift.h @@ -20,6 +20,10 @@ #ifndef _THRIFT_THRIFT_H_ #define _THRIFT_THRIFT_H_ 1 +#ifdef _WIN32 +#include "windows/config.h" +#endif + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/lib/cpp/src/transport/TSocket.cpp b/lib/cpp/src/transport/TSocket.cpp index 48d00075..2db8f8b7 100644 --- a/lib/cpp/src/transport/TSocket.cpp +++ b/lib/cpp/src/transport/TSocket.cpp @@ -181,10 +181,6 @@ bool TSocket::peek() { void TSocket::openConnection(struct addrinfo *res) { -#ifdef _WIN32 - TWinsockSingleton::create(); -#endif // _WIN32 - if (isOpen()) { return; } @@ -276,7 +272,7 @@ void TSocket::openConnection(struct addrinfo *res) { goto done; } - if (errno != EINPROGRESS) { + if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK)) { int errno_copy = errno; GlobalOutput.perror("TSocket::open() connect() " + getSocketInfo(), errno_copy); throw TTransportException(TTransportException::NOT_OPEN, "connect() failed", errno_copy); @@ -346,6 +342,11 @@ void TSocket::unix_open(){ } void TSocket::local_open(){ + +#ifdef _WIN32 + TWinsockSingleton::create(); +#endif // _WIN32 + if (isOpen()) { return; } diff --git a/lib/cpp/src/windows/TargetVersion.h b/lib/cpp/src/windows/TargetVersion.h index 73746660..c8498b13 100644 --- a/lib/cpp/src/windows/TargetVersion.h +++ b/lib/cpp/src/windows/TargetVersion.h @@ -28,6 +28,9 @@ #error This is a MSVC header only. #endif +#include + +#define _WIN32_WINNT 0x0601 #include #endif //_THIRFT_WINDOWS_TARGETVERSION_H_ diff --git a/lib/cpp/src/windows/config.h b/lib/cpp/src/windows/config.h index 29a01f69..0f9a3043 100644 --- a/lib/cpp/src/windows/config.h +++ b/lib/cpp/src/windows/config.h @@ -28,6 +28,11 @@ #error This is a MSVC header only. #endif +#pragma warning(disable: 4996) // Depreciated posix name. +#pragma warning(disable: 4250) // Inherits via dominance. + +#define HAVE_GETTIMEOFDAY 1 + #include "TargetVersion.h" #include "GetTimeOfDay.h" #include "Operators.h" @@ -50,27 +55,31 @@ typedef boost::uint8_t uint8_t; // pthreads #include -//"asm/posix_types.h" -typedef unsigned int __kernel_size_t; -typedef int __kernel_ssize_t; - -//"linux/types.h" -typedef __kernel_size_t size_t; -typedef __kernel_ssize_t ssize_t; - -// Missing defines. -#define __BYTE_ORDER __LITTLE_ENDIAN +typedef ptrdiff_t ssize_t; // Missing functions. #define usleep(ms) Sleep(ms) -#if WINVER == 0x0501 -# define poll(fds, nfds, timeout) \ - select(0, NULL, fds, NULL, timeout) -#else -# define poll(fds, nfds, timeout) \ - WSAPoll(fds, nfds, timeout) -#endif // WINVER +#define poll(fds, nfds, timeout) \ + poll_win32(fds, nfds, timeout) + +inline int poll_win32(LPWSAPOLLFD fdArray, ULONG fds, INT timeout) +{ + fd_set read_fds; + fd_set write_fds; + fd_set except_fds; + + FD_ZERO(&read_fds); + FD_ZERO(&write_fds); + FD_ZERO(&except_fds); + + FD_SET(fdArray[0].fd, &read_fds); + FD_SET(fdArray[0].fd, &write_fds); + FD_SET(fdArray[0].fd, &except_fds); + + timeval time_out = {timeout * 0.001, timeout * 1000}; + return select(1, &read_fds, &write_fds, &except_fds, &time_out); +} inline void close(SOCKET socket) { diff --git a/lib/cpp/src/windows/force_inc.h b/lib/cpp/src/windows/force_inc.h index aa81c42b..a85b8801 100644 --- a/lib/cpp/src/windows/force_inc.h +++ b/lib/cpp/src/windows/force_inc.h @@ -28,6 +28,10 @@ #error This is a MSVC header only. #endif +#define NOMINMAX + +#include "windows/config.h" + #undef gai_strerror #define gai_strerror gai_strerrorA -- 2.17.1