00001 #ifndef CPP_WEB_SERVER_HTTP_SERVER_HPP 00002 #define CPP_WEB_SERVER_HTTP_SERVER_HPP 00003 00004 #include <boost/asio.hpp> 00005 #include <string> 00006 #include <vector> 00007 #include <boost/noncopyable.hpp> 00008 #include <boost/function.hpp> 00009 #include <boost/shared_ptr.hpp> 00010 #include <boost/thread/thread.hpp> 00011 00012 #include "async_web_server_cpp/http_request_handler.hpp" 00013 #include "async_web_server_cpp/http_connection.hpp" 00014 00015 namespace async_web_server_cpp 00016 { 00017 00024 class HttpServer : private boost::noncopyable 00025 { 00026 public: 00027 HttpServer(const std::string &address, const std::string &port, 00028 HttpServerRequestHandler request_handler, std::size_t thread_pool_size); 00029 00030 void run(); 00031 00032 void stop(); 00033 00034 private: 00035 void start_accept(); 00036 00037 void handle_accept(const boost::system::error_code &e); 00038 00039 boost::asio::io_service io_service_; 00040 boost::asio::ip::tcp::acceptor acceptor_; 00041 std::size_t thread_pool_size_; 00042 std::vector<boost::shared_ptr<boost::thread> > threads_; 00043 boost::shared_ptr<HttpConnection> new_connection_; 00044 HttpServerRequestHandler request_handler_; 00045 }; 00046 00047 } 00048 00049 #endif