Skip to content

Commit

Permalink
Prepare TLS::Stream for usage with co_await
Browse files Browse the repository at this point in the history
Co-Authored-By: Fabian Albert <[email protected]>
  • Loading branch information
reneme and FAlbertDev committed Oct 18, 2023
1 parent f873880 commit 931e92c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/lib/tls/asio/asio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class StreamCallbacks : public Callbacks {
*/
template <class StreamLayer, class ChannelT = Channel>
class Stream {
private:
using default_completion_token =
boost::asio::default_completion_token_t<boost::beast::executor_type<StreamLayer>>;

public:
//! \name construction
//! @{
Expand Down Expand Up @@ -342,8 +346,9 @@ class Stream {
* @param completion_token The completion handler to be called when the handshake operation completes.
* The completion signature of the handler must be: void(boost::system::error_code).
*/
template <typename CompletionToken>
auto async_handshake(Botan::TLS::Connection_Side side, CompletionToken&& completion_token) {
template <typename CompletionToken = default_completion_token>
auto async_handshake(Botan::TLS::Connection_Side side,
CompletionToken&& completion_token = default_completion_token{}) {
return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code)>(
[this](auto&& completion_handler, TLS::Connection_Side connection_side) {
using completion_handler_t = std::decay_t<decltype(completion_handler)>;
Expand Down Expand Up @@ -442,8 +447,8 @@ class Stream {
* @param completion_token The completion handler to be called when the shutdown operation completes.
* The completion signature of the handler must be: void(boost::system::error_code).
*/
template <typename CompletionToken>
auto async_shutdown(CompletionToken&& completion_token) {
template <typename CompletionToken = default_completion_token>
auto async_shutdown(CompletionToken&& completion_token = default_completion_token{}) {
return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code)>(
[this](auto&& completion_handler) {
using completion_handler_t = std::decay_t<decltype(completion_handler)>;
Expand Down Expand Up @@ -569,8 +574,9 @@ class Stream {
* handler will be made as required. The completion signature of the handler must be:
* void(boost::system::error_code, std::size_t).
*/
template <typename ConstBufferSequence, typename CompletionToken>
auto async_write_some(const ConstBufferSequence& buffers, CompletionToken&& completion_token) {
template <typename ConstBufferSequence, typename CompletionToken = default_completion_token>
auto async_write_some(const ConstBufferSequence& buffers,
CompletionToken&& completion_token = default_completion_token{}) {
return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code, std::size_t)>(
[this](auto&& completion_handler, const auto& bufs) {
using completion_handler_t = std::decay_t<decltype(completion_handler)>;
Expand Down Expand Up @@ -605,8 +611,9 @@ class Stream {
* @param completion_token The completion handler to be called when the read operation completes. The completion
* signature of the handler must be: void(boost::system::error_code, std::size_t).
*/
template <typename MutableBufferSequence, typename CompletionToken>
auto async_read_some(const MutableBufferSequence& buffers, CompletionToken&& completion_token) {
template <typename MutableBufferSequence, typename CompletionToken = default_completion_token>
auto async_read_some(const MutableBufferSequence& buffers,
CompletionToken&& completion_token = default_completion_token{}) {
return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code, std::size_t)>(
[this](auto&& completion_handler, const auto& bufs) {
using completion_handler_t = std::decay_t<decltype(completion_handler)>;
Expand Down

0 comments on commit 931e92c

Please sign in to comment.