20 #include <boost/bind.hpp>
26 using namespace agentxcpp;
51 static void callback(
const boost::system::error_code& result,
54 if( result.value() == 0 )
92 template<
typename AsyncReadStream,
93 typename MutableBufferSequence>
94 static void read_with_timeout(AsyncReadStream& s,
95 const MutableBufferSequence& buffers,
120 boost::bind(callback,
121 boost::asio::placeholders::error,
130 s.get_io_service().run_one();
135 catch(boost::system::system_error)
159 switch(timer.get_status())
203 template<
typename ConstBufferSequence>
204 static void send_with_timeout(boost::asio::local::stream_protocol::socket& s,
205 const ConstBufferSequence& buffers,
230 s.async_send(buffers,
231 boost::bind(callback,
232 boost::asio::placeholders::error,
242 s.get_io_service().run_one();
247 catch(boost::system::system_error)
271 switch(timer.get_status())
305 const std::string& unix_domain_socket,
308 io_service(io_service),
310 endpoint(unix_domain_socket.c_str()),
325 using boost::asio::local::stream_protocol;
331 catch(boost::system::system_error)
345 boost::asio::placeholders::error));
364 boost::asio::local::stream_protocol::socket::shutdown_both);
366 catch(boost::system::system_error)
377 catch(boost::system::system_error)
399 if( result.value() != 0 )
404 if( result.value() == boost::asio::error::operation_aborted )
424 bool big_endian = ( this->
header_buf[2] & (1<<4) ) ?
true :
false;
427 uint32_t payload_length;
428 binary::const_iterator pos = buf.begin() + 16;
429 payload_length =
read32(pos, big_endian);
430 if( payload_length % 4 != 0 )
452 uint8_t* payload =
new uint8_t[payload_length];
455 read_with_timeout(*this->
socket,
456 boost::asio::buffer(payload, payload_length),
467 buf.append(payload, payload_length);
511 shared_ptr<ResponsePDU> response;
512 response = boost::dynamic_pointer_cast<
ResponsePDU>(pdu);
513 if(response.get() != 0)
516 std::map< uint32_t, boost::shared_ptr<ResponsePDU> >::iterator i;
517 i = this->
responses.find( response->get_packetID() );
521 i->second = response;
554 boost::asio::placeholders::error));
571 send_with_timeout(*this->
socket,
572 boost::asio::buffer(buf.data(), buf.size()),
593 boost::shared_ptr<ResponsePDU>
604 responses[packetID] = boost::shared_ptr<ResponsePDU>();
608 timer.expires_from_now( boost::posix_time::seconds(this->timeout) );
613 while( this->
responses[packetID].
get() == 0
619 catch(boost::system::system_error)
628 if( this->
responses[packetID].
get() != 0 )
635 shared_ptr<ResponsePDU> retval = this->
responses[packetID];
641 switch(timer.get_status())