Program Listing for File http_server.hpp

Return to documentation for file (/tmp/ws/src/async_web_server_cpp/include/async_web_server_cpp/http_server.hpp)

#ifndef CPP_WEB_SERVER_HTTP_SERVER_HPP
#define CPP_WEB_SERVER_HTTP_SERVER_HPP

#include "async_web_server_cpp/http_connection.hpp"
#include "async_web_server_cpp/http_request_handler.hpp"

#include <boost/asio.hpp>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread/thread.hpp>

#include <string>
#include <vector>

namespace async_web_server_cpp
{

class HttpServer : private boost::noncopyable
{
public:
    HttpServer(const std::string& address, const std::string& port,
               HttpServerRequestHandler request_handler,
               std::size_t thread_pool_size);
    ~HttpServer();

    void run();

    void stop();

private:
    void start_accept();

    void handle_accept(const boost::system::error_code& e);

    boost::asio::io_service io_service_;
    boost::asio::ip::tcp::acceptor acceptor_;
    std::size_t thread_pool_size_;
    std::vector<boost::shared_ptr<boost::thread>> threads_;
    boost::shared_ptr<HttpConnection> new_connection_;
    HttpServerRequestHandler request_handler_;
};

}  // namespace async_web_server_cpp

#endif