JayBeams  0.1
Another project to have fun coding.
acceptor.hpp
Go to the documentation of this file.
1 #ifndef jb_ehs_acceptor_hpp
2 #define jb_ehs_acceptor_hpp
3 
4 #include <jb/ehs/connection.hpp>
5 
6 #include <boost/asio/ip/tcp.hpp>
7 
8 namespace jb {
9 namespace ehs {
10 
11 /**
12  * Create a control server for the program.
13  *
14  * The program runs as a typical daemon, accepting HTTP requests to
15  * start new replays, stop them, and show its current status.
16  */
17 class acceptor {
18 public:
19  /**
20  * Create an acceptor a Embedded HTTP Server and start accepting connections.
21  *
22  * @param io Boost.ASIO service used to demux I/O events for this
23  * acceptor.
24  * @param ep the endpoint this control server listens on.
25  * @param dispatcher the object to process requests.
26  */
27  acceptor(
28  boost::asio::io_service& io, boost::asio::ip::tcp::endpoint const& ep,
29  std::shared_ptr<request_dispatcher> dispatcher);
30 
31  /// Return the local listening endpoint.
32  boost::asio::ip::tcp::endpoint local_endpoint() const {
33  return acceptor_.local_endpoint();
34  }
35 
36  /// Gracefully shutdown the acceptor
37  void shutdown();
38 
39 private:
40  /**
41  * Handle a completed asynchronous accept() call.
42  */
43  void on_accept(boost::system::error_code const& ec);
44 
45 private:
46  boost::asio::ip::tcp::acceptor acceptor_;
47  std::shared_ptr<request_dispatcher> dispatcher_;
48  // Hold the results of an asynchronous accept() operation.
49  boost::asio::ip::tcp::socket sock_;
50 };
51 
52 } // namespace ehs
53 } // namespace jb
54 
55 #endif // jb_ehs_acceptor_hpp
void shutdown()
Gracefully shutdown the acceptor.
Definition: acceptor.cpp:26
std::shared_ptr< request_dispatcher > dispatcher_
Definition: acceptor.hpp:47
void on_accept(boost::system::error_code const &ec)
Handle a completed asynchronous accept() call.
Definition: acceptor.cpp:31
boost::asio::ip::tcp::socket sock_
Definition: acceptor.hpp:49
boost::asio::ip::tcp::endpoint local_endpoint() const
Return the local listening endpoint.
Definition: acceptor.hpp:32
Create a control server for the program.
Definition: acceptor.hpp:17
acceptor(boost::asio::io_service &io, boost::asio::ip::tcp::endpoint const &ep, std::shared_ptr< request_dispatcher > dispatcher)
Create an acceptor a Embedded HTTP Server and start accepting connections.
Definition: acceptor.cpp:8
boost::asio::ip::tcp::acceptor acceptor_
Definition: acceptor.hpp:46
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7