Skip to content

Commit eb208f3

Browse files
committed
Hide some private data members.
1 parent 92dbddd commit eb208f3

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

Release/src/http/client/http_linux.cpp

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace web { namespace http
5656
class linux_connection_pool;
5757
class linux_connection : public std::enable_shared_from_this<linux_connection>
5858
{
59+
friend class linux_connection_pool;
5960
public:
6061
linux_connection(std::weak_ptr<linux_connection_pool> pool_weak, boost::asio::io_service& io_service) :
6162
m_socket(io_service),
@@ -64,12 +65,23 @@ namespace web { namespace http
6465
m_is_reused(false)
6566
{}
6667

68+
void handle_pool_timer(const boost::system::error_code& ec);
69+
70+
tcp::socket& get_socket()
71+
{
72+
return m_socket;
73+
}
74+
75+
bool is_reused()
76+
{
77+
return m_is_reused;
78+
}
79+
80+
private:
6781
std::weak_ptr<linux_connection_pool> m_pool_weak;
6882
tcp::socket m_socket;
6983
boost::asio::deadline_timer m_pool_timer;
7084
bool m_is_reused;
71-
72-
void handle_pool_timer(const boost::system::error_code& ec);
7385
};
7486

7587
class linux_connection_pool : public std::enable_shared_from_this<linux_connection_pool>
@@ -215,7 +227,7 @@ namespace web { namespace http
215227
m_timedout = true;
216228

217229
boost::system::error_code error;
218-
m_connection->m_socket.cancel(error);
230+
m_connection->get_socket().cancel(error);
219231
if (error)
220232
{
221233
report_error("Failed to cancel the socket", error);
@@ -256,7 +268,7 @@ namespace web { namespace http
256268
{
257269
boost::asio::ssl::context context(boost::asio::ssl::context::sslv23);
258270
context.set_default_verify_paths();
259-
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection->m_socket, context));
271+
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection->get_socket(), context));
260272
}
261273

262274
auto encoded_resource = uri_builder(m_uri).append(ctx->m_request.relative_uri()).to_uri().resource().to_string();
@@ -331,7 +343,7 @@ namespace web { namespace http
331343

332344
ctx->set_timer(static_cast<int>(client_config().timeout().count()));
333345

334-
if (ctx->m_connection->m_socket.is_open())
346+
if (ctx->m_connection->get_socket().is_open())
335347
{
336348
write_request(ctx);
337349
}
@@ -388,7 +400,7 @@ namespace web { namespace http
388400
ctx->m_ssl_stream->set_verify_mode(boost::asio::ssl::context::verify_none);
389401
}
390402
}
391-
ctx->m_connection->m_socket.async_connect(endpoint, boost::bind(&linux_client::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints, ctx));
403+
ctx->m_connection->get_socket().async_connect(endpoint, boost::bind(&linux_client::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints, ctx));
392404
}
393405
}
394406

@@ -400,7 +412,7 @@ namespace web { namespace http
400412
}
401413
else
402414
{
403-
boost::asio::async_write(ctx->m_connection->m_socket, ctx->m_body_buf, boost::bind(&linux_client::handle_write_request, shared_from_this(), boost::asio::placeholders::error, ctx));
415+
boost::asio::async_write(ctx->m_connection->get_socket(), ctx->m_body_buf, boost::bind(&linux_client::handle_write_request, shared_from_this(), boost::asio::placeholders::error, ctx));
404416
}
405417
}
406418

@@ -419,16 +431,16 @@ namespace web { namespace http
419431
ctx->m_timeout_timer.cancel();
420432

421433
boost::system::error_code error;
422-
ctx->m_connection->m_socket.shutdown(tcp::socket::shutdown_both, error);
423-
ctx->m_connection->m_socket.close(error);
434+
ctx->m_connection->get_socket().shutdown(tcp::socket::shutdown_both, error);
435+
ctx->m_connection->get_socket().close(error);
424436
ctx->m_connection = m_pool->obtain();
425437

426438
auto endpoint = *endpoints;
427439
if (ctx->m_ssl_stream)
428440
{
429441
boost::asio::ssl::context context(boost::asio::ssl::context::sslv23);
430442
context.set_default_verify_paths();
431-
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection->m_socket, context));
443+
ctx->m_ssl_stream.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket &>(ctx->m_connection->get_socket(), context));
432444

433445
// Check to turn off server certificate verification.
434446
if(client_config().validate_certificates())
@@ -442,7 +454,7 @@ namespace web { namespace http
442454
}
443455
}
444456

445-
ctx->m_connection->m_socket.async_connect(endpoint, boost::bind(&linux_client::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints, ctx));
457+
ctx->m_connection->get_socket().async_connect(endpoint, boost::bind(&linux_client::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints, ctx));
446458
}
447459
}
448460

