100.00% Lines (2/2) 100.00% Functions (2/2)
TLA Baseline Branch
Line Hits Code Line Hits 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_stream_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 + posix_stream_descriptor.cpp creates the running backend's service
  32 + on first use via use_backend_service.
  33 + */
  34 + class BOOST_COROSIO_DECL descriptor_service
  35 + : public capy::execution_context::service
  36 + , public io_object::io_service
  37 + {
  38 + public:
  39 + /// Identifies this service for execution_context lookup.
  40 + using key_type = descriptor_service;
  41 +
  42 + /** Adopt an existing native descriptor.
  43 +
  44 + The implementation is closed. On failure it stays closed and
  45 + the caller retains ownership of @a fd. On success the
  46 + implementation takes ownership and will close it.
  47 +
  48 + @param impl The descriptor implementation to assign to.
  49 + @param fd The native descriptor to adopt.
  50 + @return Error code on failure, empty on success.
  51 + */
  52 + virtual std::error_code assign_descriptor(
  53 + posix_stream_descriptor::implementation& impl,
  54 + native_handle_type fd) = 0;
  55 +
  56 + protected:
HITGNC   57 + 105 descriptor_service() = default;
HITGNC   58 + 105 ~descriptor_service() override = default;
  59 + };
  60 +
  61 + } // namespace boost::corosio::detail
  62 +
  63 + #endif // BOOST_COROSIO_POSIX
  64 +
  65 + #endif