THRIFT-1031 Patch to compile Thrift for vc++ 9.0 and 10.0
Patch: James Dickson and Alexandre Parenteau
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1171777 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/windows/Fcntl.cpp b/lib/cpp/src/windows/Fcntl.cpp
new file mode 100644
index 0000000..bd27773
--- /dev/null
+++ b/lib/cpp/src/windows/Fcntl.cpp
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "Fcntl.h"
+
+// Win32
+#include <Winsock2.h>
+
+int fcntl(int fd, int cmd, int flags)
+{
+ if(cmd != F_GETFL && cmd != F_SETFL)
+ {
+ return -1;
+ }
+
+ if(flags != O_NONBLOCK && flags != 0)
+ {
+ return -1;
+ }
+
+ if(cmd == F_GETFL)
+ {
+ return 0;
+ }
+
+ int res;
+ if(flags)
+ {
+ res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long *>(&(flags = 1)));
+ }
+ else
+ {
+ res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long *>(&(flags = 0)));
+ }
+
+ return res;
+}
diff --git a/lib/cpp/src/windows/Fcntl.h b/lib/cpp/src/windows/Fcntl.h
new file mode 100644
index 0000000..40b70d6
--- /dev/null
+++ b/lib/cpp/src/windows/Fcntl.h
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_WINDOWS_FCNTL_H_
+#define _THRIFT_WINDOWS_FCNTL_H_ 1
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+#ifndef _WIN32
+#error This is a MSVC header only.
+#endif
+
+#define O_NONBLOCK 1
+
+enum
+{
+ F_GETFL,
+ F_SETFL,
+};
+
+int fcntl(int fd, int cmd, int flags);
+
+#endif // _THRIFT_WINDOWS_FCNTL_H_
diff --git a/lib/cpp/src/windows/GetTimeOfDay.cpp b/lib/cpp/src/windows/GetTimeOfDay.cpp
new file mode 100644
index 0000000..6201eda
--- /dev/null
+++ b/lib/cpp/src/windows/GetTimeOfDay.cpp
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "GetTimeOfDay.h"
+#include "config.h"
+
+// win32
+#include <time.h>
+
+#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+# define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
+#else
+# define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
+#endif
+
+struct timezone
+{
+ int tz_minuteswest; /* minutes W of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
+
+int gettimeofday(struct timeval * tv, struct timezone * tz)
+{
+ FILETIME ft;
+ unsigned __int64 tmpres(0);
+ static int tzflag;
+
+ if (NULL != tv)
+ {
+ GetSystemTimeAsFileTime(&ft);
+
+ tmpres |= ft.dwHighDateTime;
+ tmpres <<= 32;
+ tmpres |= ft.dwLowDateTime;
+
+ /*converting file time to unix epoch*/
+ tmpres -= DELTA_EPOCH_IN_MICROSECS;
+ tmpres /= 10; /*convert into microseconds*/
+ tv->tv_sec = (long)(tmpres / 1000000UL);
+ tv->tv_usec = (long)(tmpres % 1000000UL);
+ }
+
+ if (NULL != tz)
+ {
+ if (!tzflag)
+ {
+ _tzset();
+ tzflag++;
+ }
+
+ long time_zone(0);
+ errno_t err(_get_timezone(&time_zone));
+ if (err == NO_ERROR)
+ {
+ tz->tz_minuteswest = time_zone / 60;
+ }
+ else
+ {
+ return -1;
+ }
+
+ int day_light(0);
+ err = (_get_daylight(&day_light));
+ if (err == NO_ERROR)
+ {
+ tz->tz_dsttime = day_light;
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ return -1;
+}
diff --git a/lib/cpp/src/windows/GetTimeOfDay.h b/lib/cpp/src/windows/GetTimeOfDay.h
new file mode 100644
index 0000000..f6bdf1c
--- /dev/null
+++ b/lib/cpp/src/windows/GetTimeOfDay.h
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_WINDOWS_GETTIMEOFDAY_H_
+#define _THRIFT_WINDOWS_GETTIMEOFDAY_H_
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+#ifndef _WIN32
+#error This is a MSVC header only.
+#endif
+
+int gettimeofday(struct timeval * tv, struct timezone * tz);
+
+#endif // _THRIFT_WINDOWS_GETTIMEOFDAY_H_
diff --git a/lib/cpp/src/windows/Operators.h b/lib/cpp/src/windows/Operators.h
new file mode 100644
index 0000000..95d8e3e
--- /dev/null
+++ b/lib/cpp/src/windows/Operators.h
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_WINDOWS_OPERATORS_H_
+#define _THRIFT_WINDOWS_OPERATORS_H_
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+namespace apache { namespace thrift {
+
+class TEnumIterator;
+
+inline bool operator == (const TEnumIterator&, const TEnumIterator&)
+{
+ // Not entirely sure what the test should be here. It is only to enable
+ // iterator debugging and is not used in release mode.
+ return true;
+}
+
+}} // apache::thrift
+
+#endif // _THRIFT_WINDOWS_OPERATORS_H_
diff --git a/lib/cpp/src/windows/SocketPair.cpp b/lib/cpp/src/windows/SocketPair.cpp
new file mode 100644
index 0000000..5eee4ae
--- /dev/null
+++ b/lib/cpp/src/windows/SocketPair.cpp
@@ -0,0 +1,96 @@
+/* socketpair.c
+ * Copyright 2007 by Nathan C. Myers <ncm@cantrip.org>; some rights reserved.
+ * This code is Free Software. It may be copied freely, in original or
+ * modified form, subject only to the restrictions that (1) the author is
+ * relieved from all responsibilities for any use for any purpose, and (2)
+ * this copyright notice must be retained, unchanged, in its entirety. If
+ * for any reason the author might be held responsible for any consequences
+ * of copying or use, license is withheld.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "SocketPair.h"
+
+// stl
+#include <string.h>
+
+// Win32
+#include <Winsock2.h>
+#include <WS2tcpip.h>
+
+int socketpair(int d, int type, int protocol, int sv[2])
+{
+ union {
+ struct sockaddr_in inaddr;
+ struct sockaddr addr;
+ } a;
+ SOCKET listener;
+ int e;
+ socklen_t addrlen = sizeof(a.inaddr);
+ DWORD flags = 0;
+ int reuse = 1;
+
+ if (sv == 0) {
+ WSASetLastError(WSAEINVAL);
+ return SOCKET_ERROR;
+ }
+
+ listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (listener == INVALID_SOCKET)
+ return SOCKET_ERROR;
+
+ memset(&a, 0, sizeof(a));
+ a.inaddr.sin_family = AF_INET;
+ a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ a.inaddr.sin_port = 0;
+
+ sv[0] = sv[1] = INVALID_SOCKET;
+ do {
+ if (setsockopt(listener, SOL_SOCKET, SO_REUSEADDR,
+ (char*) &reuse, (socklen_t) sizeof(reuse)) == -1)
+ break;
+ if (bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
+ break;
+ if (getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR)
+ break;
+ if (listen(listener, 1) == SOCKET_ERROR)
+ break;
+ sv[0] = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, flags);
+ if (sv[0] == INVALID_SOCKET)
+ break;
+ if (connect(sv[0], &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
+ break;
+ sv[1] = accept(listener, NULL, NULL);
+ if (sv[1] == INVALID_SOCKET)
+ break;
+
+ closesocket(listener);
+ return 0;
+
+ } while (0);
+
+ e = WSAGetLastError();
+ closesocket(listener);
+ closesocket(sv[0]);
+ closesocket(sv[1]);
+ WSASetLastError(e);
+ return SOCKET_ERROR;
+}
diff --git a/lib/cpp/src/windows/SocketPair.h b/lib/cpp/src/windows/SocketPair.h
new file mode 100644
index 0000000..27ec9b1
--- /dev/null
+++ b/lib/cpp/src/windows/SocketPair.h
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_WINDOWS_SOCKETPAIR_H_
+#define _THRIFT_WINDOWS_SOCKETPAIR_H_ 1
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+#ifndef _WIN32
+#error This is a MSVC header only.
+#endif
+
+int socketpair(int d, int type, int protocol, int sv[2]);
+
+#endif // _THRIFT_WINDOWS_SOCKETPAIR_H_
diff --git a/lib/cpp/src/windows/StdAfx.cpp b/lib/cpp/src/windows/StdAfx.cpp
new file mode 100644
index 0000000..5e49487
--- /dev/null
+++ b/lib/cpp/src/windows/StdAfx.cpp
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "stdafx.h"
diff --git a/lib/cpp/src/windows/StdAfx.h b/lib/cpp/src/windows/StdAfx.h
new file mode 100644
index 0000000..b953b22
--- /dev/null
+++ b/lib/cpp/src/windows/StdAfx.h
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_WINDOWS_STDAFX_H_
+#define _THRIFT_WINDOWS_STDAFX_H_
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+#ifndef _WIN32
+#error This is a MSVC header only.
+#endif
+
+#include "TargetVersion.h"
+#include "Config.h"
+
+// Exclude rarely-used stuff from Windows headers
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+
+#endif // _THRIFT_WINDOWS_STDAFX_H_
diff --git a/lib/cpp/src/windows/TWinsockSingleton.cpp b/lib/cpp/src/windows/TWinsockSingleton.cpp
new file mode 100644
index 0000000..aae25ab
--- /dev/null
+++ b/lib/cpp/src/windows/TWinsockSingleton.cpp
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "StdAfx.h"
+#include "TWinsockSingleton.h"
+
+// boost
+#include <boost/assert.hpp>
+
+namespace apache { namespace thrift { namespace transport {
+
+TWinsockSingleton::instance_ptr TWinsockSingleton::instance_ptr_(NULL);
+boost::once_flag TWinsockSingleton::flags_ = BOOST_ONCE_INIT;
+
+//------------------------------------------------------------------------------
+TWinsockSingleton::TWinsockSingleton(void)
+{
+ WORD version(MAKEWORD(2, 2));
+ WSAData data = {0};
+
+ int error(WSAStartup(version, &data));
+ if (error != 0)
+ {
+ BOOST_ASSERT(false);
+ throw std::runtime_error("Failed to initialise Winsock.");
+ }
+}
+
+//------------------------------------------------------------------------------
+TWinsockSingleton::~TWinsockSingleton(void)
+{
+ WSACleanup();
+}
+
+//------------------------------------------------------------------------------
+void TWinsockSingleton::create(void)
+{
+ boost::call_once(init, flags_);
+}
+
+//------------------------------------------------------------------------------
+void TWinsockSingleton::init(void)
+{
+ instance_ptr_.reset(new TWinsockSingleton);
+}
+
+}}} // apache::thrift::transport
diff --git a/lib/cpp/src/windows/TWinsockSingleton.h b/lib/cpp/src/windows/TWinsockSingleton.h
new file mode 100644
index 0000000..134c7b0
--- /dev/null
+++ b/lib/cpp/src/windows/TWinsockSingleton.h
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_TRANSPORT_WINDOWS_TWINSOCKSINGLETON_H_
+#define _THRIFT_TRANSPORT_WINDOWS_TWINSOCKSINGLETON_H_ 1
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+#ifndef _WIN32
+#error This is a MSVC header only.
+#endif
+
+// boost
+#include <boost/noncopyable.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/thread/once.hpp>
+
+namespace apache { namespace thrift { namespace transport {
+
+/**
+ * Winsock2 must be intialised once only in order to create sockets. This class
+ * performs a one time initialisation when create is called.
+ */
+class TWinsockSingleton : private boost::noncopyable
+{
+
+public:
+
+ typedef boost::scoped_ptr<TWinsockSingleton> instance_ptr;
+
+private:
+
+ friend void boost::call_once(void (*func)(void), boost::once_flag& flag);
+
+private:
+
+ TWinsockSingleton(void);
+
+public:
+
+ ~TWinsockSingleton(void);
+
+public:
+
+ static void create(void);
+
+private:
+
+ static void init(void);
+
+private:
+
+ static instance_ptr instance_ptr_;
+ static boost::once_flag flags_;
+};
+
+}}} // apache::thrift::transport
+
+#endif // _THRIFT_TRANSPORT_WINDOWS_TWINSOCKSINGLETON_H_
diff --git a/lib/cpp/src/windows/TargetVersion.h b/lib/cpp/src/windows/TargetVersion.h
new file mode 100644
index 0000000..7374666
--- /dev/null
+++ b/lib/cpp/src/windows/TargetVersion.h
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THIRFT_WINDOWS_TARGETVERSION_H_
+#define _THIRFT_WINDOWS_TARGETVERSION_H_
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+#ifndef _WIN32
+#error This is a MSVC header only.
+#endif
+
+#include <SDKDDKVer.h>
+
+#endif //_THIRFT_WINDOWS_TARGETVERSION_H_
diff --git a/lib/cpp/src/windows/config.h b/lib/cpp/src/windows/config.h
new file mode 100644
index 0000000..29a01f6
--- /dev/null
+++ b/lib/cpp/src/windows/config.h
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_WINDOWS_CONFIG_H_
+#define _THRIFT_WINDOWS_CONFIG_H_ 1
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+#ifndef _WIN32
+#error This is a MSVC header only.
+#endif
+
+#include "TargetVersion.h"
+#include "GetTimeOfDay.h"
+#include "Operators.h"
+#include "TWinsockSingleton.h"
+#include "Fcntl.h"
+#include "SocketPair.h"
+
+// boost
+#include <boost/cstdint.hpp>
+
+typedef boost::int64_t int64_t;
+typedef boost::uint32_t uint32_t;
+typedef boost::uint8_t uint8_t;
+
+// windows
+#include <Winsock2.h>
+#include <ws2tcpip.h>
+#pragma comment(lib, "Ws2_32.lib")
+
+// pthreads
+#include <pthread.h>
+
+//"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
+
+// 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
+
+inline void close(SOCKET socket)
+{
+ ::closesocket(socket);
+}
+
+#endif // _THRIFT_WINDOWS_CONFIG_H_
diff --git a/lib/cpp/src/windows/force_inc.h b/lib/cpp/src/windows/force_inc.h
new file mode 100644
index 0000000..aa81c42
--- /dev/null
+++ b/lib/cpp/src/windows/force_inc.h
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_WINDOWS_FORCEINC_H_
+#define _THRIFT_WINDOWS_FORCEINC_H_
+
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+#pragma once
+#endif // _MSC_VER
+
+#ifndef _WIN32
+#error This is a MSVC header only.
+#endif
+
+#undef gai_strerror
+#define gai_strerror gai_strerrorA
+
+#undef errno
+#undef EINTR
+#undef EINPROGRESS
+#undef ECONNRESET
+#undef ENOTCONN
+#undef ETIMEDOUT
+#undef EWOULDBLOCK
+#undef EAGAIN
+#undef EPIPE
+#define errno ::WSAGetLastError()
+#define EINPROGRESS WSAEINPROGRESS
+#define EAGAIN WSAEWOULDBLOCK
+#define EINTR WSAEINTR
+#define ECONNRESET WSAECONNRESET
+#define ENOTCONN WSAENOTCONN
+#define ETIMEDOUT WSAETIMEDOUT
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#define EPIPE WSAECONNRESET
+
+#endif // _THRIFT_WINDOWS_FORCEINC_H_
diff --git a/lib/cpp/src/windows/tr1/functional b/lib/cpp/src/windows/tr1/functional
new file mode 100644
index 0000000..ebee384
--- /dev/null
+++ b/lib/cpp/src/windows/tr1/functional
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <functional>