Loading src/Client.cpp +83 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,89 @@ void Client::handleResolve(const boost::system::error_code& errorCode, } } //============================================================================== // Client::handleRequest() //============================================================================== void Client::handleWriteRequest(const boost::system::error_code& errorCode) { DEBUG_STREAM << "Client::handleRequest()" << endl; if(!errorCode) { startReadResponseHeader(); } else { ERROR_STREAM << "Client::handleRequest() " << errorCode.message() << endl; } } //============================================================================== // Client::handleReadResponseHeader() //============================================================================== void Client::handleReadResponseHeader(const boost::system::error_code& errorCode) { DEBUG_STREAM << "Client::handleReadResponseHeader()" << endl; if(!errorCode) { boost::uint32_t bodySize = decodeHeader(m_readBuff); DEBUG_STREAM << "Client::handleReadResponseHeader() SIZE: " << bodySize << endl; startReadResponseBody(bodySize); } else { ERROR_STREAM << "Client::handleReadResponseHeader() " << errorCode.message() << endl; } } //============================================================================== // Client::handleReadResponseBody() //============================================================================== void Client::handleReadResponseBody(const boost::system::error_code& errorCode) { DEBUG_STREAM << "Client::handleReadResponseBody()" << endl; if(!errorCode) { ResponseSP response_sp(new Response); response_sp->ParseFromArray(&m_readBuff[HEADER_SIZE], m_readBuff.size() - HEADER_SIZE); processAuthorisationResponse(response_sp); m_requestResponseTimer.expires_from_now(boost::posix_time::seconds(10)); m_requestResponseTimer.async_wait(boost::bind(&Client::startWriteRequest, this)); } else { ERROR_STREAM << "Client::handleResponse() " << errorCode.message() << endl; } } //============================================================================== // Client::resetConnection() //============================================================================== void Client::resetConnection() { DEBUG_STREAM << "Client::resetConnection()" << endl; if(m_resetConnectionTimer.expires_at() <= boost::asio::deadline_timer::traits_type::now()) { closeConnection(); m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin); m_requestResponseTimer.expires_at(boost::posix_time::pos_infin); startResolve(); } m_resetConnectionTimer.async_wait(boost::bind(&Client::resetConnection, this)); } //============================================================================== // Client::createAuthorisationRequest() //============================================================================== Loading src/Client.h +46 −23 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ public: typedef boost::shared_ptr<Client> SP; //------------------------------------------------------------------------------ // [Public] Request Response shared pointer typedef // [Public] Request Response classes shared pointer typedef //------------------------------------------------------------------------------ typedef boost::shared_ptr<Request> RequestSP; typedef boost::shared_ptr<Response> ResponseSP; Loading @@ -44,14 +44,14 @@ protected: public: //------------------------------------------------------------------------------ // [Public] Users abstract methods // [Public] Thread management methods //------------------------------------------------------------------------------ virtual void start() = 0; virtual void stop() = 0; //------------------------------------------------------------------------------ // [Public] Users methods // [Public] State status methods //------------------------------------------------------------------------------ virtual Tango::DevState readState(); Loading @@ -59,50 +59,73 @@ public: protected: //------------------------------------------------------------------------------ // [Protected] Utilities methods // [Protected] IO service run thread method //------------------------------------------------------------------------------ virtual void run(); //------------------------------------------------------------------------------ // [Protected] Endpoint resolution methods //------------------------------------------------------------------------------ virtual void startResolve(); virtual void handleResolve(const boost::system::error_code&, boost::asio::ip::tcp::resolver::iterator); virtual RequestSP createAuthorisationRequest(); virtual void processAuthorisationResponse(ResponseSP); virtual RequestSP createMetadataRequest(); virtual void processMetadataResponse(ResponseSP); virtual void encodeHeader(std::vector<boost::uint8_t>&, boost::uint32_t) throw(std::runtime_error); virtual boost::uint32_t decodeHeader(std::vector<boost::uint8_t>&) throw(std::runtime_error); //------------------------------------------------------------------------------ // [Protected] Utilities abstract methods // [Protected] Connection initialization methods //------------------------------------------------------------------------------ virtual void startConnect(boost::asio::ip::tcp::resolver::iterator) = 0; virtual void handleConnect(const boost::system::error_code&, boost::asio::ip::tcp::resolver::iterator) = 0; //------------------------------------------------------------------------------ // [Protected] Write request methods //------------------------------------------------------------------------------ virtual void startWriteRequest() = 0; virtual void handleWriteRequest(const boost::system::error_code&) = 0; virtual void handleWriteRequest(const boost::system::error_code&); //------------------------------------------------------------------------------ // [Protected] Read response header methods //------------------------------------------------------------------------------ virtual void startReadResponseHeader() = 0; virtual void handleReadResponseHeader(const boost::system::error_code&) = 0; virtual void handleReadResponseHeader(const boost::system::error_code&); //------------------------------------------------------------------------------ // [Protected] Read response body methods //------------------------------------------------------------------------------ virtual void startReadResponseBody(boost::uint32_t) = 0; virtual void handleReadResponseBody(const boost::system::error_code&) = 0; virtual void handleReadResponseBody(const boost::system::error_code&); virtual void resetConnection() = 0; //------------------------------------------------------------------------------ // [Protected] Connection reset and timeout handler methods //------------------------------------------------------------------------------ virtual void closeConnection() = 0; virtual void resetConnection(); //------------------------------------------------------------------------------ // [Protected] Request response methods //------------------------------------------------------------------------------ virtual RequestSP createAuthorisationRequest(); virtual void processAuthorisationResponse(ResponseSP); virtual RequestSP createMetadataRequest(); virtual void processMetadataResponse(ResponseSP); //------------------------------------------------------------------------------ // [Protected] Header encoding decoding methods //------------------------------------------------------------------------------ virtual void encodeHeader(std::vector<boost::uint8_t>&, boost::uint32_t) throw(std::runtime_error); virtual boost::uint32_t decodeHeader(std::vector<boost::uint8_t>&) throw(std::runtime_error); //------------------------------------------------------------------------------ // [Protected] Class variables Loading src/PlainClient.cpp +8 −89 Original line number Diff line number Diff line Loading @@ -22,10 +22,7 @@ PlainClient::~PlainClient() { DEBUG_STREAM << "PlainClient::~PlainClient()" << endl; boost::system::error_code errorCode; m_plainSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_plainSocket.close(errorCode); closeConnection(); } //============================================================================== Loading Loading @@ -59,10 +56,7 @@ void PlainClient::stop() { DEBUG_STREAM << "PlainClient::stop()" << endl; boost::system::error_code errorCode; m_plainSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_plainSocket.close(errorCode); closeConnection(); Client::stop(); } Loading Loading @@ -141,23 +135,6 @@ void PlainClient::startWriteRequest() boost::asio::placeholders::error)); } //============================================================================== // PlainClient::handleRequest() //============================================================================== void PlainClient::handleWriteRequest(const boost::system::error_code& errorCode) { DEBUG_STREAM << "PlainClient::handleRequest()" << endl; if(!errorCode) { startReadResponseHeader(); } else { ERROR_STREAM << "PlainClient::handleRequest() " << errorCode.message() << endl; } } //============================================================================== // PlainClient::startReadResponseHeader() //============================================================================== Loading @@ -175,27 +152,6 @@ void PlainClient::startReadResponseHeader() boost::asio::placeholders::error)); } //============================================================================== // PlainClient::handleReadResponseHeader() //============================================================================== void PlainClient::handleReadResponseHeader(const boost::system::error_code& errorCode) { DEBUG_STREAM << "PlainClient::handleReadResponseHeader()" << endl; if(!errorCode) { boost::uint32_t bodySize = decodeHeader(m_readBuff); DEBUG_STREAM << "PlainClient::handleReadResponseHeader() SIZE: " << bodySize << endl; startReadResponseBody(bodySize); } else { ERROR_STREAM << "PlainClient::handleReadResponseHeader() " << errorCode.message() << endl; } } //============================================================================== // PlainClient::startReadResponseBody() //============================================================================== Loading @@ -214,53 +170,16 @@ void PlainClient::startReadResponseBody(boost::uint32_t bodySize) } //============================================================================== // PlainClient::handleReadResponseBody() //============================================================================== void PlainClient::handleReadResponseBody(const boost::system::error_code& errorCode) { DEBUG_STREAM << "PlainClient::handleReadResponseBody()" << endl; if(!errorCode) { ResponseSP response_sp(new Response); response_sp->ParseFromArray(&m_readBuff[HEADER_SIZE], m_readBuff.size() - HEADER_SIZE); processAuthorisationResponse(response_sp); m_requestResponseTimer.expires_from_now(boost::posix_time::seconds(10)); m_requestResponseTimer.async_wait(boost::bind(&PlainClient::startWriteRequest, this)); } else { ERROR_STREAM << "PlainClient::handleResponse() " << errorCode.message() << endl; } } //============================================================================== // PlainClient::resetConnection() // PlainClient::closeConnection() //============================================================================== void PlainClient::resetConnection() void PlainClient::closeConnection() { DEBUG_STREAM << "PlainClient::resetConnection()" << endl; if(m_resetConnectionTimer.expires_at() <= boost::asio::deadline_timer::traits_type::now()) { INFO_STREAM << "PlainClient::resetConnection() closing socket" << endl; DEBUG_STREAM << "PlainClient::closeConnection()" << endl; boost::system::error_code errorCode; m_plainSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_plainSocket.close(errorCode); m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin); m_requestResponseTimer.expires_at(boost::posix_time::pos_infin); startResolve(); } m_resetConnectionTimer.async_wait(boost::bind(&PlainClient::resetConnection, this)); } } //namespace src/PlainClient.h +1 −7 Original line number Diff line number Diff line Loading @@ -45,17 +45,11 @@ protected: virtual void startWriteRequest(); virtual void handleWriteRequest(const boost::system::error_code&); virtual void startReadResponseHeader(); virtual void handleReadResponseHeader(const boost::system::error_code&); virtual void startReadResponseBody(boost::uint32_t); virtual void handleReadResponseBody(const boost::system::error_code&); virtual void resetConnection(); virtual void closeConnection(); //------------------------------------------------------------------------------ // [Protected] Class variables Loading src/SSLClient.cpp +50 −40 Original line number Diff line number Diff line Loading @@ -39,13 +39,7 @@ SSLClient::~SSLClient() { DEBUG_STREAM << "SSLClient::~SSLClient()" << endl; boost::system::error_code errorCode; m_sSLSocket.shutdown(errorCode); m_sSLSocket.lowest_layer().shutdown( boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_sSLSocket.lowest_layer().close(errorCode); closeConnection(); } //============================================================================== Loading Loading @@ -80,13 +74,7 @@ void SSLClient::stop() { DEBUG_STREAM << "SSLClient::stop()" << endl; boost::system::error_code errorCode; m_sSLSocket.shutdown(errorCode); m_sSLSocket.lowest_layer().shutdown( boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_sSLSocket.lowest_layer().close(errorCode); closeConnection(); Client::stop(); } Loading Loading @@ -194,14 +182,25 @@ void SSLClient::handleHandShake(const boost::system::error_code& errorCode) void SSLClient::startWriteRequest() { DEBUG_STREAM << "SSLClient::startWriteRequest()" << endl; } //============================================================================== // SSLClient::handleWriteRequest() //============================================================================== void SSLClient::handleWriteRequest(const boost::system::error_code&) { DEBUG_STREAM << "SSLClient::handleWriteRequest()" << endl; RequestSP request_sp = createAuthorisationRequest(); boost::uint32_t bodySize = request_sp->ByteSize(); DEBUG_STREAM << "PlainClient::startRequest() SIZE " << bodySize << endl; std::vector<boost::uint8_t> writeBuff; writeBuff.resize(HEADER_SIZE + bodySize); encodeHeader(writeBuff, bodySize); request_sp->SerializeToArray(&writeBuff[HEADER_SIZE], bodySize); m_resetConnectionTimer.expires_from_now(boost::posix_time::seconds(30)); boost::asio::async_write(m_sSLSocket, boost::asio::buffer(writeBuff), boost::bind(&SSLClient::handleWriteRequest, this, boost::asio::placeholders::error)); } //============================================================================== Loading @@ -210,38 +209,49 @@ void SSLClient::handleWriteRequest(const boost::system::error_code&) void SSLClient::startReadResponseHeader() { DEBUG_STREAM << "SSLClient::startReadResponseHeader()" << endl; } //============================================================================== // SSLClient::handleReadResponseHeader() //============================================================================== void SSLClient::handleReadResponseHeader(const boost::system::error_code&) { DEBUG_STREAM << "SSLClient::handleReadResponseHeader()" << endl; m_readBuff.resize(HEADER_SIZE); m_resetConnectionTimer.expires_from_now(boost::posix_time::seconds(30)); boost::asio::async_read(m_sSLSocket, boost::asio::buffer(m_readBuff), boost::bind( &SSLClient::handleReadResponseHeader, this, boost::asio::placeholders::error)); } //============================================================================== // SSLClient::startReadResponseBody() //============================================================================== void SSLClient::startReadResponseBody(boost::uint32_t) void SSLClient::startReadResponseBody(boost::uint32_t bodySize) { DEBUG_STREAM << "SSLClient::startReadResponseBody()" << endl; } //============================================================================== // SSLClient::handleReadResponseBody() //============================================================================== void SSLClient::handleReadResponseBody(const boost::system::error_code&) { DEBUG_STREAM << "SSLClient::handleReadResponseBody()" << endl; m_readBuff.resize(HEADER_SIZE + bodySize); boost::asio::mutable_buffers_1 mutableBuffer = boost::asio::buffer(&m_readBuff[HEADER_SIZE], bodySize); boost::asio::async_read(m_sSLSocket, mutableBuffer, boost::bind(&SSLClient::handleReadResponseBody, this, boost::asio::placeholders::error)); } //============================================================================== // SSLClient::resetConnection() // SSLClient::closeConnection() //============================================================================== void SSLClient::resetConnection() void SSLClient::closeConnection() { DEBUG_STREAM << "SSLClient::resetConnection()" << endl; DEBUG_STREAM << "SSLClient::closeConnection()" << endl; boost::system::error_code errorCode; m_sSLSocket.shutdown(errorCode); m_sSLSocket.lowest_layer().shutdown( boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_sSLSocket.lowest_layer().close(errorCode); } } //namespace Loading
src/Client.cpp +83 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,89 @@ void Client::handleResolve(const boost::system::error_code& errorCode, } } //============================================================================== // Client::handleRequest() //============================================================================== void Client::handleWriteRequest(const boost::system::error_code& errorCode) { DEBUG_STREAM << "Client::handleRequest()" << endl; if(!errorCode) { startReadResponseHeader(); } else { ERROR_STREAM << "Client::handleRequest() " << errorCode.message() << endl; } } //============================================================================== // Client::handleReadResponseHeader() //============================================================================== void Client::handleReadResponseHeader(const boost::system::error_code& errorCode) { DEBUG_STREAM << "Client::handleReadResponseHeader()" << endl; if(!errorCode) { boost::uint32_t bodySize = decodeHeader(m_readBuff); DEBUG_STREAM << "Client::handleReadResponseHeader() SIZE: " << bodySize << endl; startReadResponseBody(bodySize); } else { ERROR_STREAM << "Client::handleReadResponseHeader() " << errorCode.message() << endl; } } //============================================================================== // Client::handleReadResponseBody() //============================================================================== void Client::handleReadResponseBody(const boost::system::error_code& errorCode) { DEBUG_STREAM << "Client::handleReadResponseBody()" << endl; if(!errorCode) { ResponseSP response_sp(new Response); response_sp->ParseFromArray(&m_readBuff[HEADER_SIZE], m_readBuff.size() - HEADER_SIZE); processAuthorisationResponse(response_sp); m_requestResponseTimer.expires_from_now(boost::posix_time::seconds(10)); m_requestResponseTimer.async_wait(boost::bind(&Client::startWriteRequest, this)); } else { ERROR_STREAM << "Client::handleResponse() " << errorCode.message() << endl; } } //============================================================================== // Client::resetConnection() //============================================================================== void Client::resetConnection() { DEBUG_STREAM << "Client::resetConnection()" << endl; if(m_resetConnectionTimer.expires_at() <= boost::asio::deadline_timer::traits_type::now()) { closeConnection(); m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin); m_requestResponseTimer.expires_at(boost::posix_time::pos_infin); startResolve(); } m_resetConnectionTimer.async_wait(boost::bind(&Client::resetConnection, this)); } //============================================================================== // Client::createAuthorisationRequest() //============================================================================== Loading
src/Client.h +46 −23 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ public: typedef boost::shared_ptr<Client> SP; //------------------------------------------------------------------------------ // [Public] Request Response shared pointer typedef // [Public] Request Response classes shared pointer typedef //------------------------------------------------------------------------------ typedef boost::shared_ptr<Request> RequestSP; typedef boost::shared_ptr<Response> ResponseSP; Loading @@ -44,14 +44,14 @@ protected: public: //------------------------------------------------------------------------------ // [Public] Users abstract methods // [Public] Thread management methods //------------------------------------------------------------------------------ virtual void start() = 0; virtual void stop() = 0; //------------------------------------------------------------------------------ // [Public] Users methods // [Public] State status methods //------------------------------------------------------------------------------ virtual Tango::DevState readState(); Loading @@ -59,50 +59,73 @@ public: protected: //------------------------------------------------------------------------------ // [Protected] Utilities methods // [Protected] IO service run thread method //------------------------------------------------------------------------------ virtual void run(); //------------------------------------------------------------------------------ // [Protected] Endpoint resolution methods //------------------------------------------------------------------------------ virtual void startResolve(); virtual void handleResolve(const boost::system::error_code&, boost::asio::ip::tcp::resolver::iterator); virtual RequestSP createAuthorisationRequest(); virtual void processAuthorisationResponse(ResponseSP); virtual RequestSP createMetadataRequest(); virtual void processMetadataResponse(ResponseSP); virtual void encodeHeader(std::vector<boost::uint8_t>&, boost::uint32_t) throw(std::runtime_error); virtual boost::uint32_t decodeHeader(std::vector<boost::uint8_t>&) throw(std::runtime_error); //------------------------------------------------------------------------------ // [Protected] Utilities abstract methods // [Protected] Connection initialization methods //------------------------------------------------------------------------------ virtual void startConnect(boost::asio::ip::tcp::resolver::iterator) = 0; virtual void handleConnect(const boost::system::error_code&, boost::asio::ip::tcp::resolver::iterator) = 0; //------------------------------------------------------------------------------ // [Protected] Write request methods //------------------------------------------------------------------------------ virtual void startWriteRequest() = 0; virtual void handleWriteRequest(const boost::system::error_code&) = 0; virtual void handleWriteRequest(const boost::system::error_code&); //------------------------------------------------------------------------------ // [Protected] Read response header methods //------------------------------------------------------------------------------ virtual void startReadResponseHeader() = 0; virtual void handleReadResponseHeader(const boost::system::error_code&) = 0; virtual void handleReadResponseHeader(const boost::system::error_code&); //------------------------------------------------------------------------------ // [Protected] Read response body methods //------------------------------------------------------------------------------ virtual void startReadResponseBody(boost::uint32_t) = 0; virtual void handleReadResponseBody(const boost::system::error_code&) = 0; virtual void handleReadResponseBody(const boost::system::error_code&); virtual void resetConnection() = 0; //------------------------------------------------------------------------------ // [Protected] Connection reset and timeout handler methods //------------------------------------------------------------------------------ virtual void closeConnection() = 0; virtual void resetConnection(); //------------------------------------------------------------------------------ // [Protected] Request response methods //------------------------------------------------------------------------------ virtual RequestSP createAuthorisationRequest(); virtual void processAuthorisationResponse(ResponseSP); virtual RequestSP createMetadataRequest(); virtual void processMetadataResponse(ResponseSP); //------------------------------------------------------------------------------ // [Protected] Header encoding decoding methods //------------------------------------------------------------------------------ virtual void encodeHeader(std::vector<boost::uint8_t>&, boost::uint32_t) throw(std::runtime_error); virtual boost::uint32_t decodeHeader(std::vector<boost::uint8_t>&) throw(std::runtime_error); //------------------------------------------------------------------------------ // [Protected] Class variables Loading
src/PlainClient.cpp +8 −89 Original line number Diff line number Diff line Loading @@ -22,10 +22,7 @@ PlainClient::~PlainClient() { DEBUG_STREAM << "PlainClient::~PlainClient()" << endl; boost::system::error_code errorCode; m_plainSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_plainSocket.close(errorCode); closeConnection(); } //============================================================================== Loading Loading @@ -59,10 +56,7 @@ void PlainClient::stop() { DEBUG_STREAM << "PlainClient::stop()" << endl; boost::system::error_code errorCode; m_plainSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_plainSocket.close(errorCode); closeConnection(); Client::stop(); } Loading Loading @@ -141,23 +135,6 @@ void PlainClient::startWriteRequest() boost::asio::placeholders::error)); } //============================================================================== // PlainClient::handleRequest() //============================================================================== void PlainClient::handleWriteRequest(const boost::system::error_code& errorCode) { DEBUG_STREAM << "PlainClient::handleRequest()" << endl; if(!errorCode) { startReadResponseHeader(); } else { ERROR_STREAM << "PlainClient::handleRequest() " << errorCode.message() << endl; } } //============================================================================== // PlainClient::startReadResponseHeader() //============================================================================== Loading @@ -175,27 +152,6 @@ void PlainClient::startReadResponseHeader() boost::asio::placeholders::error)); } //============================================================================== // PlainClient::handleReadResponseHeader() //============================================================================== void PlainClient::handleReadResponseHeader(const boost::system::error_code& errorCode) { DEBUG_STREAM << "PlainClient::handleReadResponseHeader()" << endl; if(!errorCode) { boost::uint32_t bodySize = decodeHeader(m_readBuff); DEBUG_STREAM << "PlainClient::handleReadResponseHeader() SIZE: " << bodySize << endl; startReadResponseBody(bodySize); } else { ERROR_STREAM << "PlainClient::handleReadResponseHeader() " << errorCode.message() << endl; } } //============================================================================== // PlainClient::startReadResponseBody() //============================================================================== Loading @@ -214,53 +170,16 @@ void PlainClient::startReadResponseBody(boost::uint32_t bodySize) } //============================================================================== // PlainClient::handleReadResponseBody() //============================================================================== void PlainClient::handleReadResponseBody(const boost::system::error_code& errorCode) { DEBUG_STREAM << "PlainClient::handleReadResponseBody()" << endl; if(!errorCode) { ResponseSP response_sp(new Response); response_sp->ParseFromArray(&m_readBuff[HEADER_SIZE], m_readBuff.size() - HEADER_SIZE); processAuthorisationResponse(response_sp); m_requestResponseTimer.expires_from_now(boost::posix_time::seconds(10)); m_requestResponseTimer.async_wait(boost::bind(&PlainClient::startWriteRequest, this)); } else { ERROR_STREAM << "PlainClient::handleResponse() " << errorCode.message() << endl; } } //============================================================================== // PlainClient::resetConnection() // PlainClient::closeConnection() //============================================================================== void PlainClient::resetConnection() void PlainClient::closeConnection() { DEBUG_STREAM << "PlainClient::resetConnection()" << endl; if(m_resetConnectionTimer.expires_at() <= boost::asio::deadline_timer::traits_type::now()) { INFO_STREAM << "PlainClient::resetConnection() closing socket" << endl; DEBUG_STREAM << "PlainClient::closeConnection()" << endl; boost::system::error_code errorCode; m_plainSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_plainSocket.close(errorCode); m_resetConnectionTimer.expires_at(boost::posix_time::pos_infin); m_requestResponseTimer.expires_at(boost::posix_time::pos_infin); startResolve(); } m_resetConnectionTimer.async_wait(boost::bind(&PlainClient::resetConnection, this)); } } //namespace
src/PlainClient.h +1 −7 Original line number Diff line number Diff line Loading @@ -45,17 +45,11 @@ protected: virtual void startWriteRequest(); virtual void handleWriteRequest(const boost::system::error_code&); virtual void startReadResponseHeader(); virtual void handleReadResponseHeader(const boost::system::error_code&); virtual void startReadResponseBody(boost::uint32_t); virtual void handleReadResponseBody(const boost::system::error_code&); virtual void resetConnection(); virtual void closeConnection(); //------------------------------------------------------------------------------ // [Protected] Class variables Loading
src/SSLClient.cpp +50 −40 Original line number Diff line number Diff line Loading @@ -39,13 +39,7 @@ SSLClient::~SSLClient() { DEBUG_STREAM << "SSLClient::~SSLClient()" << endl; boost::system::error_code errorCode; m_sSLSocket.shutdown(errorCode); m_sSLSocket.lowest_layer().shutdown( boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_sSLSocket.lowest_layer().close(errorCode); closeConnection(); } //============================================================================== Loading Loading @@ -80,13 +74,7 @@ void SSLClient::stop() { DEBUG_STREAM << "SSLClient::stop()" << endl; boost::system::error_code errorCode; m_sSLSocket.shutdown(errorCode); m_sSLSocket.lowest_layer().shutdown( boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_sSLSocket.lowest_layer().close(errorCode); closeConnection(); Client::stop(); } Loading Loading @@ -194,14 +182,25 @@ void SSLClient::handleHandShake(const boost::system::error_code& errorCode) void SSLClient::startWriteRequest() { DEBUG_STREAM << "SSLClient::startWriteRequest()" << endl; } //============================================================================== // SSLClient::handleWriteRequest() //============================================================================== void SSLClient::handleWriteRequest(const boost::system::error_code&) { DEBUG_STREAM << "SSLClient::handleWriteRequest()" << endl; RequestSP request_sp = createAuthorisationRequest(); boost::uint32_t bodySize = request_sp->ByteSize(); DEBUG_STREAM << "PlainClient::startRequest() SIZE " << bodySize << endl; std::vector<boost::uint8_t> writeBuff; writeBuff.resize(HEADER_SIZE + bodySize); encodeHeader(writeBuff, bodySize); request_sp->SerializeToArray(&writeBuff[HEADER_SIZE], bodySize); m_resetConnectionTimer.expires_from_now(boost::posix_time::seconds(30)); boost::asio::async_write(m_sSLSocket, boost::asio::buffer(writeBuff), boost::bind(&SSLClient::handleWriteRequest, this, boost::asio::placeholders::error)); } //============================================================================== Loading @@ -210,38 +209,49 @@ void SSLClient::handleWriteRequest(const boost::system::error_code&) void SSLClient::startReadResponseHeader() { DEBUG_STREAM << "SSLClient::startReadResponseHeader()" << endl; } //============================================================================== // SSLClient::handleReadResponseHeader() //============================================================================== void SSLClient::handleReadResponseHeader(const boost::system::error_code&) { DEBUG_STREAM << "SSLClient::handleReadResponseHeader()" << endl; m_readBuff.resize(HEADER_SIZE); m_resetConnectionTimer.expires_from_now(boost::posix_time::seconds(30)); boost::asio::async_read(m_sSLSocket, boost::asio::buffer(m_readBuff), boost::bind( &SSLClient::handleReadResponseHeader, this, boost::asio::placeholders::error)); } //============================================================================== // SSLClient::startReadResponseBody() //============================================================================== void SSLClient::startReadResponseBody(boost::uint32_t) void SSLClient::startReadResponseBody(boost::uint32_t bodySize) { DEBUG_STREAM << "SSLClient::startReadResponseBody()" << endl; } //============================================================================== // SSLClient::handleReadResponseBody() //============================================================================== void SSLClient::handleReadResponseBody(const boost::system::error_code&) { DEBUG_STREAM << "SSLClient::handleReadResponseBody()" << endl; m_readBuff.resize(HEADER_SIZE + bodySize); boost::asio::mutable_buffers_1 mutableBuffer = boost::asio::buffer(&m_readBuff[HEADER_SIZE], bodySize); boost::asio::async_read(m_sSLSocket, mutableBuffer, boost::bind(&SSLClient::handleReadResponseBody, this, boost::asio::placeholders::error)); } //============================================================================== // SSLClient::resetConnection() // SSLClient::closeConnection() //============================================================================== void SSLClient::resetConnection() void SSLClient::closeConnection() { DEBUG_STREAM << "SSLClient::resetConnection()" << endl; DEBUG_STREAM << "SSLClient::closeConnection()" << endl; boost::system::error_code errorCode; m_sSLSocket.shutdown(errorCode); m_sSLSocket.lowest_layer().shutdown( boost::asio::ip::tcp::socket::shutdown_both, errorCode); m_sSLSocket.lowest_layer().close(errorCode); } } //namespace