Updated Branches: refs/heads/master 0928eda77 -> 7cb7fc8a7
http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/transport/TSocket.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TSocket.h b/lib/cpp/src/thrift/transport/TSocket.h index b916a3e..60b5b51 100644 --- a/lib/cpp/src/thrift/transport/TSocket.h +++ b/lib/cpp/src/thrift/transport/TSocket.h @@ -25,6 +25,7 @@ #include "TTransport.h" #include "TVirtualTransport.h" #include "TServerSocket.h" +#include "PlatformSocket.h" #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> @@ -35,9 +36,6 @@ #ifdef HAVE_NETDB_H #include <netdb.h> #endif -#ifndef _WIN32 - typedef int SOCKET; -#endif namespace apache { namespace thrift { namespace transport { @@ -175,7 +173,7 @@ class TSocket : public TVirtualTransport<TSocket> { void setSendTimeout(int ms); /** - * Set the max number of recv retries in case of an EAGAIN + * Set the max number of recv retries in case of an THRIFT_EAGAIN * error */ void setMaxRecvRetries(int maxRecvRetries); @@ -203,7 +201,7 @@ class TSocket : public TVirtualTransport<TSocket> { /** * Returns the underlying socket file descriptor. */ - SOCKET getSocketFD() { + THRIFT_SOCKET getSocketFD() { return socket_; } @@ -214,7 +212,7 @@ class TSocket : public TVirtualTransport<TSocket> { * * @param fd the descriptor for an already-connected socket */ - void setSocketFD(int fd); + void setSocketFD(THRIFT_SOCKET fd); /* * Returns a cached copy of the peer address. @@ -234,7 +232,7 @@ class TSocket : public TVirtualTransport<TSocket> { /** * Constructor to create socket from raw UNIX handle. */ - TSocket(SOCKET socket); + TSocket(THRIFT_SOCKET socket); /** * Set a cache of the peer address (used when trivially available: e.g. @@ -265,7 +263,7 @@ class TSocket : public TVirtualTransport<TSocket> { std::string path_; /** Underlying UNIX socket handle */ - SOCKET socket_; + THRIFT_SOCKET socket_; /** Connect timeout in ms */ int connTimeout_; @@ -297,9 +295,6 @@ class TSocket : public TVirtualTransport<TSocket> { sockaddr_in6 ipv6; } cachedPeerAddr_; - /** Connection start time */ - timespec startTime_; - /** Whether to use low minimum TCP retransmission timeout */ static bool useLowMinRto_; http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/transport/TSocketPool.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/transport/TSocketPool.h b/lib/cpp/src/thrift/transport/TSocketPool.h index 48e35bb..f8c5ddc 100644 --- a/lib/cpp/src/thrift/transport/TSocketPool.h +++ b/lib/cpp/src/thrift/transport/TSocketPool.h @@ -49,7 +49,7 @@ class TSocketPoolServer { int port_; // Socket for the server - SOCKET socket_; + THRIFT_SOCKET socket_; // Last time connecting to this server failed time_t lastFailTime_; http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp b/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp index 6201eda..4f0ac55 100644 --- a/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp +++ b/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp @@ -35,7 +35,7 @@ struct timezone int tz_dsttime; /* type of dst correction */ }; -int gettimeofday(struct timeval * tv, struct timezone * tz) +int thrift_gettimeofday(struct timeval * tv, struct timezone * tz) { FILETIME ft; unsigned __int64 tmpres(0); @@ -50,7 +50,7 @@ int gettimeofday(struct timeval * tv, struct timezone * tz) tmpres |= ft.dwLowDateTime; /*converting file time to unix epoch*/ - tmpres -= DELTA_EPOCH_IN_MICROSECS; + tmpres -= DELTA_EPOCH_IN_MICROSECS; tmpres /= 10; /*convert into microseconds*/ tv->tv_sec = (long)(tmpres / 1000000UL); tv->tv_usec = (long)(tmpres % 1000000UL); @@ -90,3 +90,23 @@ int gettimeofday(struct timeval * tv, struct timezone * tz) return -1; } + +int thrift_sleep(unsigned int seconds) +{ + ::Sleep(seconds * 1000); + return 0; +} +int thrift_usleep(unsigned int microseconds) +{ + unsigned int milliseconds = (microseconds + 999)/ 1000; + ::Sleep(milliseconds); + return 0; +} + +char *thrift_ctime_r(const time_t *_clock, char *_buf) +{ + strcpy(_buf, ctime(_clock)); + return _buf; +} + + http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/GetTimeOfDay.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/GetTimeOfDay.h b/lib/cpp/src/thrift/windows/GetTimeOfDay.h index f6bdf1c..25ed254 100644 --- a/lib/cpp/src/thrift/windows/GetTimeOfDay.h +++ b/lib/cpp/src/thrift/windows/GetTimeOfDay.h @@ -28,6 +28,16 @@ #error This is a MSVC header only. #endif -int gettimeofday(struct timeval * tv, struct timezone * tz); +#include "config.h" + +struct thrift_timespec { + int64_t tv_sec; + int64_t tv_nsec; +}; + +int thrift_gettimeofday(struct timeval * tv, struct timezone * tz); +int thrift_sleep(unsigned int seconds); +int thrift_usleep(unsigned int micro_seconds); +char *thrift_ctime_r(const time_t *_clock, char *_buf); #endif // _THRIFT_WINDOWS_GETTIMEOFDAY_H_ http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/SocketPair.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/SocketPair.cpp b/lib/cpp/src/thrift/windows/SocketPair.cpp index bca8d92..45aa7e8 100644 --- a/lib/cpp/src/thrift/windows/SocketPair.cpp +++ b/lib/cpp/src/thrift/windows/SocketPair.cpp @@ -35,13 +35,13 @@ // Win32 #include <WS2tcpip.h> -int socketpair(int d, int type, int protocol, SOCKET sv[2]) +int thrift_socketpair(int d, int type, int protocol, THRIFT_SOCKET sv[2]) { union { struct sockaddr_in inaddr; struct sockaddr addr; } a; - SOCKET listener; + THRIFT_SOCKET listener; int e; socklen_t addrlen = sizeof(a.inaddr); DWORD flags = 0; @@ -63,9 +63,11 @@ int socketpair(int d, int type, int protocol, SOCKET sv[2]) sv[0] = sv[1] = INVALID_SOCKET; do { - if (setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, - (char*) &reuse, (socklen_t) sizeof(reuse)) == -1) - break; + //ignore errors coming out of this setsockopt. This is because + //SO_EXCLUSIVEADDRUSE requires admin privileges on WinXP, but we don't + //want to force socket pairs to be an admin. + setsockopt(listener, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, + (char*) &reuse, (socklen_t) sizeof(reuse)); if (bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR) break; if (getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR) http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/SocketPair.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/SocketPair.h b/lib/cpp/src/thrift/windows/SocketPair.h index 9d02998..1de5613 100644 --- a/lib/cpp/src/thrift/windows/SocketPair.h +++ b/lib/cpp/src/thrift/windows/SocketPair.h @@ -30,7 +30,8 @@ // Win32 #include <Winsock2.h> +#include "config.h" -int socketpair(int d, int type, int protocol, SOCKET sv[2]); +int thrift_socketpair(int d, int type, int protocol, THRIFT_SOCKET sv[2]); #endif // _THRIFT_WINDOWS_SOCKETPAIR_H_ http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/StdAfx.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/StdAfx.cpp b/lib/cpp/src/thrift/windows/StdAfx.cpp index 5e49487..e69de29 100644 --- a/lib/cpp/src/thrift/windows/StdAfx.cpp +++ b/lib/cpp/src/thrift/windows/StdAfx.cpp @@ -1,20 +0,0 @@ -/* - * 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" http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/StdAfx.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/StdAfx.h b/lib/cpp/src/thrift/windows/StdAfx.h index e6ebbba..e69de29 100644 --- a/lib/cpp/src/thrift/windows/StdAfx.h +++ b/lib/cpp/src/thrift/windows/StdAfx.h @@ -1,41 +0,0 @@ -/* - * 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 -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include <Windows.h> - -#endif // _THRIFT_WINDOWS_STDAFX_H_ http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp b/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp index aae25ab..a1c7e49 100644 --- a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp +++ b/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp @@ -17,16 +17,22 @@ * under the License. */ -#include "StdAfx.h" #include "TWinsockSingleton.h" // boost #include <boost/assert.hpp> +#include <stdexcept> namespace apache { namespace thrift { namespace transport { TWinsockSingleton::instance_ptr TWinsockSingleton::instance_ptr_(NULL); +#if USE_BOOST_THREAD boost::once_flag TWinsockSingleton::flags_ = BOOST_ONCE_INIT; +#elif USE_STD_THREAD +std::once_flag TWinsockSingleton::flags_; +#else +#error For windows you must choose USE_BOOST_THREAD or USE_STD_THREAD +#endif //------------------------------------------------------------------------------ TWinsockSingleton::TWinsockSingleton(void) @@ -51,7 +57,11 @@ TWinsockSingleton::~TWinsockSingleton(void) //------------------------------------------------------------------------------ void TWinsockSingleton::create(void) { +#if USE_BOOST_THREAD boost::call_once(init, flags_); +#elif USE_STD_THREAD + std::call_once(flags_, init); +#endif } //------------------------------------------------------------------------------ http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/TWinsockSingleton.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/TWinsockSingleton.h b/lib/cpp/src/thrift/windows/TWinsockSingleton.h index 134c7b0..f6e4b8c 100644 --- a/lib/cpp/src/thrift/windows/TWinsockSingleton.h +++ b/lib/cpp/src/thrift/windows/TWinsockSingleton.h @@ -28,10 +28,19 @@ #error This is a MSVC header only. #endif +#include <config.h> + // boost #include <boost/noncopyable.hpp> #include <boost/scoped_ptr.hpp> + +#if USE_BOOST_THREAD #include <boost/thread/once.hpp> +#elif USE_STD_THREAD +#include <mutex> +#else +#error For windows you must choose USE_BOOST_THREAD or USE_STD_THREAD +#endif namespace apache { namespace thrift { namespace transport { @@ -48,7 +57,9 @@ public: private: +#if USE_BOOST_THREAD friend void boost::call_once(void (*func)(void), boost::once_flag& flag); +#endif private: @@ -69,7 +80,13 @@ private: private: static instance_ptr instance_ptr_; +#if USE_BOOST_THREAD static boost::once_flag flags_; +#elif USE_STD_THREAD + static std::once_flag flags_; +#else +#error Need a non-Boost non-C++11 way to track single initialization here. +#endif }; }}} // apache::thrift::transport http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/TargetVersion.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/TargetVersion.h b/lib/cpp/src/thrift/windows/TargetVersion.h index 35c093f..e69de29 100644 --- a/lib/cpp/src/thrift/windows/TargetVersion.h +++ b/lib/cpp/src/thrift/windows/TargetVersion.h @@ -1,31 +0,0 @@ -/* - * 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 - -#endif //_THIRFT_WINDOWS_TARGETVERSION_H_ http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/WinFcntl.cpp ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/WinFcntl.cpp b/lib/cpp/src/thrift/windows/WinFcntl.cpp index da2f73a..86132e9 100644 --- a/lib/cpp/src/thrift/windows/WinFcntl.cpp +++ b/lib/cpp/src/thrift/windows/WinFcntl.cpp @@ -19,19 +19,19 @@ #include "WinFcntl.h" -int fcntl(SOCKET fd, int cmd, int flags) +int thrift_fcntl(THRIFT_SOCKET fd, int cmd, int flags) { - if(cmd != F_GETFL && cmd != F_SETFL) + if(cmd != THRIFT_F_GETFL && cmd != THRIFT_F_SETFL) { return -1; } - if(flags != O_NONBLOCK && flags != 0) + if(flags != THRIFT_O_NONBLOCK && flags != 0) { return -1; } - if(cmd == F_GETFL) + if(cmd == THRIFT_F_GETFL) { return 0; } @@ -48,3 +48,57 @@ int fcntl(SOCKET fd, int cmd, int flags) return res; } + +#if WINVER <= 0x0502 //XP, Server2003 +int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout) +{ + fd_set read_fds, write_fds; + fd_set* read_fds_ptr = NULL; + fd_set* write_fds_ptr = NULL; + + FD_ZERO(&read_fds); + FD_ZERO(&write_fds); + + for(ULONG i=0; i<nfds; i++) { + //Read (in) socket + if((fdArray[i].events & THRIFT_POLLIN) == THRIFT_POLLIN) { + read_fds_ptr = &read_fds; + FD_SET(fdArray[i].fd, &read_fds); + } + //Write (out) socket + else if((fdArray[i].events & THRIFT_POLLOUT) == THRIFT_POLLOUT) { + write_fds_ptr = &write_fds; + FD_SET(fdArray[i].fd, &write_fds); + } + } + + timeval time_out; + timeval* time_out_ptr = NULL; + if(timeout >= 0) { + timeval time_out = {timeout / 1000, timeout * 1000}; + time_out_ptr = &time_out; + } + else { //to avoid compiler warnings + (void)time_out; + (void)timeout; + } + + int sktready = select(1, read_fds_ptr, write_fds_ptr, NULL, time_out_ptr); + if(sktready > 0) { + for(ULONG i=0; i<nfds; i++) { + fdArray[i].revents = 0; + if(FD_ISSET(fdArray[i].fd, &read_fds)) + fdArray[i].revents |= THRIFT_POLLIN; + if(FD_ISSET(fdArray[i].fd, &write_fds)) + fdArray[i].revents |= THRIFT_POLLOUT; + } + } + return sktready; +} +#else //Vista, Win7... +int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout) +{ + return WSAPoll(fdArray, nfds, timeout); +} +#endif // WINVER + http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/WinFcntl.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/WinFcntl.h b/lib/cpp/src/thrift/windows/WinFcntl.h index be80c5b..8910a14 100644 --- a/lib/cpp/src/thrift/windows/WinFcntl.h +++ b/lib/cpp/src/thrift/windows/WinFcntl.h @@ -30,15 +30,17 @@ // Win32 #include <Winsock2.h> +#include <thrift/transport/PlatformSocket.h> -#define O_NONBLOCK 1 - -enum -{ - F_GETFL, - F_SETFL, +#if WINVER <= 0x0502 //XP, Server2003 +struct thrift_pollfd { + THRIFT_SOCKET fd; + SHORT events; + SHORT revents; }; +#endif -int fcntl(SOCKET fd, int cmd, int flags); +int thrift_fcntl(THRIFT_SOCKET fd, int cmd, int flags); +int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout); #endif // _THRIFT_WINDOWS_FCNTL_H_ http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/config.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/config.h b/lib/cpp/src/thrift/windows/config.h index d8b814c..25230c5 100644 --- a/lib/cpp/src/thrift/windows/config.h +++ b/lib/cpp/src/thrift/windows/config.h @@ -28,123 +28,63 @@ #error This is a MSVC header only. #endif -#pragma warning(disable: 4996) // Depreciated posix name. -#pragma warning(disable: 4250) // Inherits via dominance. +// use std::thread in MSVC11 (2012) or newer +#if _MSC_VER >= 1700 +# define USE_STD_THREAD 1 +// otherwise use boost threads +#else +# define USE_BOOST_THREAD 1 +#endif + +#ifndef TARGET_WIN_XP +# define TARGET_WIN_XP 1 +#endif + +#if TARGET_WIN_XP +# ifndef WINVER +# define WINVER 0x0501 +# endif +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0501 +# endif +#endif + +#ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0601 +#endif + +#pragma warning(disable: 4996) // Deprecated posix name. #define VERSION "1.0.0-dev" #define HAVE_GETTIMEOFDAY 1 #define HAVE_SYS_STAT_H 1 -#include "TargetVersion.h" +#ifdef HAVE_STDINT_H +# include <stdint.h> +#else +# include <boost/cstdint.hpp> + +typedef boost::int64_t int64_t; +typedef boost::uint64_t uint64_t; +typedef boost::int32_t int32_t; +typedef boost::uint32_t uint32_t; +typedef boost::int16_t int16_t; +typedef boost::uint16_t uint16_t; +typedef boost::int8_t int8_t; +typedef boost::uint8_t uint8_t; +#endif + +#include <thrift/transport/PlatformSocket.h> #include "GetTimeOfDay.h" #include "Operators.h" #include "TWinsockSingleton.h" #include "WinFcntl.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") #pragma comment(lib, "advapi32.lib") //For security APIs in TPipeServer -// pthreads -#if 0 -# include <pthread.h> -#else -struct timespec { - int64_t tv_sec; - int64_t tv_nsec; -}; -# define USE_BOOST_THREAD 1 -# define ctime_r( _clock, _buf ) \ - ( strcpy( (_buf), ctime( (_clock) ) ), \ - (_buf) ) -#endif - -typedef ptrdiff_t ssize_t; - -// Missing functions. -#define usleep(ms) Sleep(ms) -inline int sleep(DWORD ms) -{ - Sleep(ms); - return 0; -} - -#if WINVER <= 0x0502 //XP, Server2003 -#define POLLIN 0x0300 -#define POLLOUT 0x0010 -#define poll(fds, nfds, timeout) \ - poll_win32(fds, nfds, timeout) - -typedef struct pollfd { - SOCKET fd; - SHORT events; - SHORT revents; -} WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD; - -inline int poll_win32(LPWSAPOLLFD fdArray, ULONG nfds, INT timeout) -{ - fd_set read_fds, write_fds; - fd_set* read_fds_ptr = NULL; - fd_set* write_fds_ptr = NULL; - - FD_ZERO(&read_fds); - FD_ZERO(&write_fds); - - for(ULONG i=0; i<nfds; i++) { - //Read (in) socket - if((fdArray[i].events & POLLIN) == POLLIN) { - read_fds_ptr = &read_fds; - FD_SET(fdArray[i].fd, &read_fds); - } - //Write (out) socket - else if((fdArray[i].events & POLLOUT) == POLLOUT) { - write_fds_ptr = &write_fds; - FD_SET(fdArray[i].fd, &write_fds); - } - } - - timeval time_out; - timeval* time_out_ptr = NULL; - if(timeout >= 0) { - timeval time_out = {timeout / 1000, timeout * 1000}; - time_out_ptr = &time_out; - } - else { //to avoid compiler warnings - (void)time_out; - (void)timeout; - } - - int sktready = select(1, read_fds_ptr, write_fds_ptr, NULL, time_out_ptr); - if(sktready > 0) { - for(ULONG i=0; i<nfds; i++) { - fdArray[i].revents = 0; - if(FD_ISSET(fdArray[i].fd, &read_fds)) - fdArray[i].revents |= POLLIN; - if(FD_ISSET(fdArray[i].fd, &write_fds)) - fdArray[i].revents |= POLLOUT; - } - } - return sktready; -} -#else //Vista, Win7... - inline int poll(struct pollfd* fdArray, ULONG fds, INT timeout) { - return WSAPoll(fdArray, fds, timeout); - } -#endif // WINVER - -inline int close(SOCKET socket) -{ - return ::closesocket(socket); -} - #endif // _THRIFT_WINDOWS_CONFIG_H_ http://git-wip-us.apache.org/repos/asf/thrift/blob/7cb7fc8a/lib/cpp/src/thrift/windows/force_inc.h ---------------------------------------------------------------------- diff --git a/lib/cpp/src/thrift/windows/force_inc.h b/lib/cpp/src/thrift/windows/force_inc.h index 38eb134..e69de29 100644 --- a/lib/cpp/src/thrift/windows/force_inc.h +++ b/lib/cpp/src/thrift/windows/force_inc.h @@ -1,77 +0,0 @@ -/* - * 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 - -#ifndef NOMINMAX -# define NOMINMAX -#endif -#ifndef USE_BOOST_THREAD -# define BOOST_ALL_NO_LIB 1 -# define BOOST_THREAD_NO_LIB 1 -#endif -#define TARGET_WIN_XP - -#ifdef TARGET_WIN_XP -# ifndef WINVER -# define WINVER 0x0501 -# endif -# ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x0501 -# endif -#endif - -#ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x0601 -#endif - -#include "config.h" - -#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_
