2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_WEBSOCKET_IMPL_SSL_HPP
11 #define BOOST_BEAST_WEBSOCKET_IMPL_SSL_HPP
14 #include <boost/beast/websocket/teardown.hpp>
15 #include <boost/asio/compose.hpp>
16 #include <boost/asio/coroutine.hpp>
24 http://stackoverflow.com/questions/32046034/what-is-the-proper-way-to-securely-disconnect-an-asio-ssl-socket/32054476#32054476
26 Behavior of ssl::stream regarding close_notify
28 If the remote host calls async_shutdown then the
29 local host's async_read will complete with eof.
31 If both hosts call async_shutdown then the calls
32 to async_shutdown will complete with eof.
36 template<class AsyncStream>
40 boost::asio::ssl::stream<AsyncStream>& stream,
44 using boost::beast::websocket::teardown;
46 teardown(role, stream.next_layer(), ec ? ec2 : ec);
51 template<class AsyncStream>
52 struct ssl_shutdown_op
53 : boost::asio::coroutine
56 boost::asio::ssl::stream<AsyncStream>& s,
65 operator()(Self& self, error_code ec = {}, std::size_t bytes_transferred = 0)
67 BOOST_ASIO_CORO_REENTER(*this)
70 s_.async_shutdown(std::move(self));
73 using boost::beast::websocket::async_teardown;
75 async_teardown(role_, s_.next_layer(), std::move(self));
84 boost::asio::ssl::stream<AsyncStream>& s_;
93 class TeardownHandler>
97 boost::asio::ssl::stream<AsyncStream>& stream,
98 TeardownHandler&& handler)
100 return boost::asio::async_compose<TeardownHandler, void(error_code)>(
101 detail::ssl_shutdown_op<AsyncStream>(stream, role),