src/corosio/src/io_context.cpp
100.0% Lines (26/26)
100.0% List of functions (5/5)
50.0% Branches (1/2)
Functions (5)
Function
Calls
Lines
Branches
Blocks
boost::corosio::select_t::construct(boost::capy::execution_context&, unsigned int)
:63
231x
100.0%
–
100.0%
boost::corosio::kqueue_t::construct(boost::capy::execution_context&, unsigned int)
:78
375x
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
288x
100.0%
50.0%
100.0%
boost::corosio::io_context::~io_context()
:124
1200x
100.0%
–
100.0%
| Line | Branch | 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 | epoll_t::construct(capy::execution_context& ctx, unsigned concurrency_hint) | |||
| 49 | { | |||
| 50 | auto& sched = ctx.make_service<detail::epoll_scheduler>( | |||
| 51 | static_cast<int>(concurrency_hint)); | |||
| 52 | ||||
| 53 | ctx.make_service<detail::epoll_tcp_service>(); | |||
| 54 | ctx.make_service<detail::epoll_tcp_acceptor_service>(); | |||
| 55 | ctx.make_service<detail::epoll_udp_service>(); | |||
| 56 | ||||
| 57 | return sched; | |||
| 58 | } | |||
| 59 | #endif | |||
| 60 | ||||
| 61 | #if BOOST_COROSIO_HAS_SELECT | |||
| 62 | detail::scheduler& | |||
| 63 | 231x | select_t::construct(capy::execution_context& ctx, unsigned concurrency_hint) | ||
| 64 | { | |||
| 65 | 462x | auto& sched = ctx.make_service<detail::select_scheduler>( | ||
| 66 | 231x | static_cast<int>(concurrency_hint)); | ||
| 67 | ||||
| 68 | 231x | ctx.make_service<detail::select_tcp_service>(); | ||
| 69 | 231x | ctx.make_service<detail::select_tcp_acceptor_service>(); | ||
| 70 | 231x | ctx.make_service<detail::select_udp_service>(); | ||
| 71 | ||||
| 72 | 231x | return sched; | ||
| 73 | } | |||
| 74 | #endif | |||
| 75 | ||||
| 76 | #if BOOST_COROSIO_HAS_KQUEUE | |||
| 77 | detail::scheduler& | |||
| 78 | 375x | kqueue_t::construct(capy::execution_context& ctx, unsigned concurrency_hint) | ||
| 79 | { | |||
| 80 | 750x | auto& sched = ctx.make_service<detail::kqueue_scheduler>( | ||
| 81 | 375x | static_cast<int>(concurrency_hint)); | ||
| 82 | ||||
| 83 | 375x | ctx.make_service<detail::kqueue_tcp_service>(); | ||
| 84 | 375x | ctx.make_service<detail::kqueue_tcp_acceptor_service>(); | ||
| 85 | 375x | ctx.make_service<detail::kqueue_udp_service>(); | ||
| 86 | ||||
| 87 | 375x | 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 | 288x | io_context::io_context(unsigned concurrency_hint) | ||
| 110 | 144x | : capy::execution_context(this) | ||
| 111 | 144x | , sched_(nullptr) | ||
| 112 | 144x | { | ||
| 113 | #if BOOST_COROSIO_HAS_IOCP | |||
| 114 | sched_ = &iocp_t::construct(*this, concurrency_hint); | |||
| 115 | #elif BOOST_COROSIO_HAS_EPOLL | |||
| 116 | sched_ = &epoll_t::construct(*this, concurrency_hint); | |||
| 117 | #elif BOOST_COROSIO_HAS_KQUEUE | |||
| 118 |
1/2✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144x | sched_ = &kqueue_t::construct(*this, concurrency_hint); | |
| 119 | #elif BOOST_COROSIO_HAS_SELECT | |||
| 120 | sched_ = &select_t::construct(*this, concurrency_hint); | |||
| 121 | #endif | |||
| 122 | 288x | } | ||
| 123 | ||||
| 124 | 1200x | io_context::~io_context() | ||
| 125 | 594x | { | ||
| 126 | 606x | shutdown(); | ||
| 127 | 606x | destroy(); | ||
| 128 | 1200x | } | ||
| 129 | ||||
| 130 | } // namespace boost::corosio | |||
| 131 |