Skip to content

Commit

Permalink
[#43] Use trailing underscores for member variables.
Browse files Browse the repository at this point in the history
This commit also adjusts things to satisfy other iRODS conventions.

A notable change is the addition of "const noexcept" on
"transport::is_connected()".
  • Loading branch information
korydraughn authored and trel committed Jan 25, 2024
1 parent 253ad92 commit cfb0c76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
15 changes: 8 additions & 7 deletions core/include/irods/private/http_api/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace irods::http
virtual ~transport() = default;

auto connect(std::string_view _host, std::string_view _port) -> void;
auto is_connected() -> bool;
auto is_connected() const noexcept -> bool;
auto communicate(boost::beast::http::request<boost::beast::http::string_body>& _request)
-> boost::beast::http::response<boost::beast::http::string_body>;

Expand All @@ -36,8 +36,8 @@ namespace irods::http
virtual auto do_write(boost::beast::http::request<boost::beast::http::string_body>& _request) -> void = 0;
virtual auto do_read() -> boost::beast::http::response<boost::beast::http::string_body> = 0;

boost::asio::io_context& _io_ctx;
bool _did_connect;
boost::asio::io_context& io_ctx_;
bool did_connect_;
}; // class transport

class tls_transport : public transport
Expand All @@ -55,7 +55,7 @@ namespace irods::http
auto disconnect() -> void;
auto set_sni_hostname(std::string_view _host) -> void;

boost::beast::ssl_stream<boost::beast::tcp_stream> _stream;
boost::beast::ssl_stream<boost::beast::tcp_stream> stream_;
}; // class tls_transport

class plain_transport : public transport
Expand All @@ -70,10 +70,11 @@ namespace irods::http
auto do_read() -> boost::beast::http::response<boost::beast::http::string_body> override;
auto disconnect() -> void;

boost::beast::tcp_stream _stream;
boost::beast::tcp_stream stream_;
}; // class plain_transport

auto transport_factory(const boost::urls::scheme& _scheme, boost::asio::io_context& _ctx)
-> std::unique_ptr<transport>;
} //namespace irods::http
#endif
} // namespace irods::http

#endif // IRODS_HTTP_API_TRANSPORT_HPP
34 changes: 17 additions & 17 deletions core/src/transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
namespace irods::http
{
transport::transport(boost::asio::io_context& _ctx)
: _io_ctx{_ctx}
: io_ctx_{_ctx}
{
}

auto transport::connect(std::string_view _host, std::string_view _port) -> void
{
auto res{resolve(_host, _port)};
do_connect(res);
_did_connect = true;
did_connect_ = true;
}

auto transport::is_connected() -> bool
auto transport::is_connected() const noexcept -> bool
{
return _did_connect;
return did_connect_;
}

auto transport::communicate(boost::beast::http::request<boost::beast::http::string_body>& _request)
Expand All @@ -33,13 +33,13 @@ namespace irods::http
auto transport::resolve(std::string_view _host, std::string_view _port)
-> boost::asio::ip::tcp::resolver::results_type
{
boost::asio::ip::tcp::resolver tcp_res{_io_ctx};
boost::asio::ip::tcp::resolver tcp_res{io_ctx_};
return tcp_res.resolve(_host, _port);
}

tls_transport::tls_transport(boost::asio::io_context& _ctx, boost::asio::ssl::context& _secure_ctx)
: transport{_ctx}
, _stream{_ctx, _secure_ctx}
, stream_{_ctx, _secure_ctx}
{
}

Expand All @@ -59,42 +59,42 @@ namespace irods::http

auto tls_transport::do_connect(boost::asio::ip::tcp::resolver::results_type& _resolved_host) -> void
{
boost::beast::get_lowest_layer(_stream).connect(_resolved_host);
_stream.handshake(boost::asio::ssl::stream_base::client);
boost::beast::get_lowest_layer(stream_).connect(_resolved_host);
stream_.handshake(boost::asio::ssl::stream_base::client);
}

auto tls_transport::do_write(boost::beast::http::request<boost::beast::http::string_body>& _request) -> void
{
boost::beast::http::write(_stream, _request);
boost::beast::http::write(stream_, _request);
}

auto tls_transport::do_read() -> boost::beast::http::response<boost::beast::http::string_body>
{
boost::beast::flat_buffer buffer;
boost::beast::http::response<boost::beast::http::string_body> res;
boost::beast::http::read(_stream, buffer, res);
boost::beast::http::read(stream_, buffer, res);

return res;
}

auto tls_transport::disconnect() -> void
{
boost::beast::error_code ec;
_stream.shutdown(ec);
stream_.shutdown(ec);
}

auto tls_transport::set_sni_hostname(std::string_view _host) -> void
{
// Set SNI Hostname (many hosts need this to handshake successfully)
if (!SSL_set_tlsext_host_name(_stream.native_handle(), _host.data())) {
if (!SSL_set_tlsext_host_name(stream_.native_handle(), _host.data())) {
boost::beast::error_code ec{static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()};
throw boost::beast::system_error{ec};
}
}

plain_transport::plain_transport(boost::asio::io_context& _ctx)
: transport{_ctx}
, _stream{_ctx}
, stream_{_ctx}
{
}

Expand All @@ -107,27 +107,27 @@ namespace irods::http

auto plain_transport::do_connect(boost::asio::ip::tcp::resolver::results_type& _resolved_host) -> void
{
_stream.connect(_resolved_host);
stream_.connect(_resolved_host);
}

auto plain_transport::do_write(boost::beast::http::request<boost::beast::http::string_body>& _request) -> void
{
boost::beast::http::write(_stream, _request);
boost::beast::http::write(stream_, _request);
}

auto plain_transport::do_read() -> boost::beast::http::response<boost::beast::http::string_body>
{
boost::beast::flat_buffer buffer;
boost::beast::http::response<boost::beast::http::string_body> res;
boost::beast::http::read(_stream, buffer, res);
boost::beast::http::read(stream_, buffer, res);

return res;
}

auto plain_transport::disconnect() -> void
{
boost::beast::error_code ec;
_stream.socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
stream_.socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
}

auto make_secure_context() -> boost::asio::ssl::context
Expand Down

0 comments on commit cfb0c76

Please sign in to comment.