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
http_request_handler.hpp
async_web_server_cpp::HttpRequestParser
Definition: http_request_parser.hpp:22
async_web_server_cpp::HttpConnection::write_in_progress_
bool write_in_progress_
Definition: http_connection.hpp:89
async_web_server_cpp::HttpConnection::request_
HttpRequest request_
Definition: http_connection.hpp:85
async_web_server_cpp::HttpServerRequestHandler
boost::function< bool(const HttpRequest &, boost::shared_ptr< HttpConnection >, const char *begin, const char *end)> HttpServerRequestHandler
Definition: http_request_handler.hpp:12
async_web_server_cpp::HttpConnection::pending_write_resources_
std::vector< ResourcePtr > pending_write_resources_
Definition: http_connection.hpp:91
async_web_server_cpp::HttpConnection::strand_
boost::asio::io_service::strand strand_
Definition: http_connection.hpp:81
async_web_server_cpp::HttpConnection::handle_write
void handle_write(const boost::system::error_code &e, std::vector< ResourcePtr > resources)
Definition: http_connection.cpp:140
async_web_server_cpp::HttpConnection::buffer_
boost::array< char, 8192 > buffer_
Definition: http_connection.hpp:84
async_web_server_cpp::HttpConnection::ReadHandler
boost::function< void(const char *begin, const char *end)> ReadHandler
Definition: http_connection.hpp:39
async_web_server_cpp::HttpConnection::request_handler_
HttpServerRequestHandler request_handler_
Definition: http_connection.hpp:83
async_web_server_cpp::HttpConnection
Definition: http_connection.hpp:34
async_web_server_cpp::HttpConnection::write_and_clear
void write_and_clear(std::vector< unsigned char > &data)
Definition: http_connection.cpp:86
async_web_server_cpp::HttpConnection::read_handler_
ReadHandler read_handler_
Definition: http_connection.hpp:93
async_web_server_cpp::HttpConnection::handle_read_raw
void handle_read_raw(ReadHandler callback, const boost::system::error_code &e, std::size_t bytes_transferred)
Definition: http_connection.cpp:59
async_web_server_cpp
Definition: http_connection.hpp:14
http_request_parser.hpp
async_web_server_cpp::HttpConnection::handle_read
void handle_read(const char *begin, const char *end)
Definition: http_connection.cpp:27
async_web_server_cpp::HttpConnection::ResourcePtr
boost::shared_ptr< const void > ResourcePtr
Definition: http_connection.hpp:40
async_web_server_cpp::HttpConnection::socket_
boost::asio::ip::tcp::socket socket_
Definition: http_connection.hpp:82
async_web_server_cpp::HttpConnection::async_read
void async_read(ReadHandler callback)
Definition: http_connection.cpp:72
async_web_server_cpp::HttpConnection::write_mutex_
boost::mutex write_mutex_
Definition: http_connection.hpp:88
async_web_server_cpp::HttpRequest
Definition: http_request.hpp:18
async_web_server_cpp::HttpConnection::request_parser_
HttpRequestParser request_parser_
Definition: http_connection.hpp:86
async_web_server_cpp::HttpConnection::write_pending
void write_pending()
Definition: http_connection.cpp:124
async_web_server_cpp::HttpConnection::start
void start()
Definition: http_connection.cpp:21
async_web_server_cpp::HttpConnection::HttpConnection
HttpConnection(boost::asio::io_service &io_service, HttpServerRequestHandler request_handler)
Definition: http_connection.cpp:9
async_web_server_cpp::HttpConnectionPtr
boost::shared_ptr< HttpConnection > HttpConnectionPtr
Definition: http_connection.hpp:17
async_web_server_cpp::HttpConnection::write
void write(const std::string &)
Definition: http_connection.cpp:94
async_web_server_cpp::HttpConnection::pending_write_buffers_
std::vector< boost::asio::const_buffer > pending_write_buffers_
Definition: http_connection.hpp:90
async_web_server_cpp::HttpConnection::last_error_
boost::system::error_code last_error_
Definition: http_connection.hpp:92
async_web_server_cpp::HttpConnection::socket
boost::asio::ip::tcp::socket & socket()
Definition: http_connection.cpp:16
http_request.hpp
async_web_server_cpp::HttpConnectionWeakPtr
boost::weak_ptr< HttpConnection > HttpConnectionWeakPtr
Definition: http_connection.hpp:19


async_web_server_cpp
Author(s): Mitchell Wills , Russel Toris
autogenerated on Tue Mar 1 2022 23:49:06