@@ -507,7 +519,7 @@ namespace web { namespace http
507519
}
508520
else
509521
{
510-
boost::asio::async_write(ctx->m_connection->m_socket, ctx->m_body_buf,
522+
boost::asio::async_write(ctx->m_connection->get_socket(), ctx->m_body_buf,
511523
boost::bind(readSize != 0 ? &linux_client::handle_write_chunked_body : &linux_client::handle_write_body,
512524
shared_from_this(), boost::asio::placeholders::error, ctx));
513525
}
@@ -562,7 +574,7 @@ namespace web { namespace http
562574
}
563575
else
564576
{
565-
boost::asio::async_write(ctx->m_connection->m_socket, ctx->m_body_buf,
577+
boost::asio::async_write(ctx->m_connection->get_socket(), ctx->m_body_buf,
566578
boost::bind(&linux_client::handle_write_large_body, shared_from_this(), boost::asio::placeholders::error, ctx));
567579
}
568580
});
@@ -615,7 +627,7 @@ namespace web { namespace http
615627
}
616628
else
617629
{
618-
boost::asio::async_read_until(ctx->m_connection->m_socket, ctx->m_body_buf, CRLF+CRLF,
630+
boost::asio::async_read_until(ctx->m_connection->get_socket(), ctx->m_body_buf, CRLF+CRLF,
619631
boost::bind(&linux_client::handle_status_line, shared_from_this(), boost::asio::placeholders::error, ctx));
620632
}
621633
}
@@ -657,13 +669,13 @@ namespace web { namespace http
657669
const bool socket_was_closed((boost::asio::error::eof == ec)
658670
|| (boost::asio::error::connection_reset == ec)
659671
|| (boost::asio::error::connection_aborted == ec));
660-
if (socket_was_closed && ctx->m_connection->m_is_reused && ctx->m_connection->m_socket.is_open())
672+
if (socket_was_closed && ctx->m_connection->is_reused() && ctx->m_connection->get_socket().is_open())
661673
{
662674
// Connection was closed by the server for some reason during the connection was
663675
// being pooled. We re-send the request to get a new connection.
664676
boost::system::error_code error;
665-
ctx->m_connection->m_socket.shutdown(tcp::socket::shutdown_both, error);
666-
ctx->m_connection->m_socket.close(error);
677+
ctx->m_connection->get_socket().shutdown(tcp::socket::shutdown_both, error);
678+
ctx->m_connection->get_socket().close(error);
667679
ctx->m_close_socket_in_destructor = true;
668680

669681
auto new_ctx = details::linux_client_request_context::create_request_context(ctx->m_http_client, ctx->m_request);
@@ -756,7 +768,7 @@ namespace web { namespace http
756768
}
757769
else
758770
{
759-
boost::asio::async_read_until(ctx->m_connection->m_socket, ctx->m_body_buf, CRLF,
771+
boost::asio::async_read_until(ctx->m_connection->get_socket(), ctx->m_body_buf, CRLF,
760772
boost::bind(&linux_client::handle_chunk_header, shared_from_this(), boost::asio::placeholders::error, ctx));
761773
}
762774
}
@@ -778,7 +790,7 @@ namespace web { namespace http
778790
}
779791
else
780792
{
781-
boost::asio::async_read(ctx->m_connection->m_socket, ctx->m_body_buf, boost::asio::transfer_at_least(size_to_read), handler);
793+
boost::asio::async_read(ctx->m_connection->get_socket(), ctx->m_body_buf, boost::asio::transfer_at_least(size_to_read), handler);
782794
}
783795
}
784796

@@ -873,7 +885,7 @@ namespace web { namespace http
873885
}
874886
else
875887
{
876-
boost::asio::async_read_until(ctx->m_connection->m_socket, ctx->m_body_buf, CRLF,
888+
boost::asio::async_read_until(ctx->m_connection->get_socket(), ctx->m_body_buf, CRLF,
877889
boost::bind(&linux_client::handle_chunk_header, shared_from_this(), boost::asio::placeholders::error, ctx));
878890
}
879891
});
@@ -1007,12 +1019,12 @@ namespace web { namespace http
10071019

10081020
if (m_close_socket_in_destructor)
10091021
{
1010-
m_connection->m_socket.shutdown(tcp::socket::shutdown_both, error);
1011-
m_connection->m_socket.close(error);
1022+
m_connection->get_socket().shutdown(tcp::socket::shutdown_both, error);
1023+
m_connection->get_socket().close(error);
10121024
}
10131025
else
10141026
{
1015-
m_connection->m_socket.cancel(error);
1027+
m_connection->get_socket().cancel(error);
10161028
std::static_pointer_cast<linux_client>(m_http_client)->m_pool->release(m_connection);
10171029
}
10181030
}

0 commit comments

Comments
 (0)