Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make http client connection buffer size configurable#843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make http client connection buffer size configurable
  • Loading branch information
@umennel
umennel committedMay 27, 2018
commit90feb460fca5a8dc9d05823a196bae9baa1924b2
1 change: 0 additions & 1 deletionboost/network/protocol/http/client.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,6 @@
#include <string>

#include <boost/network/protocol/http/client/facade.hpp>
#include <boost/network/protocol/http/client/macros.hpp>
#include <boost/network/protocol/http/client/options.hpp>

namespace boost {
Expand Down
6 changes: 5 additions & 1 deletionboost/network/protocol/http/client/async_impl.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
#include <functional>
#include <boost/asio/io_service.hpp>
#include <boost/asio/strand.hpp>
#include <boost/network/protocol/http/client/macros.hpp>
#include <boost/network/protocol/http/traits/connection_policy.hpp>

namespace boost {
Expand All@@ -31,7 +32,10 @@ struct async_client
typedef typename resolver<Tag>::type resolver_type;
typedef typename string<Tag>::type string_type;

typedef typename std::array<typename char_<Tag>::type, 1024>::const_iterator const_iterator;
typedef
typename std::array<typename char_<Tag>::type,
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>::
const_iterator const_iterator;
typedef iterator_range<const_iterator> char_const_range;

typedef std::function<void(char_const_range,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,10 @@ struct async_connection_base {
typedef typename string<Tag>::type string_type;
typedef basic_request<Tag> request;
typedef basic_response<Tag> response;
typedef typename std::array<typename char_<Tag>::type, 1024>::const_iterator const_iterator;
typedef
typename std::array<typename char_<Tag>::type,
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>::
const_iterator const_iterator;
typedef iterator_range<const_iterator> char_const_range;
typedef std::function<void(char_const_range const &, boost::system::error_code const &)>
body_callback_function_type;
Expand Down
33 changes: 16 additions & 17 deletionsboost/network/protocol/http/client/connection/async_normal.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,19 +38,20 @@ namespace network {
namespace http {
namespace impl {

template <classTag>
template <classbuffer_type>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't think this change is necessary... unless I'm missing something.

We're using theTag type to determine the character type being placed in the array definition. If anything, I suspect you want to lift the trait to determine what the buffer type should be for a given tag.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

My thought was that I didn't want to redefine the buffer_type in the parser, which is just a helper class. The actual buffer type is defined in the class utilizing the parser, and then just forwarded. IMHO it was redundancy introduced by mistake which enforced redefinition of exactly the same buffer type in a helper class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

True, but not in the way it's designed to use traits to dispatch on the tag. Arguably the problem is that we're hard-coding the type of the buffer instead of using the tag-based dispatch we've been using everywhere. Because this is currently an implementation detail, I think the way you've done it is fine -- but that we might want to think about the wider design of this, so that it can be applied more systematically.

At this point, since the tests pass I'm willing to merge this as-is, but something worth thinking about in the future to clean this up better.

struct chunk_encoding_parser {
typedef typename buffer_type::const_iterator const_iterator;
typedef boost::iterator_range<const_iterator> char_const_range;

chunk_encoding_parser() : state(state_t::header), chunk_size(0) {}

enum class state_t { header, header_end, data, data_end };

state_t state;
size_t chunk_size;
std::array<typename char_<Tag>::type, 1024> buffer;
buffer_type buffer;

void update_chunk_size(
boost::iterator_range<typename std::array<
typename char_<Tag>::type, 1024>::const_iterator> const &range) {
void update_chunk_size(char_const_range const &range) {
if (range.empty()) return;
std::stringstream ss;
ss << std::hex << range;
Expand All@@ -60,11 +61,7 @@ struct chunk_encoding_parser {
chunk_size = (chunk_size << (range.size() * 4)) | size;
}

boost::iterator_range<
typename std::array<typename char_<Tag>::type, 1024>::const_iterator>
operator()(
boost::iterator_range<typename std::array<
typename char_<Tag>::type, 1024>::const_iterator> const &range) {
char_const_range operator()(char_const_range const &range) {
auto iter = boost::begin(range);
auto begin = iter;
auto pos = boost::begin(buffer);
Expand DownExpand Up@@ -147,6 +144,7 @@ struct http_async_connection
typedef typename delegate_factory<Tag>::type delegate_factory_type;
typedef typename delegate_factory_type::connection_delegate_ptr
connection_delegate_ptr;
typedef chunk_encoding_parser<typename protocol_base::buffer_type> chunk_encoding_parser_type;

http_async_connection(resolver_type& resolver, resolve_function resolve,
bool follow_redirect, int timeout,
Expand DownExpand Up@@ -484,13 +482,14 @@ struct http_async_connection
} else {
string_type body_string;
if (this->is_chunk_encoding && remove_chunk_markers_) {
for (size_t i = 0; i < this->partial_parsed.size(); i += 1024) {
const auto parse_buffer_size = parse_chunk_encoding.buffer.size();
for (size_t i = 0; i < this->partial_parsed.size(); i += parse_buffer_size) {
auto range = parse_chunk_encoding(boost::make_iterator_range(
static_cast<typename std::array<typename char_<Tag>::type, 1024>::const_iterator>(
this->partial_parsed.data()) + i,
static_cast<typename std::array<typename char_<Tag>::type, 1024>::const_iterator>(
this->partial_parsed.data()) +
std::min(i +1024, this->partial_parsed.size())));
static_cast<
typename chunk_encoding_parser_type::const_iterator>(this->partial_parsed.data()) + i,
static_cast<
typename chunk_encoding_parser_type::const_iterator>(this->partial_parsed.data()) +
std::min(i +parse_buffer_size, this->partial_parsed.size())));
body_string.append(boost::begin(range), boost::end(range));
}
this->partial_parsed.clear();
Expand DownExpand Up@@ -602,7 +601,7 @@ struct http_async_connection
connection_delegate_ptr delegate_;
boost::asio::streambuf command_streambuf;
string_type method;
chunk_encoding_parser<Tag> parse_chunk_encoding;
chunk_encoding_parser_type parse_chunk_encoding;
};

} // namespace impl
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
#include <array>
#include <boost/logic/tribool.hpp>
#include <boost/network/detail/debug.hpp>
#include <boost/network/protocol/http/client/macros.hpp>
#include <boost/network/protocol/http/algorithms/linearize.hpp>
#include <boost/network/protocol/http/parser/incremental.hpp>
#include <boost/network/protocol/http/request_parser.hpp>
Expand DownExpand Up@@ -400,8 +401,8 @@ struct http_async_protocol_handler {
}

typedef response_parser<Tag> response_parser_type;
// TODO(dberris): make 1024 go away and become a configurable value.
typedef std::array<typename char_<Tag>::type, 1024> buffer_type;
typedef std::array<typename char_<Tag>::type,
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE> buffer_type;

response_parser_type response_parser_;
boost::promise<string_type> version_promise;
Expand Down
5 changes: 4 additions & 1 deletionboost/network/protocol/http/client/facade.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,10 @@ class basic_client_facade {
/** The response type. This models the HTTP Response concept.*/
typedef basic_response<Tag> response;

typedef typename std::array<typename char_<Tag>::type, 1024>::const_iterator const_iterator;
typedef
typename std::array<typename char_<Tag>::type,
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>::
const_iterator const_iterator;
typedef iterator_range<const_iterator> char_const_range;

/**
Expand Down
18 changes: 14 additions & 4 deletionsboost/network/protocol/http/client/macros.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,11 +10,21 @@
#include <array>
#include <system_error>

#ifndef BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE
/**
* We define the buffer size for each connection that we will use on the client
* side.
*/
#define BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE 4096uL
#endif

#ifndef BOOST_NETWORK_HTTP_BODY_CALLBACK
#define BOOST_NETWORK_HTTP_BODY_CALLBACK(function_name, range_name, \
error_name) \
void function_name(boost::iterator_range<std::array<char, 1024>::const_iterator> (range_name), \
boost::system::error_code const& (error_name))
#define BOOST_NETWORK_HTTP_BODY_CALLBACK(function_name, range_name, error_name)\
void function_name( \
boost::iterator_range< \
std::array<char, BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>:: \
const_iterator>(range_name), \
boost::system::error_code const&(error_name))
#endif

#endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_MACROS_HPP_20110430 */
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,10 @@ struct async_connection_policy : resolver_policy<Tag>::type {
typedef typename resolver_base::resolve_function resolve_function;
typedef typename resolver_base::resolve_completion_function
resolve_completion_function;
typedef typename std::array<typename char_<Tag>::type, 1024>::const_iterator const_iterator;
typedef
typename std::array<typename char_<Tag>::type,
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>::
const_iterator const_iterator;
typedef iterator_range<const_iterator> char_const_range;
typedef std::function<void(char_const_range,
boost::system::error_code const&)>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp