JayBeams  0.1
Another project to have fun coding.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
jb::ehs::connection Class Reference

Handle one connection to the control server. More...

#include <connection.hpp>

Inheritance diagram for jb::ehs::connection:

Public Types

using socket_type = boost::asio::ip::tcp::socket
 The type of socket used for the connection. More...
 

Public Member Functions

 connection (socket_type &&sock, std::shared_ptr< request_dispatcher > dispatcher)
 Create a new connection. More...
 
 ~connection ()
 Destructor. More...
 
void run ()
 Asynchronously read a HTTP request for this connection. More...
 
 connection (connection &&)=default
 Control copy and assignment. More...
 
 connection (connection const &)=default
 
connectionoperator= (connection &&)=delete
 
connectionoperator= (connection const &)=delete
 

Private Member Functions

void on_read (boost::system::error_code const &ec)
 Handle a completed HTTP request read. More...
 
void on_write (boost::system::error_code const &ec)
 Handle a completed response write. More...
 

Private Attributes

socket_type sock_
 
std::shared_ptr< request_dispatcherdispatcher_
 
boost::asio::io_service::strand strand_
 
int id_
 
beast::flat_buffer sb_
 
request_type req_
 

Static Private Attributes

static std::atomic< int > idgen
 

Detailed Description

Handle one connection to the control server.

Definition at line 17 of file connection.hpp.

Member Typedef Documentation

◆ socket_type

using jb::ehs::connection::socket_type = boost::asio::ip::tcp::socket

The type of socket used for the connection.

Definition at line 20 of file connection.hpp.

Constructor & Destructor Documentation

◆ connection() [1/3]

jb::ehs::connection::connection ( socket_type &&  sock,
std::shared_ptr< request_dispatcher dispatcher 
)

Create a new connection.

Parameters
sockthe underlying socket for this connection.
dispatcherthe handler for the connections.

Definition at line 8 of file connection.cpp.

References dispatcher_, id_, jb::info, JB_LOG, and sock_.

◆ ~connection()

jb::ehs::connection::~connection ( )

Destructor.

Definition at line 19 of file connection.cpp.

References dispatcher_, id_, jb::info, and JB_LOG.

◆ connection() [2/3]

jb::ehs::connection::connection ( connection &&  )
default

Control copy and assignment.

◆ connection() [3/3]

jb::ehs::connection::connection ( connection const &  )
default

Member Function Documentation

◆ on_read()

void jb::ehs::connection::on_read ( boost::system::error_code const &  ec)
private

Handle a completed HTTP request read.

Once a HTTP request has been received it needs to be parsed and a response sent back. This function is called by the Beast framework when the read completes.

Parameters
ecthe error code

Definition at line 31 of file connection.cpp.

References dispatcher_, id_, jb::info, JB_LOG, req_, sock_, and strand_.

◆ on_write()

void jb::ehs::connection::on_write ( boost::system::error_code const &  ec)
private

Handle a completed response write.

Parameters
ecindicate if writing the response resulted in an error.

Definition at line 51 of file connection.cpp.

References dispatcher_, id_, idgen, jb::info, JB_LOG, and run().

◆ operator=() [1/2]

connection& jb::ehs::connection::operator= ( connection &&  )
delete

◆ operator=() [2/2]

connection& jb::ehs::connection::operator= ( connection const &  )
delete

◆ run()

void jb::ehs::connection::run ( )

Asynchronously read a HTTP request for this connection.

Definition at line 24 of file connection.cpp.

References req_, sb_, sock_, and strand_.

Referenced by on_write().

Member Data Documentation

◆ dispatcher_

std::shared_ptr<request_dispatcher> jb::ehs::connection::dispatcher_
private

Definition at line 68 of file connection.hpp.

Referenced by connection(), on_read(), on_write(), and ~connection().

◆ id_

int jb::ehs::connection::id_
private

Definition at line 70 of file connection.hpp.

Referenced by connection(), on_read(), on_write(), and ~connection().

◆ idgen

std::atomic< int > jb::ehs::connection::idgen
staticprivate

Definition at line 74 of file connection.hpp.

Referenced by on_write().

◆ req_

request_type jb::ehs::connection::req_
private

Definition at line 72 of file connection.hpp.

Referenced by on_read(), and run().

◆ sb_

beast::flat_buffer jb::ehs::connection::sb_
private

Definition at line 71 of file connection.hpp.

Referenced by run().

◆ sock_

socket_type jb::ehs::connection::sock_
private

Definition at line 67 of file connection.hpp.

Referenced by connection(), on_read(), and run().

◆ strand_

boost::asio::io_service::strand jb::ehs::connection::strand_
private

Definition at line 69 of file connection.hpp.

Referenced by on_read(), and run().


The documentation for this class was generated from the following files: