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-04-17 20:21:04 Functions: 68.2 % 44 30 14

           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<class Derived, class Traits, class Service,
      56                 :          class AcceptorType, class ImplBase, class Endpoint>
      57                 : class reactor_stream_socket_impl
      58                 :     : public reactor_stream_socket<
      59                 :           Derived,
      60                 :           Service,
      61                 :           reactor_stream_connect_op<Traits, Derived, AcceptorType, Endpoint>,
      62                 :           reactor_stream_read_op<Traits, Derived, AcceptorType, Endpoint>,
      63                 :           reactor_stream_write_op<Traits, Derived, AcceptorType, Endpoint>,
      64                 :           typename Traits::desc_state_type,
      65                 :           ImplBase,
      66                 :           Endpoint>
      67                 : {
      68                 :     friend Derived;
      69                 :     friend Service;
      70                 : 
      71 HIT       24777 :     explicit reactor_stream_socket_impl(Service& svc) noexcept
      72           24777 :         : reactor_stream_socket_impl::reactor_stream_socket(svc)
      73                 :     {
      74           24777 :     }
      75                 : 
      76                 : public:
      77                 :     using impl_base_type = ImplBase;
      78                 : 
      79                 :     // Per-socket hook state (e.g., kqueue SO_LINGER tracking).
      80                 :     [[no_unique_address]] typename Traits::stream_socket_hook hook_;
      81                 : 
      82           24777 :     ~reactor_stream_socket_impl() override = default;
      83                 : 
      84              60 :     std::error_code set_option(
      85                 :         int level, int optname,
      86                 :         void const* data, std::size_t size) noexcept override
      87                 :     {
      88              60 :         return hook_.on_set_option(this->fd_, level, optname, data, size);
      89                 :     }
      90                 : 
      91                 :     // Shadows reactor_stream_socket::close_socket so the hook fires on
      92                 :     // every fd close path.
      93           74334 :     void close_socket() noexcept
      94                 :     {
      95           74334 :         hook_.pre_shutdown(this->fd_);
      96           74334 :         this->do_close_socket();
      97           74334 :     }
      98                 : };
      99                 : 
     100                 : // ============================================================
     101                 : // Datagram socket implementation base
     102                 : // ============================================================
     103                 : 
     104                 : /** Intermediate base for reactor datagram sockets.
     105                 : 
     106                 :     @tparam Derived      The named final class (CRTP self).
     107                 :     @tparam Traits       Backend traits.
     108                 :     @tparam Service      The concrete datagram service type.
     109                 :     @tparam AcceptorType The concrete acceptor type (placeholder for op base).
     110                 :     @tparam ImplBase     The public vtable base.
     111                 :     @tparam Endpoint     endpoint or local_endpoint.
     112                 : */
     113                 : template<class Derived, class Traits, class Service,
     114                 :          class AcceptorType, class ImplBase, class Endpoint>
     115                 : class reactor_dgram_socket_impl
     116                 :     : public reactor_datagram_socket<
     117                 :           Derived,
     118                 :           Service,
     119                 :           reactor_dgram_connect_op<Traits, Derived, AcceptorType, Endpoint>,
     120                 :           reactor_dgram_send_to_op<Traits, Derived, AcceptorType, Endpoint>,
     121                 :           reactor_dgram_recv_from_op<Traits, Derived, AcceptorType, Endpoint>,
     122                 :           reactor_dgram_send_op<Traits, Derived, AcceptorType, Endpoint>,
     123                 :           reactor_dgram_recv_op<Traits, Derived, AcceptorType, Endpoint>,
     124                 :           typename Traits::desc_state_type,
     125                 :           ImplBase,
     126                 :           Endpoint>
     127                 : {
     128                 :     friend Derived;
     129                 :     friend Service;
     130                 : 
     131             120 :     explicit reactor_dgram_socket_impl(Service& svc) noexcept
     132             120 :         : reactor_dgram_socket_impl::reactor_datagram_socket(svc)
     133                 :     {
     134             120 :     }
     135                 : 
     136                 : public:
     137                 :     using impl_base_type = ImplBase;
     138                 : 
     139             120 :     ~reactor_dgram_socket_impl() override = default;
     140                 : };
     141                 : 
     142                 : // ============================================================
     143                 : // Acceptor implementation base
     144                 : // ============================================================
     145                 : 
     146                 : /** Intermediate base for reactor stream acceptors.
     147                 : 
     148                 :     @tparam Derived      The named final class (CRTP self).
     149                 :     @tparam Traits       Backend traits.
     150                 :     @tparam Service      The concrete acceptor service type.
     151                 :     @tparam SocketFinal  The concrete stream socket type (for accept).
     152                 :     @tparam AccImplBase  The public vtable base.
     153                 :     @tparam Endpoint     endpoint or local_endpoint.
     154                 : */
     155                 : template<class Derived, class Traits, class Service,
     156                 :          class SocketFinal, class AccImplBase, class Endpoint>
     157                 : class reactor_acceptor_impl
     158                 :     : public reactor_acceptor<
     159                 :           Derived,
     160                 :           Service,
     161                 :           reactor_stream_base_op<Traits, SocketFinal, Derived, Endpoint>,
     162                 :           reactor_stream_accept_op<Traits, SocketFinal, Derived, Endpoint>,
     163                 :           typename Traits::desc_state_type,
     164                 :           AccImplBase,
     165                 :           Endpoint>
     166                 : {
     167                 :     friend Derived;
     168                 :     friend Service;
     169                 : 
     170             161 :     explicit reactor_acceptor_impl(Service& svc) noexcept
     171             161 :         : reactor_acceptor_impl::reactor_acceptor(svc)
     172                 :     {
     173             161 :     }
     174                 : 
     175                 : public:
     176                 :     using impl_base_type = AccImplBase;
     177                 : 
     178             161 :     ~reactor_acceptor_impl() override = default;
     179                 : 
     180                 :     std::coroutine_handle<> accept(
     181                 :         std::coroutine_handle<>,
     182                 :         capy::executor_ref,
     183                 :         std::stop_token,
     184                 :         std::error_code*,
     185                 :         io_object::implementation**) override;
     186                 : };
     187                 : 
     188                 : } // namespace boost::corosio::detail
     189                 : 
     190                 : #endif // BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_SOCKET_FINALS_HPP
        

Generated by: LCOV version 2.3