shutdown.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // Copyright (c) 2025 Ivica Siladic, Bruno Iljazovic, Korina Simicevic
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MQTT5_SHUTDOWN_HPP
  8. #define BOOST_MQTT5_SHUTDOWN_HPP
  9. #include <boost/asio/basic_stream_socket.hpp>
  10. namespace boost::mqtt5::detail {
  11. template <typename Stream, typename ShutdownHandler>
  12. void async_shutdown(Stream& /* stream */, ShutdownHandler&& /* handler */) {
  13. /*
  14. If you are trying to use beast::websocket::stream and/or OpenSSL
  15. and this goes off, you need to add an include for one of these
  16. * <boost/mqtt5/websocket.hpp>
  17. * <boost/mqtt5/ssl.hpp>
  18. * <boost/mqtt5/websocket_ssl.hpp>
  19. If you are trying to use mqtt_client with user-defined stream type, you must
  20. provide an overload of async_shutdown that is discoverable via
  21. argument-dependent lookup (ADL).
  22. */
  23. static_assert(sizeof(Stream) == -1,
  24. "Unknown Stream type in async_shutdown.");
  25. }
  26. template <typename P, typename E, typename ShutdownHandler>
  27. void async_shutdown(
  28. asio::basic_stream_socket<P, E>& socket, ShutdownHandler&& handler
  29. ) {
  30. boost::system::error_code ec;
  31. socket.shutdown(asio::socket_base::shutdown_both, ec);
  32. return std::move(handler)(ec);
  33. }
  34. } // end namespace boost::mqtt5::detail
  35. #endif // !BOOST_MQTT5_SHUTDOWN_HPP