50
50
#include < cstddef>
51
51
#include < deque>
52
52
#include < functional>
53
- #include < limits>
54
53
#include < memory>
55
54
#include < string_view>
56
55
#include < utility>
@@ -59,13 +58,6 @@ namespace boost::redis {
59
58
namespace detail
60
59
{
61
60
62
- template <class DynamicBuffer >
63
- std::string_view buffer_view (DynamicBuffer buf) noexcept
64
- {
65
- char const * start = static_cast <char const *>(buf.data (0 , buf.size ()).data ());
66
- return std::string_view{start, std::size (buf)};
67
- }
68
-
69
61
template <class AsyncReadStream , class DynamicBuffer >
70
62
class append_some_op {
71
63
private:
@@ -250,6 +242,8 @@ template <class Conn, class Logger>
250
242
struct reader_op {
251
243
using parse_result = typename Conn::parse_result;
252
244
using parse_ret_type = typename Conn::parse_ret_type;
245
+ using dyn_buffer_type = asio::dynamic_string_buffer<char , std::char_traits<char >, std::allocator<char >>;
246
+
253
247
Conn* conn_;
254
248
Logger logger_;
255
249
parse_ret_type res_{parse_result::resp, 0 };
@@ -270,14 +264,14 @@ struct reader_op {
270
264
BOOST_ASIO_CORO_YIELD
271
265
async_append_some (
272
266
conn_->next_layer (),
273
- conn_->dbuf_ ,
267
+ dyn_buffer_type{ conn_->read_buffer_ , conn_-> cfg_ . max_read_size } ,
274
268
conn_->get_suggested_buffer_growth (),
275
269
std::move (self));
276
270
} else {
277
271
BOOST_ASIO_CORO_YIELD
278
272
async_append_some (
279
273
conn_->next_layer ().next_layer (),
280
- conn_->dbuf_ ,
274
+ dyn_buffer_type{ conn_->read_buffer_ , conn_-> cfg_ . max_read_size } ,
281
275
conn_->get_suggested_buffer_growth (),
282
276
std::move (self));
283
277
}
@@ -302,7 +296,7 @@ struct reader_op {
302
296
}
303
297
}
304
298
305
- res_ = conn_->on_read (buffer_view (conn_-> dbuf_ ), ec);
299
+ res_ = conn_->on_read (ec);
306
300
if (ec) {
307
301
logger_.trace (" reader_op (3)" , ec);
308
302
conn_->cancel (operation::run);
@@ -501,21 +495,17 @@ class basic_connection {
501
495
*
502
496
* @param ex Executor on which connection operation will run.
503
497
* @param ctx SSL context.
504
- * @param max_read_size Maximum read size that is passed to
505
- * the internal `asio::dynamic_buffer` constructor.
506
498
*/
507
499
explicit
508
500
basic_connection (
509
501
executor_type ex,
510
- asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client},
511
- std::size_t max_read_size = (std::numeric_limits<std::size_t >::max)())
502
+ asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client})
512
503
: ctx_{std::move (ctx)}
513
504
, stream_{std::make_unique<next_layer_type>(ex, ctx_)}
514
505
, writer_timer_{ex}
515
506
, receive_channel_{ex, 256 }
516
507
, resv_{ex}
517
508
, health_checker_{ex}
518
- , dbuf_{read_buffer_, max_read_size}
519
509
{
520
510
set_receive_response (ignore);
521
511
writer_timer_.expires_at ((std::chrono::steady_clock::time_point::max)());
@@ -525,9 +515,8 @@ class basic_connection {
525
515
explicit
526
516
basic_connection (
527
517
asio::io_context& ioc,
528
- asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client},
529
- std::size_t max_read_size = (std::numeric_limits<std::size_t >::max)())
530
- : basic_connection(ioc.get_executor(), std::move(ctx), max_read_size)
518
+ asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client})
519
+ : basic_connection(ioc.get_executor(), std::move(ctx))
531
520
{ }
532
521
533
522
/* * @brief Starts underlying connection operations.
@@ -1126,13 +1115,13 @@ class basic_connection {
1126
1115
}
1127
1116
1128
1117
on_push_ = false ;
1129
- dbuf_. consume ( parser_.get_consumed ());
1118
+ read_buffer_. erase ( 0 , parser_.get_consumed ());
1130
1119
auto const res = std::make_pair (t, parser_.get_consumed ());
1131
1120
parser_.reset ();
1132
1121
return res;
1133
1122
}
1134
1123
1135
- parse_ret_type on_read (std::string_view data, system::error_code& ec)
1124
+ parse_ret_type on_read (system::error_code& ec)
1136
1125
{
1137
1126
// We arrive here in two states:
1138
1127
//
@@ -1148,7 +1137,7 @@ class basic_connection {
1148
1137
on_push_ = is_next_push ();
1149
1138
1150
1139
if (on_push_) {
1151
- if (!resp3::parse (parser_, data , receive_adapter_, ec))
1140
+ if (!resp3::parse (parser_, read_buffer_ , receive_adapter_, ec))
1152
1141
return std::make_pair (parse_result::needs_more, 0 );
1153
1142
1154
1143
if (ec)
@@ -1162,7 +1151,7 @@ class basic_connection {
1162
1151
BOOST_ASSERT (reqs_.front () != nullptr );
1163
1152
BOOST_ASSERT (reqs_.front ()->expected_responses_ != 0 );
1164
1153
1165
- if (!resp3::parse (parser_, data , reqs_.front ()->adapter_ , ec))
1154
+ if (!resp3::parse (parser_, read_buffer_ , reqs_.front ()->adapter_ , ec))
1166
1155
return std::make_pair (parse_result::needs_more, 0 );
1167
1156
1168
1157
if (ec) {
@@ -1205,11 +1194,8 @@ class basic_connection {
1205
1194
resp3_handshaker_type handshaker_;
1206
1195
receiver_adapter_type receive_adapter_;
1207
1196
1208
- using dyn_buffer_type = asio::dynamic_string_buffer<char , std::char_traits<char >, std::allocator<char >>;
1209
-
1210
1197
config cfg_;
1211
1198
std::string read_buffer_;
1212
- dyn_buffer_type dbuf_;
1213
1199
std::string write_buffer_;
1214
1200
reqs_type reqs_;
1215
1201
resp3::parser parser_{};
@@ -1237,15 +1223,13 @@ class connection {
1237
1223
explicit
1238
1224
connection (
1239
1225
executor_type ex,
1240
- asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client},
1241
- std::size_t max_read_size = (std::numeric_limits<std::size_t >::max)());
1226
+ asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client});
1242
1227
1243
1228
// / Contructs from a context.
1244
1229
explicit
1245
1230
connection (
1246
1231
asio::io_context& ioc,
1247
- asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client},
1248
- std::size_t max_read_size = (std::numeric_limits<std::size_t >::max)());
1232
+ asio::ssl::context ctx = asio::ssl::context{asio::ssl::context::tlsv12_client});
1249
1233
1250
1234
// / Returns the underlying executor.
1251
1235
executor_type get_executor () noexcept
0 commit comments