async_mqtt 9.0.1
Loading...
Searching...
No Matches
customized_basic_stream.hpp
1// Copyright Takatoshi Kondo 2024
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#if !defined(ASYNC_MQTT_PREDEFINED_LAYER_CUSTOMIZED_BASIC_STREAM_HPP)
8#define ASYNC_MQTT_PREDEFINED_LAYER_CUSTOMIZED_BASIC_STREAM_HPP
9
10#include <boost/asio.hpp>
11
12#include <async_mqtt/util/stream_traits.hpp>
13#include <async_mqtt/util/log.hpp>
14
15namespace async_mqtt {
16
17namespace as = boost::asio;
18
33template <typename Protocol, typename Executor>
34struct layer_customize<as::basic_stream_socket<Protocol, Executor>> {
35 template <
36 typename CompletionToken
37 >
38 static auto
39 async_close(
40 as::basic_stream_socket<Protocol, Executor>& stream,
41 CompletionToken&& token
42 ) {
43 return as::async_compose<
44 CompletionToken,
45 void(error_code const& ec)
46 > (
47 [&stream](auto& self) {
48 error_code ec;
49 if (stream.is_open()) {
50 ASYNC_MQTT_LOG("mqtt_impl", info)
51 << "TCP close";
52 stream.close(ec);
53 }
54 else {
55 ASYNC_MQTT_LOG("mqtt_impl", info)
56 << "TCP already closed";
57 }
58 self.complete(ec);
59 },
60 token,
61 stream
62 );
63 }
64};
65
66} // namespace async_mqtt
67
68#endif // ASYNC_MQTT_PREDEFINED_LAYER_CUSTOMIZED_BASIC_STREAM_HPP
sys::error_code error_code
sys is a namespace alias of boost::sytem.
Definition error.hpp:56
@ info
info level api call is output
customization class template for underlying layer In order to adapt your layer to async_mqtt,...
Definition stream_traits.hpp:101