AirInv Logo  1.00.0
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Connection.hpp
Go to the documentation of this file.
1 #ifndef __AIRINV_SVR_CONNECTION_HPP
2 #define __AIRINV_SVR_CONNECTION_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 // Boost
9 #include <boost/asio.hpp>
10 #include <boost/array.hpp>
11 #include <boost/noncopyable.hpp>
12 #include <boost/shared_ptr.hpp>
13 #include <boost/enable_shared_from_this.hpp>
14 // AirInv
15 #include <airinv/server/Reply.hpp>
17 
18 namespace AIRINV {
19 
20  // Forward declarations.
21  class RequestHandler;
22 
23 
25  class Connection : public boost::enable_shared_from_this<Connection>,
26  private boost::noncopyable {
27  public:
28  // //////////// Constructors and Destructors /////////////////
31  Connection (boost::asio::io_service&, RequestHandler&);
32 
33 
34  // /////////// Business Support Methods ////////////////
36  boost::asio::ip::tcp::socket& socket();
37 
39  void start();
40 
41 
42  private:
44  void handleRead (const boost::system::error_code& e,
45  std::size_t bytes_transferred);
46 
48  void handleWrite (const boost::system::error_code& e);
49 
52  boost::asio::io_service::strand _strand;
53 
55  boost::asio::ip::tcp::socket _socket;
56 
58  RequestHandler& _requestHandler;
59 
61  boost::array<char, 8192> _buffer;
62 
64  Request _request;
65 
67  Reply _reply;
68  };
69 
71  typedef boost::shared_ptr<Connection> ConnectionShrPtr_T;
72 
73 }
74 #endif // __AIRINV_SVR_CONNECTION_HPP