|
1 | 1 | //
|
2 |
| -// Copyright (c) 2018-2019 Christian Mazakas (christian dot mazakas at gmail dot |
3 |
| -// com) |
| 2 | +// Copyright (c) 2018-2019 Christian Mazakas (christian dot mazakas at gmail dot com) |
4 | 3 | //
|
5 |
| -// Distributed under the Boost Software License, Version 1.0. (See accompanying |
6 |
| -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 4 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt |
| 5 | +// or copy at http://www.boost.org/LICENSE_1_0.txt) |
7 | 6 | //
|
8 | 7 | // Official repository: https://github.com/LeonineKing1199/foxy
|
9 | 8 | //
|
|
12 | 11 | #define FOXY_IMPL_CLIENT_SESSION_ASYNC_SHUTDOWN_IMPL_HPP_
|
13 | 12 |
|
14 | 13 | #include <foxy/client_session.hpp>
|
15 |
| -#include <iostream> |
16 |
| -namespace launchdarkly::foxy { |
| 14 | + |
| 15 | +namespace launchdarkly::foxy |
| 16 | +{ |
17 | 17 | template <class DynamicBuffer>
|
18 | 18 | template <class ShutdownHandler>
|
19 |
| -auto basic_client_session<DynamicBuffer>::async_shutdown( |
20 |
| - ShutdownHandler&& handler) & -> |
21 |
| - typename boost::asio::async_result< |
22 |
| - std::decay_t<ShutdownHandler>, |
23 |
| - void(boost::system::error_code)>::return_type { |
24 |
| - return ::launchdarkly::foxy::detail::async_timer<void( |
25 |
| - boost::system::error_code)>( |
26 |
| - [self = this, coro = boost::asio::coroutine()]( |
27 |
| - auto& cb, boost::system::error_code ec = {}, |
28 |
| - std::size_t bytes_transferrred = 0) mutable { |
29 |
| - auto& s = *self; |
30 |
| - |
31 |
| - BOOST_ASIO_CORO_REENTER(coro) { |
32 |
| - if (s.stream.is_ssl()) { |
33 |
| - std::cout << "-> ssl().async_shutdown()\n"; |
34 |
| - BOOST_ASIO_CORO_YIELD s.stream.ssl().async_shutdown( |
35 |
| - std::move(cb)); |
36 |
| - std::cout << "<- ssl().async_shutdown: " << ec.message() |
37 |
| - << '\n'; |
38 |
| - if (ec == boost::asio::ssl::error::stream_truncated) { |
39 |
| - ec = {}; |
40 |
| - } |
41 |
| - if (ec) { |
42 |
| - goto upcall; |
43 |
| - } |
44 |
| - } |
45 |
| - |
46 |
| - std::cout << "plain socket shutdown\n"; |
47 |
| - s.stream.plain().shutdown( |
48 |
| - boost::asio::ip::tcp::socket::shutdown_both, ec); |
49 |
| - s.stream.plain().close(ec); |
50 |
| - |
51 |
| - upcall: |
52 |
| - std::cout << "invoke completion handler\n"; |
53 |
| - return cb.complete(ec); |
54 |
| - } |
55 |
| - }, |
56 |
| - *this, std::forward<ShutdownHandler>(handler)); |
| 19 | +auto |
| 20 | +basic_client_session<DynamicBuffer>::async_shutdown(ShutdownHandler&& handler) & -> |
| 21 | + typename boost::asio::async_result<std::decay_t<ShutdownHandler>, |
| 22 | + void(boost::system::error_code)>::return_type |
| 23 | +{ |
| 24 | + return ::launchdarkly::foxy::detail::async_timer<void(boost::system::error_code)>( |
| 25 | + [self = this, coro = boost::asio::coroutine()](auto& cb, boost::system::error_code ec = {}, |
| 26 | + std::size_t bytes_transferrred = 0) mutable { |
| 27 | + auto& s = *self; |
| 28 | + |
| 29 | + BOOST_ASIO_CORO_REENTER(coro) |
| 30 | + { |
| 31 | + if (s.stream.is_ssl()) { |
| 32 | + BOOST_ASIO_CORO_YIELD s.stream.ssl().async_shutdown(std::move(cb)); |
| 33 | + if (ec == boost::asio::ssl::error::stream_truncated) { ec = {}; } |
| 34 | + if (ec) { goto upcall; } |
| 35 | + } |
| 36 | + |
| 37 | + s.stream.plain().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); |
| 38 | + s.stream.plain().close(ec); |
| 39 | + |
| 40 | + upcall: |
| 41 | + return cb.complete(ec); |
| 42 | + } |
| 43 | + }, |
| 44 | + *this, std::forward<ShutdownHandler>(handler)); |
57 | 45 | }
|
58 | 46 |
|
59 |
| -} // namespace launchdarkly::foxy |
| 47 | +} // namespace launchdarkly::foxy |
60 | 48 |
|
61 |
| -#endif // FOXY_IMPL_CLIENT_SESSION_ASYNC_SHUTDOWN_IMPL_HPP_ |
| 49 | +#endif // FOXY_IMPL_CLIENT_SESSION_ASYNC_SHUTDOWN_IMPL_HPP_ |
0 commit comments