include/boost/corosio/detail/descriptor_service.hpp

100.0% Lines (2 / 2) 100.0% Functions (2 / 2)
descriptor_service.hpp
f(x) Functions (2)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2026 Michael Vandeberg
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/corosio
8 //
9
10 #ifndef BOOST_COROSIO_DETAIL_DESCRIPTOR_SERVICE_HPP
11 #define BOOST_COROSIO_DETAIL_DESCRIPTOR_SERVICE_HPP
12
13 #include <boost/corosio/detail/config.hpp>
14 #include <boost/corosio/detail/platform.hpp>
15
16 #if BOOST_COROSIO_POSIX
17
18 #include <boost/corosio/posix_descriptor.hpp>
19 #include <boost/capy/ex/execution_context.hpp>
20
21 #include <system_error>
22
23 namespace boost::corosio::detail {
24
25 /* Abstract descriptor service base class.
26
27 Concrete implementations (epoll, select, kqueue, uring) inherit
28 from this class. The three reactor backends register the adopted
29 fd with their reactor; uring has no adopt-time registration and
30 only takes ownership of it.
31 The context constructor installs whichever backend via
32 make_service, and posix_descriptor.cpp retrieves it via
33 create_handle<descriptor_service>().
34 */
35 class BOOST_COROSIO_DECL descriptor_service
36 : public capy::execution_context::service
37 , public io_object::io_service
38 {
39 public:
40 /// Identifies this service for execution_context lookup.
41 using key_type = descriptor_service;
42
43 /** Adopt an existing native descriptor.
44
45 Validates before mutating: on failure the implementation
46 keeps its previous descriptor and pending operations, and
47 the caller retains ownership of @a fd. On success the
48 implementation takes ownership and will close it.
49
50 @param impl The descriptor implementation to assign to.
51 @param fd The native descriptor to adopt.
52 @return Error code on failure, empty on success.
53 */
54 virtual std::error_code assign_descriptor(
55 posix_descriptor::implementation& impl, native_handle_type fd) = 0;
56
57 protected:
58 57x descriptor_service() = default;
59 57x ~descriptor_service() override = default;
60 };
61
62 } // namespace boost::corosio::detail
63
64 #endif // BOOST_COROSIO_POSIX
65
66 #endif
67