Open C++ Libraries.org develop
Loading...
Searching...
No Matches
asio_fwd.hpp
1// SPDX-License-Identifier: BSL-1.0
2// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org)
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5// Official repository: https://github.com/open-cpp-libraries/core
6
7#ifndef OCL_CORE_ASIO
8#define OCL_CORE_ASIO
9
10#ifdef OCL_CORE_INCLUDE_ALL_ASIO
11
12#include <boost/asio_fwd.hpp>
13
14#else
15
16#include <boost/asio/strand.hpp>
17#include <boost/asio/co_spawn.hpp>
18#include <boost/asio/detached.hpp>
19#include <boost/asio/io_context.hpp>
20#include <boost/asio/write.hpp>
21#include <boost/asio/read.hpp>
22#include <ocl/print_fwd.hpp>
23
24#endif
25
27
28namespace ocl::asio
29{
30
31 using io_context_type = boost::asio::io_context;
32
33 using run_pred_type = void (*)();
34
35 template <class IOCPred>
36 inline void run(io_context_type& ioc)
37 {
38 try
39 {
40 ioc.run();
41 }
42 catch (const std::exception& e)
43 {
44 IOCPred{}();
45 ocl::io::println(e.what());
46 }
47 }
48
49 template <run_pred_type IOCFn>
50 inline void run(io_context_type& ioc)
51 {
52 try
53 {
54 ioc.run();
55 }
56 catch (const std::exception& e)
57 {
58 IOCFn();
59 ocl::io::println(e.what());
60 }
61 }
62
63} // namespace ocl::asio
64
65#endif
ASIO file for OCL support.
Definition asio_fwd.hpp:29