src/corosio/src/io_context.cpp
100.0% Lines (23/23)
100.0% List of functions (5/5)
Functions (5)
Function
Calls
Lines
Blocks
boost::corosio::epoll_t::construct(boost::capy::execution_context&, unsigned int)
:48
339x
100.0%
100.0%
boost::corosio::select_t::construct(boost::capy::execution_context&, unsigned int)
:63
195x
100.0%
100.0%
boost::corosio::io_context::io_context()
:107
143x
100.0%
100.0%
boost::corosio::io_context::io_context(unsigned int)
:109
144x
100.0%
80.0%
boost::corosio::io_context::~io_context()
:124
534x
100.0%
100.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2026 Steve Gerbino | ||
| 3 | // Copyright (c) 2026 Michael Vandeberg | ||
| 4 | // | ||
| 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) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/cppalliance/corosio | ||
| 9 | // | ||
| 10 | |||
| 11 | #include <boost/corosio/io_context.hpp> | ||
| 12 | #include <boost/corosio/backend.hpp> | ||
| 13 | |||
| 14 | #include <thread> | ||
| 15 | |||
| 16 | #if BOOST_COROSIO_HAS_EPOLL | ||
| 17 | #include <boost/corosio/native/detail/epoll/epoll_scheduler.hpp> | ||
| 18 | #include <boost/corosio/native/detail/epoll/epoll_tcp_service.hpp> | ||
| 19 | #include <boost/corosio/native/detail/epoll/epoll_tcp_acceptor_service.hpp> | ||
| 20 | #include <boost/corosio/native/detail/epoll/epoll_udp_service.hpp> | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #if BOOST_COROSIO_HAS_SELECT | ||
| 24 | #include <boost/corosio/native/detail/select/select_scheduler.hpp> | ||
| 25 | #include <boost/corosio/native/detail/select/select_tcp_service.hpp> | ||
| 26 | #include <boost/corosio/native/detail/select/select_tcp_acceptor_service.hpp> | ||
| 27 | #include <boost/corosio/native/detail/select/select_udp_service.hpp> | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #if BOOST_COROSIO_HAS_KQUEUE | ||
| 31 | #include <boost/corosio/native/detail/kqueue/kqueue_scheduler.hpp> | ||
| 32 | #include <boost/corosio/native/detail/kqueue/kqueue_tcp_service.hpp> | ||
| 33 | #include <boost/corosio/native/detail/kqueue/kqueue_tcp_acceptor_service.hpp> | ||
| 34 | #include <boost/corosio/native/detail/kqueue/kqueue_udp_service.hpp> | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #if BOOST_COROSIO_HAS_IOCP | ||
| 38 | #include <boost/corosio/native/detail/iocp/win_scheduler.hpp> | ||
| 39 | #include <boost/corosio/native/detail/iocp/win_tcp_acceptor_service.hpp> | ||
| 40 | #include <boost/corosio/native/detail/iocp/win_udp_service.hpp> | ||
| 41 | #include <boost/corosio/native/detail/iocp/win_signals.hpp> | ||
| 42 | #endif | ||
| 43 | |||
| 44 | namespace boost::corosio { | ||
| 45 | |||
| 46 | #if BOOST_COROSIO_HAS_EPOLL | ||
| 47 | detail::scheduler& | ||
| 48 | 339x | epoll_t::construct(capy::execution_context& ctx, unsigned concurrency_hint) | |
| 49 | { | ||
| 50 | 678x | auto& sched = ctx.make_service<detail::epoll_scheduler>( | |
| 51 | 339x | static_cast<int>(concurrency_hint)); | |
| 52 | |||
| 53 | 339x | ctx.make_service<detail::epoll_tcp_service>(); | |
| 54 | 339x | ctx.make_service<detail::epoll_tcp_acceptor_service>(); | |
| 55 | 339x | ctx.make_service<detail::epoll_udp_service>(); | |
| 56 | |||
| 57 | 339x | return sched; | |
| 58 | } | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #if BOOST_COROSIO_HAS_SELECT | ||
| 62 | detail::scheduler& | ||
| 63 | 195x | select_t::construct(capy::execution_context& ctx, unsigned concurrency_hint) | |
| 64 | { | ||
| 65 | 390x | auto& sched = ctx.make_service<detail::select_scheduler>( | |
| 66 | 195x | static_cast<int>(concurrency_hint)); | |
| 67 | |||
| 68 | 195x | ctx.make_service<detail::select_tcp_service>(); | |
| 69 | 195x | ctx.make_service<detail::select_tcp_acceptor_service>(); | |
| 70 | 195x | ctx.make_service<detail::select_udp_service>(); | |
| 71 | |||
| 72 | 195x | return sched; | |
| 73 | } | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #if BOOST_COROSIO_HAS_KQUEUE | ||
| 77 | detail::scheduler& | ||
| 78 | kqueue_t::construct(capy::execution_context& ctx, unsigned concurrency_hint) | ||
| 79 | { | ||
| 80 | auto& sched = ctx.make_service<detail::kqueue_scheduler>( | ||
| 81 | static_cast<int>(concurrency_hint)); | ||
| 82 | |||
| 83 | ctx.make_service<detail::kqueue_tcp_service>(); | ||
| 84 | ctx.make_service<detail::kqueue_tcp_acceptor_service>(); | ||
| 85 | ctx.make_service<detail::kqueue_udp_service>(); | ||
| 86 | |||
| 87 | return sched; | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #if BOOST_COROSIO_HAS_IOCP | ||
| 92 | detail::scheduler& | ||
| 93 | iocp_t::construct(capy::execution_context& ctx, unsigned concurrency_hint) | ||
| 94 | { | ||
| 95 | auto& sched = ctx.make_service<detail::win_scheduler>( | ||
| 96 | static_cast<int>(concurrency_hint)); | ||
| 97 | |||
| 98 | auto& sockets = ctx.make_service<detail::win_tcp_service>(); | ||
| 99 | ctx.make_service<detail::win_tcp_acceptor_service>(sockets); | ||
| 100 | ctx.make_service<detail::win_udp_service>(); | ||
| 101 | ctx.make_service<detail::win_signals>(); | ||
| 102 | |||
| 103 | return sched; | ||
| 104 | } | ||
| 105 | #endif | ||
| 106 | |||
| 107 | 143x | io_context::io_context() : io_context(std::thread::hardware_concurrency()) {} | |
| 108 | |||
| 109 | 144x | io_context::io_context(unsigned concurrency_hint) | |
| 110 | : capy::execution_context(this) | ||
| 111 | 144x | , sched_(nullptr) | |
| 112 | { | ||
| 113 | #if BOOST_COROSIO_HAS_IOCP | ||
| 114 | sched_ = &iocp_t::construct(*this, concurrency_hint); | ||
| 115 | #elif BOOST_COROSIO_HAS_EPOLL | ||
| 116 | 144x | sched_ = &epoll_t::construct(*this, concurrency_hint); | |
| 117 | #elif BOOST_COROSIO_HAS_KQUEUE | ||
| 118 | sched_ = &kqueue_t::construct(*this, concurrency_hint); | ||
| 119 | #elif BOOST_COROSIO_HAS_SELECT | ||
| 120 | sched_ = &select_t::construct(*this, concurrency_hint); | ||
| 121 | #endif | ||
| 122 | 144x | } | |
| 123 | |||
| 124 | 534x | io_context::~io_context() | |
| 125 | { | ||
| 126 | 534x | shutdown(); | |
| 127 | 534x | destroy(); | |
| 128 | 534x | } | |
| 129 | |||
| 130 | } // namespace boost::corosio | ||
| 131 |