14#include <boost/enable_shared_from_this.hpp> 
   67    void doSend(
const void* buffer, 
const size_t length,
 
   86    void terminate(
const boost::system::error_code& ec,
 
  106    std::string current_command_;
 
  109    std::array<char, 32768> read_buf_;
 
 
  119    : socket_(io_service), feed_(), current_command_(), timer_(io_service),
 
 
  147    auto self(shared_from_this());
 
  150    [
this, self, command, handler](
const boost::system::error_code& ec) {
 
  155            terminate(ec, handler);
 
  160            doSend(current_command_.c_str(), current_command_.length(),
 
 
  171    auto self(shared_from_this());
 
  174    socket_.asyncSend(buffer, length,
 
  175        [
this, self, buffer, length, handler]
 
  176        (
const boost::system::error_code& ec, 
size_t bytes_transferred) {
 
  191            if (bytes_transferred < length) {
 
  192                doSend(
static_cast<const char*
>(buffer) + bytes_transferred,
 
  193                       length - bytes_transferred, handler);
 
 
  207    auto self(shared_from_this());
 
  208    socket_.asyncReceive(&read_buf_[0], read_buf_.size(),
 
  209        [
this, self, handler]
 
  210        (
const boost::system::error_code& ec, 
size_t length) {
 
  215            terminate(ec, handler);
 
  219            scheduleTimer(handler);
 
  221            std::string x(&read_buf_[0], length);
 
  226                feed_.reset(new JSONFeed());
 
  231            feed_->postBuffer(&read_buf_[0], length);
 
  235            if (feed_->needData()) {
 
  241                terminate(ec, handler);
 
 
  253        current_command_.clear();
 
 
  268    terminate(boost::asio::error::timed_out, handler);
 
 
  280    impl_->start(socket_path, command, handler, timeout);
 
 
The IntervalTimer class is a wrapper for the ASIO boost::asio::deadline_timer class.
Represents unix domain socket implemented in terms of boost asio.
Implementation of the ClientConnection.
void start(const ClientConnection::SocketPath &socket_path, const ClientConnection::ControlCommand &command, ClientConnection::Handler handler, const ClientConnection::Timeout &timeout)
Starts asynchronous transaction with a remote endpoint.
void timeoutCallback(ClientConnection::Handler handler)
Callback invoked when the timeout occurs.
void scheduleTimer(ClientConnection::Handler handler)
This method schedules timer or reschedules existing timer.
ClientConnectionImpl(const IOServicePtr &io_service)
Constructor.
void doSend(const void *buffer, const size_t length, ClientConnection::Handler handler)
Starts asynchronous send.
void stop()
Closes the socket.
void terminate(const boost::system::error_code &ec, ClientConnection::Handler handler)
Terminates the connection and invokes a user callback indicating an error.
void doReceive(ClientConnection::Handler handler)
Starts asynchronous receive from the server.
std::function< void(const boost::system::error_code &ec, const ConstJSONFeedPtr &feed)> Handler
Type of the callback invoked when the communication with the server is complete or an error has occur...
ClientConnection(const asiolink::IOServicePtr &io_service)
Constructor.
void start(const SocketPath &socket_path, const ControlCommand &command, Handler handler, const Timeout &timeout=Timeout(5000))
Starts asynchronous transaction with a remote endpoint.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< JSONFeed > JSONFeedPtr
Pointer to the JSONFeed.
Defines the logger used by the top-level component of kea-lfc.
Encapsulates control command.
std::string control_command_
Encapsulates socket path.
Encapsulates timeout value.