LCOV - code coverage report
Current view: top level - corosio/native/detail/reactor - reactor_socket_finals.hpp (source / functions) Coverage Total Hit Missed
Test: coverage_remapped.info Lines: 100.0 % 30 30
Test Date: 2026-10-08 18:13:32 Functions: 78.6 % 56 44 12

           TLA  Line data    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_NATIVE_DETAIL_REACTOR_REACTOR_SOCKET_FINALS_HPP
      11                 : #define BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_SOCKET_FINALS_HPP
      12                 : 
      13                 : /* Parameterized socket, datagram, and acceptor implementation bases.
      14                 : 
      15                 :    Named per-backend classes (e.g. epoll_tcp_socket) inherit from
      16                 :    these templates, supplying the concrete service/peer types. The
      17                 :    per-backend type files ({backend}_types.hpp) define the final classes.
      18                 : */
      19                 : 
      20                 : #include <boost/corosio/tcp_socket.hpp>
      21                 : #include <boost/corosio/udp_socket.hpp>
      22                 : #include <boost/corosio/local_stream_socket.hpp>
      23                 : #include <boost/corosio/local_datagram_socket.hpp>
      24                 : #include <boost/corosio/tcp_acceptor.hpp>
      25                 : #include <boost/corosio/local_stream_acceptor.hpp>
      26                 : #include <boost/corosio/shutdown_type.hpp>
      27                 : 
      28                 : #include <boost/corosio/native/detail/reactor/reactor_stream_socket.hpp>
      29                 : #include <boost/corosio/native/detail/reactor/reactor_datagram_socket.hpp>
      30                 : #include <boost/corosio/native/detail/reactor/reactor_acceptor.hpp>
      31                 : #include <boost/corosio/native/detail/reactor/reactor_stream_ops.hpp>
      32                 : #include <boost/corosio/native/detail/reactor/reactor_datagram_ops.hpp>
      33                 : 
      34                 : #include <boost/corosio/native/detail/make_err.hpp>
      35                 : 
      36                 : namespace boost::corosio::detail {
      37                 : 
      38                 : // ============================================================
      39                 : // Stream socket implementation base
      40                 : // ============================================================
      41                 : 
      42                 : /** Intermediate base for reactor stream sockets.
      43                 : 
      44                 :     Holds the per-socket hook (e.g., kqueue SO_LINGER tracking),
      45                 :     the set_option override, and the close/release shadows.
      46                 :     Named per-backend classes inherit from this as final.
      47                 : 
      48                 :     @tparam Derived      The named final class (CRTP self).
      49                 :     @tparam Traits       Backend traits (epoll_traits, etc.).
      50                 :     @tparam Service      The concrete service type.
      51                 :     @tparam AcceptorType The concrete acceptor type (for op base).
      52                 :     @tparam ImplBase     The public vtable base.
      53                 :     @tparam Endpoint     endpoint or local_endpoint.
      54                 : */
      55                 : template<
      56                 :     class Derived,
      57                 :     class Traits,
      58                 :     class Service,
      59                 :     class AcceptorType,
      60                 :     class ImplBase,
      61                 :     class Endpoint>
      62                 : class reactor_stream_socket_impl
      63                 :     : public reactor_stream_socket<
      64                 :           Derived,
      65                 :           Service,
      66                 :           reactor_stream_connect_op<Traits, Derived, AcceptorType, Endpoint>,
      67                 :           reactor_stream_read_op<Traits, Derived, AcceptorType, Endpoint>,
      68                 :           reactor_stream_write_op<Traits, Derived, AcceptorType, Endpoint>,
      69                 :           reactor_stream_wait_op<Traits, Derived, AcceptorType, Endpoint>,
      70                 :           typename Traits::desc_state_type,
      71                 :           ImplBase,
      72                 :           Endpoint>
      73                 : {
      74                 :     friend Derived;
      75                 :     friend Service;
      76                 : 
      77 HIT        2133 :     explicit reactor_stream_socket_impl(Service& svc) noexcept
      78            2133 :         : reactor_stream_socket_impl::reactor_stream_socket(svc)
      79                 :     {
      80            2133 :     }
      81                 : 
      82                 : public:
      83                 :     using impl_base_type = ImplBase;
      84                 : 
      85                 :     // Per-socket hook state (e.g., kqueue SO_LINGER tracking).
      86                 :     [[no_unique_address]] typename Traits::stream_socket_hook hook_;
      87                 : 
      88            2133 :     ~reactor_stream_socket_impl() override = default;
      89                 : 
      90                 :     /// Recycle into the owning service's pool at zero references.
      91           15272 :     void retire() noexcept override
      92                 :     {
      93                 : #if !defined(NDEBUG)
      94           15272 :         this->poison();
      95                 : #endif
      96           15272 :         this->svc_.state_->pool_.recycle(static_cast<Derived*>(this));
      97           15272 :     }
      98                 : 
      99             306 :     std::error_code set_option(
     100                 :         int level,
     101                 :         int optname,
     102                 :         void const* data,
     103                 :         std::size_t size) noexcept override
     104                 :     {
     105             306 :         return hook_.on_set_option(this->fd_, level, optname, data, size);
     106                 :     }
     107                 : 
     108                 :     // Shadows reactor_stream_socket::close_socket so the hook fires on
     109                 :     // every fd close path.
     110           45958 :     void close_socket() noexcept
     111                 :     {
     112           45958 :         hook_.pre_shutdown(this->fd_);
     113           45958 :         this->do_close_socket();
     114           45958 :     }
     115                 : };
     116                 : 
     117                 : // ============================================================
     118                 : // Datagram socket implementation base
     119                 : // ============================================================
     120                 : 
     121                 : /** Intermediate base for reactor datagram sockets.
     122                 : 
     123                 :     @tparam Derived      The named final class (CRTP self).
     124                 :     @tparam Traits       Backend traits.
     125                 :     @tparam Service      The concrete datagram service type.
     126                 :     @tparam AcceptorType The concrete acceptor type (placeholder for op base).
     127                 :     @tparam ImplBase     The public vtable base.
     128                 :     @tparam Endpoint     endpoint or local_endpoint.
     129                 : */
     130                 : template<
     131                 :     class Derived,
     132                 :     class Traits,
     133                 :     class Service,
     134                 :     class AcceptorType,
     135                 :     class ImplBase,
     136                 :     class Endpoint>
     137                 : class reactor_dgram_socket_impl
     138                 :     : public reactor_datagram_socket<
     139                 :           Derived,
     140                 :           Service,
     141                 :           reactor_dgram_connect_op<Traits, Derived, AcceptorType, Endpoint>,
     142                 :           reactor_dgram_send_to_op<Traits, Derived, AcceptorType, Endpoint>,
     143                 :           reactor_dgram_recv_from_op<Traits, Derived, AcceptorType, Endpoint>,
     144                 :           reactor_dgram_send_op<Traits, Derived, AcceptorType, Endpoint>,
     145                 :           reactor_dgram_recv_op<Traits, Derived, AcceptorType, Endpoint>,
     146                 :           reactor_dgram_wait_op<Traits, Derived, AcceptorType, Endpoint>,
     147                 :           typename Traits::desc_state_type,
     148                 :           ImplBase,
     149                 :           Endpoint>
     150                 : {
     151                 :     friend Derived;
     152                 :     friend Service;
     153                 : 
     154             632 :     explicit reactor_dgram_socket_impl(Service& svc) noexcept
     155             632 :         : reactor_dgram_socket_impl::reactor_datagram_socket(svc)
     156                 :     {
     157             632 :     }
     158                 : 
     159                 : public:
     160                 :     using impl_base_type = ImplBase;
     161                 : 
     162             632 :     ~reactor_dgram_socket_impl() override = default;
     163                 : 
     164                 :     /// Recycle into the owning service's pool at zero references.
     165             775 :     void retire() noexcept override
     166                 :     {
     167                 : #if !defined(NDEBUG)
     168             775 :         this->poison();
     169                 : #endif
     170             775 :         this->svc_.state_->pool_.recycle(static_cast<Derived*>(this));
     171             775 :     }
     172                 : };
     173                 : 
     174                 : // ============================================================
     175                 : // Acceptor implementation base
     176                 : // ============================================================
     177                 : 
     178                 : /** Intermediate base for reactor stream acceptors.
     179                 : 
     180                 :     @tparam Derived      The named final class (CRTP self).
     181                 :     @tparam Traits       Backend traits.
     182                 :     @tparam Service      The concrete acceptor service type.
     183                 :     @tparam SocketFinal  The concrete stream socket type (for accept).
     184                 :     @tparam AccImplBase  The public vtable base.
     185                 :     @tparam Endpoint     endpoint or local_endpoint.
     186                 : */
     187                 : template<
     188                 :     class Derived,
     189                 :     class Traits,
     190                 :     class Service,
     191                 :     class SocketFinal,
     192                 :     class AccImplBase,
     193                 :     class Endpoint>
     194                 : class reactor_acceptor_impl
     195                 :     : public reactor_acceptor<
     196                 :           Derived,
     197                 :           Service,
     198                 :           reactor_stream_base_op<Traits, SocketFinal, Derived, Endpoint>,
     199                 :           reactor_stream_accept_op<Traits, SocketFinal, Derived, Endpoint>,
     200                 :           reactor_stream_wait_op<Traits, SocketFinal, Derived, Endpoint>,
     201                 :           typename Traits::desc_state_type,
     202                 :           AccImplBase,
     203                 :           Endpoint>
     204                 : {
     205                 :     friend Derived;
     206                 :     friend Service;
     207                 : 
     208             780 :     explicit reactor_acceptor_impl(Service& svc) noexcept
     209             780 :         : reactor_acceptor_impl::reactor_acceptor(svc)
     210                 :     {
     211             780 :     }
     212                 : 
     213                 : public:
     214                 :     using impl_base_type = AccImplBase;
     215                 : 
     216             780 :     ~reactor_acceptor_impl() override = default;
     217                 : 
     218                 :     /// Recycle into the owning service's pool at zero references.
     219             938 :     void retire() noexcept override
     220                 :     {
     221                 : #if !defined(NDEBUG)
     222             938 :         this->poison();
     223                 : #endif
     224             938 :         this->svc_.state_->pool_.recycle(static_cast<Derived*>(this));
     225             938 :     }
     226                 : 
     227                 :     std::coroutine_handle<> accept(
     228                 :         std::coroutine_handle<>,
     229                 :         capy::executor_ref,
     230                 :         std::stop_token,
     231                 :         std::error_code*,
     232                 :         io_object::implementation**) override;
     233                 : };
     234                 : 
     235                 : } // namespace boost::corosio::detail
     236                 : 
     237                 : #endif // BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_SOCKET_FINALS_HPP
        

Generated by: LCOV version 2.3