Skip to content

Commit

Permalink
malloy::tcp::stream: add template parameter for rate policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Tectu committed Jul 29, 2022
1 parent 637eea2 commit 48ffbc0
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
6 changes: 3 additions & 3 deletions lib/malloy/client/controller.hpp
Expand Up @@ -305,11 +305,11 @@ namespace malloy::client
auto conn = websocket::connection::make(m_cfg.logger->clone("connection"), [this]() -> malloy::websocket::stream {
#if MALLOY_FEATURE_TLS
if constexpr (isSecure) {
return malloy::websocket::stream{boost::beast::ssl_stream<malloy::tcp::stream>{
malloy::tcp::stream{boost::asio::make_strand(*m_ioc)}, *m_tls_ctx}};
return malloy::websocket::stream{boost::beast::ssl_stream<malloy::tcp::stream<>>{
malloy::tcp::stream<>{boost::asio::make_strand(*m_ioc)}, *m_tls_ctx}};
} else
#endif
return malloy::websocket::stream{malloy::tcp::stream{boost::asio::make_strand(*m_ioc)}};
return malloy::websocket::stream{malloy::tcp::stream<>{boost::asio::make_strand(*m_ioc)}};
}(), m_cfg.user_agent);

conn->connect(results, resource, [conn, done = std::forward<decltype(done)>(done)](auto ec) mutable {
Expand Down
4 changes: 2 additions & 2 deletions lib/malloy/client/http/connection_plain.hpp
Expand Up @@ -25,7 +25,7 @@ namespace malloy::client::http

// Called by base class
[[nodiscard]]
malloy::tcp::stream&
malloy::tcp::stream<>&
stream()
{
return m_stream;
Expand All @@ -39,6 +39,6 @@ namespace malloy::client::http
}

private:
malloy::tcp::stream m_stream;
malloy::tcp::stream<> m_stream;
};
}
4 changes: 2 additions & 2 deletions lib/malloy/client/http/connection_tls.hpp
Expand Up @@ -32,7 +32,7 @@ namespace malloy::client::http

// Called by base class
[[nodiscard]]
boost::beast::ssl_stream<malloy::tcp::stream>&
boost::beast::ssl_stream<malloy::tcp::stream<>>&
stream()
{
return m_stream;
Expand All @@ -52,7 +52,7 @@ namespace malloy::client::http
}

private:
boost::beast::ssl_stream<malloy::tcp::stream> m_stream;
boost::beast::ssl_stream<malloy::tcp::stream<>> m_stream;

void
on_handshake(const boost::beast::error_code ec)
Expand Down
9 changes: 6 additions & 3 deletions lib/malloy/core/tcp/stream.hpp
Expand Up @@ -9,13 +9,16 @@ namespace malloy::tcp

/**
* A TCP stream.
*
* @details A TCP stream has a rate policy. The default rate policy is `malloy::tcp::rate_policy::unlimited`.
*
* @tparam RatePolicy the rate policy.
*/
// ToDo: RatePolicy template parameter
//template<class RatePolicy = malloy::tcp::rate_policy::unlimited>
template<class RatePolicy = malloy::tcp::rate_policy::unlimited>
using stream = boost::beast::basic_stream<
boost::asio::ip::tcp,
boost::asio::any_io_executor,
malloy::tcp::rate_policy::unlimited
RatePolicy
>;

}
5 changes: 0 additions & 5 deletions lib/malloy/core/tcp/tcp.hpp
@@ -1,8 +1,3 @@
#pragma onceusing tcp_stream = basic_stream<
net::ip::tcp,
net::any_io_executor,
unlimited_rate_policy>;

