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

Commit5a1c841

Browse files
umenneldeanberris
authored andcommitted
Make http client connection buffer size configurable (#843)
Fixes#842
1 parent90847f3 commit5a1c841

File tree

8 files changed

+50
-28
lines changed

8 files changed

+50
-28
lines changed

‎boost/network/protocol/http/client.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include<string>
2222

2323
#include<boost/network/protocol/http/client/facade.hpp>
24-
#include<boost/network/protocol/http/client/macros.hpp>
2524
#include<boost/network/protocol/http/client/options.hpp>
2625

2726
namespaceboost {

‎boost/network/protocol/http/client/async_impl.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include<functional>
1414
#include<boost/asio/io_service.hpp>
1515
#include<boost/asio/strand.hpp>
16+
#include<boost/network/protocol/http/client/macros.hpp>
1617
#include<boost/network/protocol/http/traits/connection_policy.hpp>
1718

1819
namespaceboost {
@@ -31,7 +32,10 @@ struct async_client
3132
typedeftypename resolver<Tag>::type resolver_type;
3233
typedeftypename string<Tag>::type string_type;
3334

34-
typedeftypename std::array<typename char_<Tag>::type,1024>::const_iterator const_iterator;
35+
typedef
36+
typename std::array<typename char_<Tag>::type,
37+
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>::
38+
const_iterator const_iterator;
3539
typedef iterator_range<const_iterator> char_const_range;
3640

3741
typedef std::function<void(char_const_range,

‎boost/network/protocol/http/client/connection/async_base.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ struct async_connection_base {
3131
typedeftypename string<Tag>::type string_type;
3232
typedef basic_request<Tag> request;
3333
typedef basic_response<Tag> response;
34-
typedeftypename std::array<typename char_<Tag>::type,1024>::const_iterator const_iterator;
34+
typedef
35+
typename std::array<typename char_<Tag>::type,
36+
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>::
37+
const_iterator const_iterator;
3538
typedef iterator_range<const_iterator> char_const_range;
3639
typedef std::function<void(char_const_rangeconst &, boost::system::error_codeconst &)>
3740
body_callback_function_type;

‎boost/network/protocol/http/client/connection/async_normal.hpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ namespace network {
3838
namespacehttp {
3939
namespaceimpl {
4040

41-
template<classTag>
41+
template<classbuffer_type>
4242
structchunk_encoding_parser {
43+
typedeftypename buffer_type::const_iterator const_iterator;
44+
typedef boost::iterator_range<const_iterator> char_const_range;
45+
4346
chunk_encoding_parser() : state(state_t::header), chunk_size(0) {}
4447

4548
enumclassstate_t { header, header_end, data, data_end };
4649

4750
state_t state;
4851
size_t chunk_size;
49-
std::array<typename char_<Tag>::type,1024> buffer;
52+
buffer_type buffer;
5053

51-
voidupdate_chunk_size(
52-
boost::iterator_range<typename std::array<
53-
typename char_<Tag>::type,1024>::const_iterator>const &range) {
54+
voidupdate_chunk_size(char_const_rangeconst &range) {
5455
if (range.empty())return;
5556
std::stringstream ss;
5657
ss << std::hex << range;
@@ -60,11 +61,7 @@ struct chunk_encoding_parser {
6061
chunk_size = (chunk_size << (range.size() *4)) | size;
6162
}
6263

63-
boost::iterator_range<
64-
typename std::array<typename char_<Tag>::type,1024>::const_iterator>
65-
operator()(
66-
boost::iterator_range<typename std::array<
67-
typename char_<Tag>::type,1024>::const_iterator>const &range) {
64+
char_const_rangeoperator()(char_const_rangeconst &range) {
6865
auto iter =boost::begin(range);
6966
auto begin = iter;
7067
auto pos =boost::begin(buffer);
@@ -147,6 +144,7 @@ struct http_async_connection
147144
typedeftypename delegate_factory<Tag>::type delegate_factory_type;
148145
typedeftypename delegate_factory_type::connection_delegate_ptr
149146
connection_delegate_ptr;
147+
typedef chunk_encoding_parser<typename protocol_base::buffer_type> chunk_encoding_parser_type;
150148

151149
http_async_connection(resolver_type& resolver, resolve_function resolve,
152150
bool follow_redirect,int timeout,
@@ -484,13 +482,14 @@ struct http_async_connection
484482
}else {
485483
string_type body_string;
486484
if (this->is_chunk_encoding && remove_chunk_markers_) {
487-
for (size_t i =0; i <this->partial_parsed.size(); i +=1024) {
485+
constauto parse_buffer_size = parse_chunk_encoding.buffer.size();
486+
for (size_t i =0; i <this->partial_parsed.size(); i += parse_buffer_size) {
488487
auto range =parse_chunk_encoding(boost::make_iterator_range(
489-
static_cast<typename std::array<typename char_<Tag>::type,1024>::const_iterator>(
490-
this->partial_parsed.data()) + i,
491-
static_cast<typename std::array<typename char_<Tag>::type,1024>::const_iterator>(
492-
this->partial_parsed.data()) +
493-
std::min(i +1024,this->partial_parsed.size())));
488+
static_cast<
489+
typename chunk_encoding_parser_type::const_iterator>(this->partial_parsed.data()) + i,
490+
static_cast<
491+
typename chunk_encoding_parser_type::const_iterator>(this->partial_parsed.data()) +
492+
std::min(i +parse_buffer_size,this->partial_parsed.size())));
494493
body_string.append(boost::begin(range),boost::end(range));
495494
}
496495
this->partial_parsed.clear();
@@ -602,7 +601,7 @@ struct http_async_connection
602601
connection_delegate_ptr delegate_;
603602
boost::asio::streambuf command_streambuf;
604603
string_type method;
605-
chunk_encoding_parser<Tag> parse_chunk_encoding;
604+
chunk_encoding_parser_type parse_chunk_encoding;
606605
};
607606

608607
}// namespace impl

‎boost/network/protocol/http/client/connection/async_protocol_handler.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include<array>
1414
#include<boost/logic/tribool.hpp>
1515
#include<boost/network/detail/debug.hpp>
16+
#include<boost/network/protocol/http/client/macros.hpp>
1617
#include<boost/network/protocol/http/algorithms/linearize.hpp>
1718
#include<boost/network/protocol/http/parser/incremental.hpp>
1819
#include<boost/network/protocol/http/request_parser.hpp>
@@ -400,8 +401,8 @@ struct http_async_protocol_handler {
400401
}
401402

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

406407
response_parser_type response_parser_;
407408
boost::promise<string_type> version_promise;

‎boost/network/protocol/http/client/facade.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ class basic_client_facade {
4040
/** The response type. This models the HTTP Response concept.*/
4141
typedef basic_response<Tag> response;
4242

43-
typedeftypename std::array<typename char_<Tag>::type,1024>::const_iterator const_iterator;
43+
typedef
44+
typename std::array<typename char_<Tag>::type,
45+
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>::
46+
const_iterator const_iterator;
4447
typedef iterator_range<const_iterator> char_const_range;
4548

4649
/**

‎boost/network/protocol/http/client/macros.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@
1010
#include<array>
1111
#include<system_error>
1212

13+
#ifndef BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE
14+
/**
15+
* We define the buffer size for each connection that we will use on the client
16+
* side.
17+
*/
18+
#defineBOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE 4096uL
19+
#endif
20+
1321
#ifndef BOOST_NETWORK_HTTP_BODY_CALLBACK
14-
#defineBOOST_NETWORK_HTTP_BODY_CALLBACK(function_name, range_name, \
15-
error_name) \
16-
voidfunction_name(boost::iterator_range<std::array<char,1024>::const_iterator> (range_name), \
17-
boost::system::error_codeconst& (error_name))
22+
#defineBOOST_NETWORK_HTTP_BODY_CALLBACK(function_name, range_name, error_name)\
23+
voidfunction_name( \
24+
boost::iterator_range< \
25+
std::array<char, BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>:: \
26+
const_iterator>(range_name), \
27+
boost::system::error_codeconst&(error_name))
1828
#endif
1929

2030
#endif/* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_MACROS_HPP_20110430*/

‎boost/network/protocol/http/policies/async_connection.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ struct async_connection_policy : resolver_policy<Tag>::type {
3030
typedeftypename resolver_base::resolve_function resolve_function;
3131
typedeftypename resolver_base::resolve_completion_function
3232
resolve_completion_function;
33-
typedeftypename std::array<typename char_<Tag>::type,1024>::const_iterator const_iterator;
33+
typedef
34+
typename std::array<typename char_<Tag>::type,
35+
BOOST_NETWORK_HTTP_CLIENT_CONNECTION_BUFFER_SIZE>::
36+
const_iterator const_iterator;
3437
typedef iterator_range<const_iterator> char_const_range;
3538
typedef std::function<void(char_const_range,
3639
boost::system::error_codeconst&)>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp