nghttp2/src/asio_client_session.cc

144 lines
5.1 KiB
C++
Raw Normal View History

2015-03-01 02:02:49 +01:00
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2015 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp2_config.h"
#include <nghttp2/asio_http2_client.h>
2015-03-01 02:02:49 +01:00
#include "asio_client_session_tcp_impl.h"
#include "asio_client_session_tls_impl.h"
#include "asio_common.h"
#include "template.h"
namespace nghttp2 {
namespace asio_http2 {
namespace client {
using boost::asio::ip::tcp;
2015-03-03 16:08:47 +01:00
session::session(boost::asio::io_service &io_service, const std::string &host,
const std::string &service)
: impl_(std::make_shared<session_tcp_impl>(
io_service, host, service, boost::posix_time::seconds(60))) {
impl_->start_resolve(host, service);
}
session::session(boost::asio::io_service &io_service, const std::string &host,
const std::string &service,
const boost::posix_time::time_duration &connect_timeout)
: impl_(std::make_shared<session_tcp_impl>(io_service, host, service,
connect_timeout)) {
impl_->start_resolve(host, service);
}
2015-03-01 02:02:49 +01:00
session::session(boost::asio::io_service &io_service,
2015-03-03 16:08:47 +01:00
boost::asio::ssl::context &tls_ctx, const std::string &host,
const std::string &service)
: impl_(std::make_shared<session_tls_impl>(
io_service, tls_ctx, host, service, boost::posix_time::seconds(60))) {
impl_->start_resolve(host, service);
}
session::session(boost::asio::io_service &io_service,
boost::asio::ssl::context &tls_ctx, const std::string &host,
const std::string &service,
const boost::posix_time::time_duration &connect_timeout)
: impl_(std::make_shared<session_tls_impl>(io_service, tls_ctx, host,
service, connect_timeout)) {
impl_->start_resolve(host, service);
2015-03-03 16:08:47 +01:00
}
2015-03-01 02:02:49 +01:00
session::~session() {}
session::session(session &&other) noexcept : impl_(std::move(other.impl_)) {}
session &session::operator=(session &&other) noexcept {
if (this == &other) {
return *this;
}
impl_ = std::move(other.impl_);
return *this;
}
void session::on_connect(connect_cb cb) const {
impl_->on_connect(std::move(cb));
}
2015-03-01 02:02:49 +01:00
void session::on_error(error_cb cb) const { impl_->on_error(std::move(cb)); }
2015-03-01 02:02:49 +01:00
void session::shutdown() const { impl_->shutdown(); }
2015-03-01 02:02:49 +01:00
boost::asio::io_service &session::io_service() const {
return impl_->io_service();
}
2015-03-03 16:08:47 +01:00
2015-03-03 16:20:09 +01:00
const request *session::submit(boost::system::error_code &ec,
const std::string &method,
const std::string &uri, header_map h,
priority_spec prio) const {
return impl_->submit(ec, method, uri, generator_cb(), std::move(h),
std::move(prio));
2015-03-01 02:02:49 +01:00
}
2015-03-03 16:20:09 +01:00
const request *session::submit(boost::system::error_code &ec,
const std::string &method,
const std::string &uri, std::string data,
header_map h, priority_spec prio) const {
return impl_->submit(ec, method, uri, string_generator(std::move(data)),
std::move(h), std::move(prio));
2015-03-01 02:02:49 +01:00
}
2015-03-03 16:20:09 +01:00
const request *session::submit(boost::system::error_code &ec,
const std::string &method,
const std::string &uri, generator_cb cb,
header_map h, priority_spec prio) const {
return impl_->submit(ec, method, uri, std::move(cb), std::move(h),
std::move(prio));
2015-03-01 02:02:49 +01:00
}
void session::read_timeout(const boost::posix_time::time_duration &t) {
impl_->read_timeout(t);
}
priority_spec::priority_spec(const int32_t stream_id, const int32_t weight,
const bool exclusive)
: valid_(true) {
nghttp2_priority_spec_init(&spec_, stream_id, weight, exclusive);
}
const nghttp2_priority_spec *priority_spec::get() const {
if (!valid_) {
return nullptr;
}
return &spec_;
}
const bool priority_spec::valid() const { return valid_; }
2015-03-01 02:02:49 +01:00
} // namespace client
} // namespace asio_http2
} // nghttp2