/**
* @namespace malloy::tcp
*
Expand Down
14 changes: 7 additions & 7 deletions lib/malloy/core/websocket/stream.hpp
Expand Up @@ -24,14 +24,14 @@ namespace malloy::websocket

#if MALLOY_FEATURE_TLS
using tls_stream = boost::beast::websocket::stream<
boost::beast::ssl_stream<malloy::tcp::stream>
boost::beast::ssl_stream<malloy::tcp::stream<>>
>;
#endif
using websocket_t = std::variant<
#if MALLOY_FEATURE_TLS
tls_stream,
#endif
boost::beast::websocket::stream<malloy::tcp::stream>
boost::beast::websocket::stream<malloy::tcp::stream<>>
>;
template<typename T>
concept rw_completion_token = boost::asio::completion_token_for<T, void(malloy::error_code, std::size_t)>;
Expand All @@ -56,14 +56,14 @@ namespace malloy::websocket
}

explicit
stream(boost::beast::websocket::stream<malloy::tcp::stream>&& s) :
stream(boost::beast::websocket::stream<malloy::tcp::stream<>>&& s) :
m_underlying_conn{ std::move(s) }
{
}

explicit
stream(malloy::tcp::stream&& from) :
stream{boost::beast::websocket::stream<malloy::tcp::stream>{std::move(from)}}
stream(malloy::tcp::stream<>&& from) :
stream{boost::beast::websocket::stream<malloy::tcp::stream<>>{std::move(from)}}
{
}

Expand All @@ -75,10 +75,10 @@ namespace malloy::websocket
}

explicit
stream(boost::beast::ssl_stream<malloy::tcp::stream>&& from) :
stream(boost::beast::ssl_stream<malloy::tcp::stream<>>&& from) :
stream{malloy::websocket::detail::tls_stream{
boost::beast::websocket::stream<
boost::beast::ssl_stream<malloy::tcp::stream>
boost::beast::ssl_stream<malloy::tcp::stream<>>
>{std::move(from)}}}
{
}
Expand Down
2 changes: 1 addition & 1 deletion lib/malloy/server/http/connection_detector.hpp
Expand Up @@ -57,7 +57,7 @@ namespace malloy::server::http

private:
std::shared_ptr<spdlog::logger> m_logger;
malloy::tcp::stream m_stream;
malloy::tcp::stream<> m_stream;
std::shared_ptr<boost::asio::ssl::context> m_ctx;
boost::beast::flat_buffer m_buffer;
std::shared_ptr<const std::filesystem::path> m_doc_root;
Expand Down
6 changes: 3 additions & 3 deletions lib/malloy/server/http/connection_plain.hpp
Expand Up @@ -36,7 +36,7 @@ namespace malloy::server::http

// Called by the base class
[[nodiscard]]
malloy::tcp::stream&
malloy::tcp::stream<>&
stream()
{
return m_stream;
Expand All @@ -48,7 +48,7 @@ namespace malloy::server::http
* @return The stream.
*/
[[nodiscard]]
malloy::tcp::stream
malloy::tcp::stream<>
release_stream()
{
return std::move(m_stream);
Expand Down Expand Up @@ -86,7 +86,7 @@ namespace malloy::server::http
}

private:
malloy::tcp::stream m_stream;
malloy::tcp::stream<> m_stream;
};

}
6 changes: 3 additions & 3 deletions lib/malloy/server/http/connection_tls.hpp
Expand Up @@ -39,14 +39,14 @@ namespace malloy::server::http

// Called by the base class
[[nodiscard]]
boost::beast::ssl_stream<malloy::tcp::stream>&
boost::beast::ssl_stream<malloy::tcp::stream<>>&
stream()
{
return m_stream;
}

[[nodiscard]]
boost::beast::ssl_stream<malloy::tcp::stream>
boost::beast::ssl_stream<malloy::tcp::stream<>>
release_stream()
{
return std::move(m_stream);
Expand Down Expand Up @@ -110,7 +110,7 @@ namespace malloy::server::http

private:
std::shared_ptr<boost::asio::ssl::context> m_ctx; // Keep the context alive
boost::beast::ssl_stream<malloy::tcp::stream> m_stream;
boost::beast::ssl_stream<malloy::tcp::stream<>> m_stream;
};

}

0 comments on commit 48ffbc0

Please sign in to comment.