mqtt_cpp
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
type_erased_socket.hpp
Go to the documentation of this file.
1 // Copyright Takatoshi Kondo 2019
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(MQTT_TYPE_ERASED_SOCKET_HPP)
8 #define MQTT_TYPE_ERASED_SOCKET_HPP
9 
10 #include <cstdlib>
11 
12 #include <boost/asio.hpp>
13 
14 #include <mqtt/namespace.hpp>
15 #include <mqtt/error_code.hpp>
16 #include <mqtt/any.hpp>
17 
18 namespace MQTT_NS {
19 
20 namespace as = boost::asio;
21 
22 class socket {
23 public:
24  virtual ~socket() = default;
25  virtual void async_read(as::mutable_buffer, std::function<void(error_code, std::size_t)>) = 0;
26  virtual void async_write(std::vector<as::const_buffer>, std::function<void(error_code, std::size_t)>) = 0;
27  virtual std::size_t write(std::vector<as::const_buffer>, boost::system::error_code&) = 0;
28  virtual void post(std::function<void()>) = 0;
29  virtual as::ip::tcp::socket::lowest_layer_type& lowest_layer() = 0;
30  virtual any native_handle() = 0;
31  virtual void close(boost::system::error_code&) = 0;
32 #if BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
33  virtual as::executor get_executor() = 0;
34 #else // BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
35  virtual as::any_io_executor get_executor() = 0;
36 #endif // BOOST_VERSION < 107400 || defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
37 };
38 
39 } // namespace MQTT_NS
40 
41 #endif // MQTT_TYPE_ERASED_SOCKET_HPP
Definition: type_erased_socket.hpp:22
virtual any native_handle()=0
virtual as::ip::tcp::socket::lowest_layer_type & lowest_layer()=0
virtual void post(std::function< void()>)=0
virtual std::size_t write(std::vector< as::const_buffer >, boost::system::error_code &)=0
virtual void async_write(std::vector< as::const_buffer >, std::function< void(error_code, std::size_t)>)=0
virtual ~socket()=default
virtual void close(boost::system::error_code &)=0
virtual as::executor get_executor()=0
virtual void async_read(as::mutable_buffer, std::function< void(error_code, std::size_t)>)=0
Definition: any.hpp:27
boost::system::error_code error_code
Definition: error_code.hpp:16
Definition: buffer.hpp:242