http_connection.hpp
Go to the documentation of this file.
1 #ifndef CPP_WEB_SERVER_HTTP_CONNECTION_HPP
2 #define CPP_WEB_SERVER_HTTP_CONNECTION_HPP
3 
7 
8 #include <boost/asio.hpp>
9 #include <boost/enable_shared_from_this.hpp>
10 #include <boost/noncopyable.hpp>
11 #include <boost/shared_ptr.hpp>
12 #include <boost/thread/mutex.hpp>
13 
15 {
16 
18 typedef boost::shared_ptr<HttpConnection> HttpConnectionPtr;
19 typedef boost::weak_ptr<HttpConnection> HttpConnectionWeakPtr;
20 
34 class HttpConnection : public boost::enable_shared_from_this<HttpConnection>,
35  private boost::noncopyable
36 {
37 public:
38  typedef boost::function<void(const char* begin, const char* end)>
40  typedef boost::shared_ptr<const void> ResourcePtr;
41 
42  explicit HttpConnection(boost::asio::io_service& io_service,
43  HttpServerRequestHandler request_handler);
44 
45  boost::asio::ip::tcp::socket& socket();
46 
50  void start();
51 
55  void async_read(ReadHandler callback);
56 
60  void write_and_clear(std::vector<unsigned char>& data);
61 
62  void write(const std::string&);
63 
64  void write(const boost::asio::const_buffer& buffer, ResourcePtr resource);
65 
66  void write(const std::vector<boost::asio::const_buffer>& buffer,
67  ResourcePtr resource);
68 
69 private:
70  void handle_read(const char* begin, const char* end);
71  void handle_read_raw(ReadHandler callback,
72  const boost::system::error_code& e,
73  std::size_t bytes_transferred);
74 
75  // Must be called while holding write lock
76  void write_pending();
77 
78  void handle_write(const boost::system::error_code& e,
79  std::vector<ResourcePtr> resources);
80 
81  boost::asio::io_service::strand strand_;
82  boost::asio::ip::tcp::socket socket_;
84  boost::array<char, 8192> buffer_;
87 
88  boost::mutex write_mutex_;
90  std::vector<boost::asio::const_buffer> pending_write_buffers_;
91  std::vector<ResourcePtr> pending_write_resources_;
92  boost::system::error_code last_error_;
94 };
95 
96 } // namespace async_web_server_cpp
97 
98 #endif
void handle_read_raw(ReadHandler callback, const boost::system::error_code &e, std::size_t bytes_transferred)
boost::array< char, 8192 > buffer_
boost::asio::ip::tcp::socket socket_
HttpServerRequestHandler request_handler_
HttpConnection(boost::asio::io_service &io_service, HttpServerRequestHandler request_handler)
void async_read(ReadHandler callback)
std::vector< boost::asio::const_buffer > pending_write_buffers_
boost::shared_ptr< HttpConnection > HttpConnectionPtr
boost::system::error_code last_error_
boost::function< void(const char *begin, const char *end)> ReadHandler
boost::asio::io_service::strand strand_
void handle_write(const boost::system::error_code &e, std::vector< ResourcePtr > resources)
std::vector< ResourcePtr > pending_write_resources_
void write_and_clear(std::vector< unsigned char > &data)
boost::function< bool(const HttpRequest &, boost::shared_ptr< HttpConnection >, const char *begin, const char *end)> HttpServerRequestHandler
boost::weak_ptr< HttpConnection > HttpConnectionWeakPtr
void handle_read(const char *begin, const char *end)
boost::asio::ip::tcp::socket & socket()
boost::shared_ptr< const void > ResourcePtr


async_web_server_cpp
Author(s): Mitchell Wills , Russel Toris
autogenerated on Mon Feb 28 2022 21:54:08