libnghttp2_asio: Move common types and functions to nghttp2::asio_http2 ns

This commit is contained in:
Tatsuhiro Tsujikawa 2014-09-28 16:54:00 +09:00
parent 88d7abcc23
commit 4f0d03b4b9
4 changed files with 47 additions and 46 deletions

View File

@ -33,6 +33,34 @@ namespace nghttp2 {
namespace asio_http2 { namespace asio_http2 {
channel::channel()
: impl_(util::make_unique<channel_impl>())
{}
void channel::post(void_cb cb)
{
impl_->post(std::move(cb));
}
channel_impl& channel::impl()
{
return *impl_;
}
channel_impl::channel_impl()
: strand_(nullptr)
{}
void channel_impl::post(void_cb cb)
{
strand_->post(std::move(cb));
}
void channel_impl::strand(boost::asio::io_service::strand *strand)
{
strand_ = strand;
}
namespace server { namespace server {
extern std::shared_ptr<std::string> cached_date; extern std::shared_ptr<std::string> cached_date;
@ -402,34 +430,6 @@ std::pair<ssize_t, bool> response_impl::call_read
return std::make_pair(0, true); return std::make_pair(0, true);
} }
channel::channel()
: impl_(util::make_unique<channel_impl>())
{}
void channel::post(void_cb cb)
{
impl_->post(std::move(cb));
}
channel_impl& channel::impl()
{
return *impl_;
}
channel_impl::channel_impl()
: strand_(nullptr)
{}
void channel_impl::post(void_cb cb)
{
strand_->post(std::move(cb));
}
void channel_impl::strand(boost::asio::io_service::strand *strand)
{
strand_ = strand;
}
http2_stream::http2_stream(int32_t stream_id) http2_stream::http2_stream(int32_t stream_id)
: request_(std::make_shared<request>()), : request_(std::make_shared<request>()),
response_(std::make_shared<response>()), response_(std::make_shared<response>()),

View File

@ -40,6 +40,16 @@
namespace nghttp2 { namespace nghttp2 {
namespace asio_http2 { namespace asio_http2 {
class channel_impl {
public:
channel_impl();
void post(void_cb cb);
void strand(boost::asio::io_service::strand *strand);
private:
boost::asio::io_service::strand *strand_;
};
namespace server { namespace server {
class http2_handler; class http2_handler;
@ -117,15 +127,6 @@ private:
bool started_; bool started_;
}; };
class channel_impl {
public:
channel_impl();
void post(void_cb cb);
void strand(boost::asio::io_service::strand *strand);
private:
boost::asio::io_service::strand *strand_;
};
class http2_stream { class http2_stream {
public: public:
http2_stream(int32_t stream_id); http2_stream(int32_t stream_id);

View File

@ -153,6 +153,8 @@ void http2_impl::num_concurrent_tasks(size_t num_concurrent_tasks)
num_concurrent_tasks_ = num_concurrent_tasks; num_concurrent_tasks_ = num_concurrent_tasks;
} }
} // namespace server
template<typename T, typename F> template<typename T, typename F>
std::shared_ptr<util::Defer<T, F>> defer_shared(T&& t, F f) std::shared_ptr<util::Defer<T, F>> defer_shared(T&& t, F f)
{ {
@ -206,8 +208,6 @@ std::string http_date(time_t t)
return util::http_date(t); return util::http_date(t);
} }
} // namespace server
} // namespace asio_http2 } // namespace asio_http2
} // namespace nghttp2 } // namespace nghttp2

View File

@ -40,11 +40,6 @@ struct header {
std::string value; std::string value;
}; };
namespace server {
class request_impl;
class response_impl;
typedef std::function<void(const uint8_t*, std::size_t)> data_cb; typedef std::function<void(const uint8_t*, std::size_t)> data_cb;
typedef std::function<void(void)> void_cb; typedef std::function<void(void)> void_cb;
@ -83,6 +78,11 @@ private:
typedef std::function<void(channel&)> thread_cb; typedef std::function<void(channel&)> thread_cb;
namespace server {
class request_impl;
class response_impl;
class request { class request {
public: public:
// Application must not call this directly. // Application must not call this directly.
@ -212,6 +212,8 @@ private:
std::unique_ptr<http2_impl> impl_; std::unique_ptr<http2_impl> impl_;
}; };
} // namespace server
// Convenient function to create function to read file denoted by // Convenient function to create function to read file denoted by
// |path|. This can be passed to response::end(). // |path|. This can be passed to response::end().
read_cb file_reader(const std::string& path); read_cb file_reader(const std::string& path);
@ -233,8 +235,6 @@ std::string percent_decode(const std::string& s);
// Returns HTTP date representation of current posix time |t|. // Returns HTTP date representation of current posix time |t|.
std::string http_date(time_t t); std::string http_date(time_t t);
} // namespace server
} // namespace asio_http2 } // namespace asio_http2
} // namespace nghttp2 } // namespace nghttp2