MACE  1.0.0
 All Classes Namespaces Files Functions Variables Enumerations Defines
libs/rpc/include/mace/rpc/http/server.hpp
00001 //
00002 // server.hpp
00003 // ~~~~~~~~~~
00004 //
00005 // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
00006 //
00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 
00011 #ifndef MACE_RPC_HTTP_SERVER_HPP
00012 #define MACE_RPC_HTTP_SERVER_HPP
00013 
00014 #include <boost/asio.hpp>
00015 #include <string>
00016 #include <boost/array.hpp>
00017 #include <boost/function.hpp>
00018 #include <boost/shared_ptr.hpp>
00019 #include <mace/rpc/http/coroutine.hpp>
00020 #include <mace/rpc/http/request_parser.hpp>
00021 
00022 namespace mace { namespace rpc { namespace http {
00023 
00024   struct request;
00025   struct reply;
00026 
00028   class server : coroutine {
00029     public:
00032       explicit server( const std::string& address, const std::string& port,
00033           boost::function<void(const request&, reply&)> request_handler);
00034 
00036       void operator()(
00037           boost::system::error_code ec = boost::system::error_code(),
00038           std::size_t length = 0);
00039 
00040     private:
00041       typedef boost::asio::ip::tcp tcp;
00042 
00044       boost::function<void(const request&, reply&)> request_handler_;
00045 
00047       boost::shared_ptr<tcp::acceptor> acceptor_;
00048 
00050       boost::shared_ptr<tcp::socket> socket_;
00051 
00053       boost::shared_ptr<boost::array<char, 8192> > buffer_;
00054 
00056       boost::shared_ptr<request> request_;
00057 
00059       boost::tribool valid_request_;
00060 
00062       request_parser request_parser_;
00063 
00065       boost::shared_ptr<reply> reply_;
00066 
00068       boost::shared_ptr<boost::asio::strand>  strand_;
00069   };
00070 
00071 } } }// mace::rpc::http
00072 
00073 #endif // HTTP_SERVER4_SERVER_HPP