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 % 18 18
Test Date: 2026-09-09 02:31:18 Functions: 72.7 % 44 32 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       14128 :     explicit reactor_stream_socket_impl(Service& svc) noexcept
      78           14128 :         : reactor_stream_socket_impl::reactor_stream_socket(svc)
      79                 :     {
      80           14128 :     }
      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           14128 :     ~reactor_stream_socket_impl() override = default;
      89                 : 
      90             298 :     std::error_code set_option(
      91                 :         int level,
      92                 :         int optname,
      93                 :         void const* data,
      94                 :         std::size_t size) noexcept override
      95                 :     {
      96             298 :         return hook_.on_set_option(this->fd_, level, optname, data, size);
      97                 :     }
      98                 : 
      99                 :     // Shadows reactor_stream_socket::close_socket so the hook fires on
     100                 :     // every fd close path.
     101           42392 :     void close_socket() noexcept
     102                 :     {
     103           42392 :         hook_.pre_shutdown(this->fd_);
     104           42392 :         this->do_close_socket();
     105           42392 :     }
     106                 : };
     107                 : 
     108                 : // ============================================================
     109                 : // Datagram socket implementation base
     110                 : // ============================================================
     111                 : 
     112                 : /** Intermediate base for reactor datagram sockets.
     113                 : 
     114                 :     @tparam Derived      The named final class (CRTP self).
     115                 :     @tparam Traits       Backend traits.
     116                 :     @tparam Service      The concrete datagram service type.
     117                 :     @tparam AcceptorType The concrete acceptor type (placeholder for op base).
     118                 :     @tparam ImplBase     The public vtable base.
     119                 :     @tparam Endpoint     endpoint or local_endpoint.
     120                 : */
     121                 : template<
     122                 :     class Derived,
     123                 :     class Traits,
     124                 :     class Service,
     125                 :     class AcceptorType,
     126                 :     class ImplBase,
     127                 :     class Endpoint>
     128                 : class reactor_dgram_socket_impl
     129                 :     : public reactor_datagram_socket<
     130                 :           Derived,
     131                 :           Service,
     132                 :           reactor_dgram_connect_op<Traits, Derived, AcceptorType, Endpoint>,
     133                 :           reactor_dgram_send_to_op<Traits, Derived, AcceptorType, Endpoint>,
     134                 :           reactor_dgram_recv_from_op<Traits, Derived, AcceptorType, Endpoint>,
     135                 :           reactor_dgram_send_op<Traits, Derived, AcceptorType, Endpoint>,
     136                 :           reactor_dgram_recv_op<Traits, Derived, AcceptorType, Endpoint>,
     137                 :           reactor_dgram_wait_op<Traits, Derived, AcceptorType, Endpoint>,
     138                 :           typename Traits::desc_state_type,
     139                 :           ImplBase,
     140                 :           Endpoint>
     141                 : {
     142                 :     friend Derived;
     143                 :     friend Service;
     144                 : 
     145             618 :     explicit reactor_dgram_socket_impl(Service& svc) noexcept
     146             618 :         : reactor_dgram_socket_impl::reactor_datagram_socket(svc)
     147                 :     {
     148             618 :     }
     149                 : 
     150                 : public:
     151                 :     using impl_base_type = ImplBase;
     152                 : 
     153             618 :     ~reactor_dgram_socket_impl() override = default;
     154                 : };
     155                 : 
     156                 : // ============================================================
     157                 : // Acceptor implementation base
     158                 : // ============================================================
     159                 : 
     160                 : /** Intermediate base for reactor stream acceptors.
     161                 : 
     162                 :     @tparam Derived      The named final class (CRTP self).
     163                 :     @tparam Traits       Backend traits.
     164                 :     @tparam Service      The concrete acceptor service type.
     165                 :     @tparam SocketFinal  The concrete stream socket type (for accept).
     166                 :     @tparam AccImplBase  The public vtable base.
     167                 :     @tparam Endpoint     endpoint or local_endpoint.
     168                 : */
     169                 : template<
     170                 :     class Derived,
     171                 :     class Traits,
     172                 :     class Service,
     173                 :     class SocketFinal,
     174                 :     class AccImplBase,
     175                 :     class Endpoint>
     176                 : class reactor_acceptor_impl
     177                 :     : public reactor_acceptor<
     178                 :           Derived,
     179                 :           Service,
     180                 :           reactor_stream_base_op<Traits, SocketFinal, Derived, Endpoint>,
     181                 :           reactor_stream_accept_op<Traits, SocketFinal, Derived, Endpoint>,
     182                 :           reactor_stream_wait_op<Traits, SocketFinal, Derived, Endpoint>,
     183                 :           typename Traits::desc_state_type,
     184                 :           AccImplBase,
     185                 :           Endpoint>
     186                 : {
     187                 :     friend Derived;
     188                 :     friend Service;
     189                 : 
     190             760 :     explicit reactor_acceptor_impl(Service& svc) noexcept
     191             760 :         : reactor_acceptor_impl::reactor_acceptor(svc)
     192                 :     {
     193             760 :     }
     194                 : 
     195                 : public:
     196                 :     using impl_base_type = AccImplBase;
     197                 : 
     198             760 :     ~reactor_acceptor_impl() override = default;
     199                 : 
     200                 :     std::coroutine_handle<> accept(
     201                 :         std::coroutine_handle<>,
     202                 :         capy::executor_ref,
     203                 :         std::stop_token,
     204                 :         std::error_code*,
     205                 :         io_object::implementation**) override;
     206                 : };
     207                 : 
     208                 : } // namespace boost::corosio::detail
     209                 : 
     210                 : #endif // BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_SOCKET_FINALS_HPP
        

Generated by: LCOV version 2.3