From ab4d799807bdcf6ecb74c6c0ffd655d6a1a965ad Mon Sep 17 00:00:00 2001 From: alzarei Date: Mon, 16 Feb 2015 14:41:28 -0800 Subject: DRILL-1219. C++ Client. Fix timeout for 32-bit windows platform --- contrib/native/client/src/clientlib/drillClientImpl.cpp | 11 +++++++++++ contrib/native/client/src/clientlib/drillClientImpl.hpp | 13 ++++++------- contrib/native/client/src/include/drill/common.hpp | 8 ++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'contrib/native/client') diff --git a/contrib/native/client/src/clientlib/drillClientImpl.cpp b/contrib/native/client/src/clientlib/drillClientImpl.cpp index f9c17f9de..ea3a7ee9d 100644 --- a/contrib/native/client/src/clientlib/drillClientImpl.cpp +++ b/contrib/native/client/src/clientlib/drillClientImpl.cpp @@ -196,6 +196,12 @@ connectionStatus_t DrillClientImpl::recvHandshake(){ if(m_rbuf!=NULL){ Utils::freeBuffer(m_rbuf, MAX_SOCK_RD_BUFSIZE); m_rbuf=NULL; } +#ifdef WIN32_SHUTDOWN_ON_TIMEOUT + if (m_pError != NULL) { + return static_cast(m_pError->status); + } +#endif // WIN32_SHUTDOWN_ON_TIMEOUT + return CONN_SUCCESS; } @@ -731,7 +737,12 @@ void DrillClientImpl::handleReadTimeout(const boost::system::error_code & err){ // to have the BOOST_ASIO_ENABLE_CANCELIO macro (as well as the BOOST_ASIO_DISABLE_IOCP macro?) // defined. To be really sure, we need to close the socket. Closing the socket is a bit // drastic and we will defer that till a later release. +#ifdef WIN32_SHUTDOWN_ON_TIMEOUT + boost::system::error_code ignorederr; + m_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignorederr); +#else // NOT WIN32_SHUTDOWN_ON_TIMEOUT m_socket.cancel(); +#endif // WIN32_SHUTDOWN_ON_TIMEOUT } } return; diff --git a/contrib/native/client/src/clientlib/drillClientImpl.hpp b/contrib/native/client/src/clientlib/drillClientImpl.hpp index c87e1b7d4..d287bfc17 100644 --- a/contrib/native/client/src/clientlib/drillClientImpl.hpp +++ b/contrib/native/client/src/clientlib/drillClientImpl.hpp @@ -20,15 +20,14 @@ #ifndef DRILL_CLIENT_IMPL_H #define DRILL_CLIENT_IMPL_H -/* Define some BOOST defines */ +#include "drill/common.hpp" + +// Define some BOOST defines +// WIN32_SHUTDOWN_ON_TIMEOUT is defined in "drill/common.hpp" for Windows 32 bit platform +#ifndef WIN32_SHUTDOWN_ON_TIMEOUT #define BOOST_ASIO_ENABLE_CANCELIO -// If we want to support older versions of windows than Windows 7, we should -// disable IOCP -//#ifdef _WIN32 -//#define BOOST_ASIO_DISABLE_IOCP -//#endif // _WIN32 +#endif //WIN32_SHUTDOWN_ON_TIMEOUT -#include "drill/common.hpp" #include #include #include diff --git a/contrib/native/client/src/include/drill/common.hpp b/contrib/native/client/src/include/drill/common.hpp index 824d67062..e149ed11d 100644 --- a/contrib/native/client/src/include/drill/common.hpp +++ b/contrib/native/client/src/include/drill/common.hpp @@ -50,6 +50,14 @@ #define CODER_DEBUGGING #endif +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/basic_stream_socket/cancel/overload1.html +// : "Calls to cancel() will always fail with boost::asio::error::operation_not_supported when run on Windows XP, Windows Server 2003, and earlier versions of Windows..." +// As such, achieving cancel needs to be implemented differently; +#if defined(_WIN32) && !defined(_WIN64) +#define WIN32_SHUTDOWN_ON_TIMEOUT +#endif // _WIN32 && !_WIN64 + + namespace Drill { typedef std::vector DataBuf; -- cgit v1.2.3