Skip to content

Commit b7bce79

Browse files
committed
Fixing Arithmetic for Buffers Vector Size
Making sure that the reservation of the size of the vector to contain the buffers would be exactly as long as it would be required.
1 parent a90bfd5 commit b7bce79

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

boost/network/protocol/http/server/async_connection.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace boost { namespace network { namespace http {
3737

3838
template <class Tag, class Handler>
3939
struct async_connection : boost::enable_shared_from_this<async_connection<Tag,Handler> > {
40+
static std::size_t const connection_buffer_size = BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE;
41+
4042
enum status_t {
4143
ok = 200
4244
, created = 201
@@ -151,9 +153,9 @@ namespace boost { namespace network { namespace http {
151153
bool headers_already_sent;
152154
asio::streambuf headers_buffer;
153155

154-
typedef boost::array<char, BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE>
156+
typedef boost::array<char, connection_buffer_size>
155157
buffer_type;
156-
typedef boost::array<char, BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE>
158+
typedef boost::array<char, connection_buffer_size>
157159
array;
158160
typedef std::list<shared_ptr<array> > array_list;
159161
typedef boost::shared_ptr<array_list> shared_array_list;
@@ -241,14 +243,11 @@ namespace boost { namespace network { namespace http {
241243

242244
std::size_t range_size = boost::distance(range);
243245
buffers->resize(
244-
(range_size / BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE)
245-
+ (range_size % BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE)
246+
(range_size / connection_buffer_size)
247+
+ ((range_size % connection_buffer_size)?1:0)
246248
);
247249
std::size_t slice_size =
248-
std::min(
249-
range_size,
250-
BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE
251-
);
250+
std::min(range_size,connection_buffer_size);
252251
typename boost::range_iterator<Range>::type
253252
start = boost::begin(range)
254253
, end = boost::end(range);
@@ -264,7 +263,7 @@ namespace boost { namespace network { namespace http {
264263
std::advance(start, slice_size);
265264
range = boost::make_iterator_range(start, end);
266265
range_size = boost::distance(range);
267-
slice_size = std::min(range_size, BOOST_NETWORK_HTTP_SERVER_CONNECTION_BUFFER_SIZE);
266+
slice_size = std::min(range_size, connection_buffer_size);
268267
}
269268

270269
if (!buffers->empty()) {

0 commit comments

Comments
 (0)