Merge pull request #881 from mway/dev/request-priority
Support specifying stream priority via session::submit()
This commit is contained in:
commit
a1bc83a2ba
|
@ -96,29 +96,48 @@ boost::asio::io_service &session::io_service() const {
|
||||||
|
|
||||||
const request *session::submit(boost::system::error_code &ec,
|
const request *session::submit(boost::system::error_code &ec,
|
||||||
const std::string &method,
|
const std::string &method,
|
||||||
const std::string &uri, header_map h) const {
|
const std::string &uri, header_map h,
|
||||||
return impl_->submit(ec, method, uri, generator_cb(), std::move(h));
|
priority_spec prio) const {
|
||||||
|
return impl_->submit(ec, method, uri, generator_cb(), std::move(h),
|
||||||
|
std::move(prio));
|
||||||
}
|
}
|
||||||
|
|
||||||
const request *session::submit(boost::system::error_code &ec,
|
const request *session::submit(boost::system::error_code &ec,
|
||||||
const std::string &method,
|
const std::string &method,
|
||||||
const std::string &uri, std::string data,
|
const std::string &uri, std::string data,
|
||||||
header_map h) const {
|
header_map h, priority_spec prio) const {
|
||||||
return impl_->submit(ec, method, uri, string_generator(std::move(data)),
|
return impl_->submit(ec, method, uri, string_generator(std::move(data)),
|
||||||
std::move(h));
|
std::move(h), std::move(prio));
|
||||||
}
|
}
|
||||||
|
|
||||||
const request *session::submit(boost::system::error_code &ec,
|
const request *session::submit(boost::system::error_code &ec,
|
||||||
const std::string &method,
|
const std::string &method,
|
||||||
const std::string &uri, generator_cb cb,
|
const std::string &uri, generator_cb cb,
|
||||||
header_map h) const {
|
header_map h, priority_spec prio) const {
|
||||||
return impl_->submit(ec, method, uri, std::move(cb), std::move(h));
|
return impl_->submit(ec, method, uri, std::move(cb), std::move(h),
|
||||||
|
std::move(prio));
|
||||||
}
|
}
|
||||||
|
|
||||||
void session::read_timeout(const boost::posix_time::time_duration &t) {
|
void session::read_timeout(const boost::posix_time::time_duration &t) {
|
||||||
impl_->read_timeout(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_; }
|
||||||
|
|
||||||
} // namespace client
|
} // namespace client
|
||||||
} // namespace asio_http2
|
} // namespace asio_http2
|
||||||
} // nghttp2
|
} // nghttp2
|
||||||
|
|
|
@ -479,7 +479,7 @@ std::unique_ptr<stream> session_impl::create_stream() {
|
||||||
const request *session_impl::submit(boost::system::error_code &ec,
|
const request *session_impl::submit(boost::system::error_code &ec,
|
||||||
const std::string &method,
|
const std::string &method,
|
||||||
const std::string &uri, generator_cb cb,
|
const std::string &uri, generator_cb cb,
|
||||||
header_map h) {
|
header_map h, priority_spec prio) {
|
||||||
ec.clear();
|
ec.clear();
|
||||||
|
|
||||||
if (stopped_) {
|
if (stopped_) {
|
||||||
|
@ -559,7 +559,7 @@ const request *session_impl::submit(boost::system::error_code &ec,
|
||||||
prdptr = &prd;
|
prdptr = &prd;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stream_id = nghttp2_submit_request(session_, nullptr, nva.data(),
|
auto stream_id = nghttp2_submit_request(session_, prio.get(), nva.data(),
|
||||||
nva.size(), prdptr, strm.get());
|
nva.size(), prdptr, strm.get());
|
||||||
if (stream_id < 0) {
|
if (stream_id < 0) {
|
||||||
ec = make_error_code(static_cast<nghttp2_error>(stream_id));
|
ec = make_error_code(static_cast<nghttp2_error>(stream_id));
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
|
|
||||||
const request *submit(boost::system::error_code &ec,
|
const request *submit(boost::system::error_code &ec,
|
||||||
const std::string &method, const std::string &uri,
|
const std::string &method, const std::string &uri,
|
||||||
generator_cb cb, header_map h);
|
generator_cb cb, header_map h, priority_spec spec);
|
||||||
|
|
||||||
virtual void start_connect(tcp::resolver::iterator endpoint_it) = 0;
|
virtual void start_connect(tcp::resolver::iterator endpoint_it) = 0;
|
||||||
virtual tcp::socket &socket() = 0;
|
virtual tcp::socket &socket() = 0;
|
||||||
|
|
|
@ -118,6 +118,28 @@ private:
|
||||||
std::unique_ptr<request_impl> impl_;
|
std::unique_ptr<request_impl> impl_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Wrapper around an nghttp2_priority_spec.
|
||||||
|
class priority_spec {
|
||||||
|
public:
|
||||||
|
// The default ctor is used only by sentinel values.
|
||||||
|
priority_spec() = default;
|
||||||
|
|
||||||
|
// Create a priority spec with the given priority settings.
|
||||||
|
explicit priority_spec(const int32_t stream_id, const int32_t weight,
|
||||||
|
const bool exclusive = false);
|
||||||
|
|
||||||
|
// Return a pointer to a valid nghttp2 priority spec, or null.
|
||||||
|
const nghttp2_priority_spec *get() const;
|
||||||
|
|
||||||
|
// Indicates whether or not this spec is valid (i.e. was constructed with
|
||||||
|
// values).
|
||||||
|
const bool valid() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
nghttp2_priority_spec spec_;
|
||||||
|
bool valid_ = false;
|
||||||
|
};
|
||||||
|
|
||||||
class session_impl;
|
class session_impl;
|
||||||
|
|
||||||
class session {
|
class session {
|
||||||
|
@ -177,7 +199,8 @@ public:
|
||||||
// succeeds, or nullptr and |ec| contains error message.
|
// succeeds, or nullptr and |ec| contains error message.
|
||||||
const request *submit(boost::system::error_code &ec,
|
const request *submit(boost::system::error_code &ec,
|
||||||
const std::string &method, const std::string &uri,
|
const std::string &method, const std::string &uri,
|
||||||
header_map h = header_map{}) const;
|
header_map h = header_map{},
|
||||||
|
priority_spec prio = priority_spec()) const;
|
||||||
|
|
||||||
// Submits request to server using |method| (e.g., "GET"), |uri|
|
// Submits request to server using |method| (e.g., "GET"), |uri|
|
||||||
// (e.g., "http://localhost/") and optionally additional header
|
// (e.g., "http://localhost/") and optionally additional header
|
||||||
|
@ -186,7 +209,8 @@ public:
|
||||||
// contains error message.
|
// contains error message.
|
||||||
const request *submit(boost::system::error_code &ec,
|
const request *submit(boost::system::error_code &ec,
|
||||||
const std::string &method, const std::string &uri,
|
const std::string &method, const std::string &uri,
|
||||||
std::string data, header_map h = header_map{}) const;
|
std::string data, header_map h = header_map{},
|
||||||
|
priority_spec prio = priority_spec()) const;
|
||||||
|
|
||||||
// Submits request to server using |method| (e.g., "GET"), |uri|
|
// Submits request to server using |method| (e.g., "GET"), |uri|
|
||||||
// (e.g., "http://localhost/") and optionally additional header
|
// (e.g., "http://localhost/") and optionally additional header
|
||||||
|
@ -195,7 +219,8 @@ public:
|
||||||
// nullptr and |ec| contains error message.
|
// nullptr and |ec| contains error message.
|
||||||
const request *submit(boost::system::error_code &ec,
|
const request *submit(boost::system::error_code &ec,
|
||||||
const std::string &method, const std::string &uri,
|
const std::string &method, const std::string &uri,
|
||||||
generator_cb cb, header_map h = header_map{}) const;
|
generator_cb cb, header_map h = header_map{},
|
||||||
|
priority_spec prio = priority_spec()) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<session_impl> impl_;
|
std::shared_ptr<session_impl> impl_;
|
||||||
|
|
Loading…
Reference in New Issue