@@ -91,7 +91,21 @@ namespace web { namespace http
91
91
}
92
92
request_context::report_error (errorcodeValue, message);
93
93
}
94
-
94
+
95
+ void set_timer (const int secs)
96
+ {
97
+ m_timer.expires_from_now (boost::posix_time::milliseconds (secs * 1000 ));
98
+ m_timer.async_wait (boost::bind (&linux_request_context::cancel, this , boost::asio::placeholders::error));
99
+ }
100
+
101
+ void reset_timer (const int secs)
102
+ {
103
+ if ( m_timer.expires_from_now (boost::posix_time::milliseconds (secs * 1000 )) > 0 )
104
+ {
105
+ m_timer.async_wait (boost::bind (&linux_request_context::cancel, this , boost::asio::placeholders::error));
106
+ }
107
+ }
108
+
95
109
tcp::socket m_socket;
96
110
std::unique_ptr<boost::asio::ssl::stream<tcp::socket &>> m_ssl_stream;
97
111
size_t m_known_size;
@@ -226,9 +240,7 @@ namespace web { namespace http
226
240
227
241
tcp::resolver::query query (host, utility::conversions::print_string (port));
228
242
229
- const int secs = static_cast <int >(client_config ().timeout ().count ());
230
- ctx->m_timer .expires_from_now (boost::posix_time::milliseconds (secs * 1000 ));
231
- ctx->m_timer .async_wait (boost::bind (&linux_request_context::cancel, ctx.get (), boost::asio::placeholders::error));
243
+ ctx->set_timer (static_cast <int >(client_config ().timeout ().count ()));
232
244
233
245
m_resolver.async_resolve (query, boost::bind (&linux_client::handle_resolve, this , boost::asio::placeholders::error, boost::asio::placeholders::iterator, ctx));
234
246
}
@@ -565,20 +577,17 @@ namespace web { namespace http
565
577
void async_read_until_buffersize (size_t size, ReadHandler handler, std::shared_ptr<linux_request_context> ctx)
566
578
{
567
579
size_t size_to_read = 0 ;
580
+ if (ctx->m_body_buf .size () < size)
581
+ {
582
+ size_to_read = size - ctx->m_body_buf .size ();
583
+ }
584
+
568
585
if (ctx->m_ssl_stream )
569
586
{
570
- if (ctx->m_body_buf .size () < size)
571
- {
572
- size_to_read = size - ctx->m_body_buf .size ();
573
- }
574
587
boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_body_buf , boost::asio::transfer_at_least (size_to_read), handler);
575
588
}
576
589
else
577
590
{
578
- if (ctx->m_body_buf .size () < size)
579
- {
580
- size_to_read = size - ctx->m_body_buf .size ();
581
- }
582
591
boost::asio::async_read (ctx->m_socket , ctx->m_body_buf , boost::asio::transfer_at_least (size_to_read), handler);
583
592
}
584
593
}
@@ -643,6 +652,7 @@ namespace web { namespace http
643
652
}
644
653
else
645
654
{
655
+ ctx->reset_timer (static_cast <int >(client_config ().timeout ().count ()));
646
656
auto writeBuffer = ctx->_get_writebuffer ();
647
657
writeBuffer.putn (boost::asio::buffer_cast<const uint8_t *>(ctx->m_body_buf .data ()), to_read).then ([=](pplx::task<size_t > op)
648
658
{
@@ -695,6 +705,7 @@ namespace web { namespace http
695
705
696
706
if (ctx->m_current_size < ctx->m_known_size )
697
707
{
708
+ ctx->reset_timer (static_cast <int >(client_config ().timeout ().count ()));
698
709
// more data need to be read
699
710
writeBuffer.putn (boost::asio::buffer_cast<const uint8_t *>(ctx->m_body_buf .data ()),
700
711
std::min (ctx->m_body_buf .size (), ctx->m_known_size - ctx->m_current_size )).then ([=](pplx::task<size_t > op)
0 commit comments