@@ -102,10 +102,21 @@ namespace web { namespace http
102
102
if (!ec)
103
103
{
104
104
m_timedout = true ;
105
- auto sock = m_socket.get ();
106
- if (sock != nullptr )
105
+ if (m_ssl_stream)
107
106
{
108
- sock->cancel ();
107
+ boost::system::error_code error;
108
+ m_ssl_stream->lowest_layer ().cancel (error);
109
+
110
+ if (error)
111
+ report_error (" Failed to cancel the socket" , error);
112
+ }
113
+ else
114
+ {
115
+ auto sock = m_socket.get ();
116
+ if (sock != nullptr )
117
+ {
118
+ sock->cancel ();
119
+ }
109
120
}
110
121
}
111
122
}
@@ -270,11 +281,23 @@ namespace web { namespace http
270
281
else
271
282
{
272
283
boost::system::error_code ignore;
273
- ctx->m_socket ->shutdown (tcp::socket::shutdown_both, ignore);
274
- ctx->m_socket ->close ();
275
- ctx->m_socket .reset (new tcp::socket (m_io_service));
276
284
auto endpoint = *endpoints;
277
- ctx->m_socket ->async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
285
+ if (ctx->m_ssl_stream )
286
+ {
287
+ ctx->m_ssl_stream ->lowest_layer ().shutdown (tcp::socket::shutdown_both, ignore);
288
+ ctx->m_ssl_stream ->lowest_layer ().close ();
289
+ boost::asio::ssl::context context (boost::asio::ssl::context::sslv23);
290
+ context.set_verify_mode (boost::asio::ssl::context::verify_none);
291
+ ctx->m_ssl_stream .reset (new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(m_io_service, context));
292
+ ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
293
+ }
294
+ else
295
+ {
296
+ ctx->m_socket ->shutdown (tcp::socket::shutdown_both, ignore);
297
+ ctx->m_socket ->close ();
298
+ ctx->m_socket .reset (new tcp::socket (m_io_service));
299
+ ctx->m_socket ->async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
300
+ }
278
301
}
279
302
}
280
303
@@ -351,11 +374,11 @@ namespace web { namespace http
351
374
ctx->m_current_size += actualSize;
352
375
ctx->m_request_buf .commit (actualSize);
353
376
if (ctx->m_ssl_stream )
354
- boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
355
- boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
377
+ boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
378
+ boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
356
379
else
357
- boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
358
- boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
380
+ boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
381
+ boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
359
382
});
360
383
}
361
384
@@ -497,17 +520,17 @@ namespace web { namespace http
497
520
{
498
521
if (ctx->m_ssl_stream )
499
522
{
500
- if (ctx-> m_response_buf . size () >= size)
501
- boost::asio::async_read (* ctx->m_ssl_stream , ctx-> m_response_buf , boost::asio::transfer_at_least ( 0 ), handler);
502
- else
503
- boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_response_buf , boost::asio::transfer_at_least (size - ctx-> m_response_buf . size () ), handler);
523
+ int size_to_read = 0 ;
524
+ if ( ctx->m_response_buf . size () < size)
525
+ size_to_read = size - ctx-> m_response_buf . size ();
526
+ boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_response_buf , boost::asio::transfer_at_least (size_to_read ), handler);
504
527
}
505
528
else
506
529
{
507
- if (ctx-> m_response_buf . size () >= size)
508
- boost::asio::async_read (* ctx->m_socket , ctx-> m_response_buf , boost::asio::transfer_at_least ( 0 ), handler);
509
- else
510
- boost::asio::async_read (*ctx->m_socket , ctx->m_response_buf , boost::asio::transfer_at_least (size - ctx-> m_response_buf . size () ), handler);
530
+ int size_to_read = 0 ;
531
+ if ( ctx->m_response_buf . size () < size)
532
+ size_to_read = size - ctx-> m_response_buf . size ();
533
+ boost::asio::async_read (*ctx->m_socket , ctx->m_response_buf , boost::asio::transfer_at_least (size_to_read ), handler);
511
534
}
512
535
}
513
536
0 commit comments