100.00% Lines (2/2) 100.00% Functions (2/2)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2026 Steve Gerbino 2   // Copyright (c) 2026 Steve Gerbino
3   // 3   //
4   // Distributed under the Boost Software License, Version 1.0. (See accompanying 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) 5   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6   // 6   //
7   // Official repository: https://github.com/cppalliance/corosio 7   // Official repository: https://github.com/cppalliance/corosio
8   // 8   //
9   9  
10   #ifndef BOOST_COROSIO_DETAIL_TCP_SERVICE_HPP 10   #ifndef BOOST_COROSIO_DETAIL_TCP_SERVICE_HPP
11   #define BOOST_COROSIO_DETAIL_TCP_SERVICE_HPP 11   #define BOOST_COROSIO_DETAIL_TCP_SERVICE_HPP
12   12  
13   #include <boost/corosio/detail/config.hpp> 13   #include <boost/corosio/detail/config.hpp>
14   #include <boost/corosio/tcp_socket.hpp> 14   #include <boost/corosio/tcp_socket.hpp>
15   #include <boost/capy/ex/execution_context.hpp> 15   #include <boost/capy/ex/execution_context.hpp>
16   #include <system_error> 16   #include <system_error>
17   17  
18   namespace boost::corosio::detail { 18   namespace boost::corosio::detail {
19   19  
20   /** Abstract TCP service base class. 20   /** Abstract TCP service base class.
21   21  
22   Concrete implementations ( epoll, select, kqueue, etc. ) 22   Concrete implementations ( epoll, select, kqueue, etc. )
23   inherit from this class and provide platform-specific stream 23   inherit from this class and provide platform-specific stream
24   socket operations. The context constructor installs whichever 24   socket operations. The context constructor installs whichever
25   backend via `make_service`, and `tcp_socket.cpp` retrieves it 25   backend via `make_service`, and `tcp_socket.cpp` retrieves it
26   via `use_service<tcp_service>()`. 26   via `use_service<tcp_service>()`.
27   */ 27   */
28   class BOOST_COROSIO_DECL tcp_service 28   class BOOST_COROSIO_DECL tcp_service
29   : public capy::execution_context::service 29   : public capy::execution_context::service
30   , public io_object::io_service 30   , public io_object::io_service
31   { 31   {
32   public: 32   public:
33   /// Identifies this service for `execution_context` lookup. 33   /// Identifies this service for `execution_context` lookup.
34   using key_type = tcp_service; 34   using key_type = tcp_service;
35   35  
36   /** Open a socket. 36   /** Open a socket.
37   37  
38   Creates a socket and associates it with the platform reactor. 38   Creates a socket and associates it with the platform reactor.
39   39  
40   @param impl The socket implementation to open. 40   @param impl The socket implementation to open.
41   @param family Address family (e.g. `AF_INET`, `AF_INET6`). 41   @param family Address family (e.g. `AF_INET`, `AF_INET6`).
42   @param type Socket type (e.g. `SOCK_STREAM`). 42   @param type Socket type (e.g. `SOCK_STREAM`).
43   @param protocol Protocol number (e.g. `IPPROTO_TCP`). 43   @param protocol Protocol number (e.g. `IPPROTO_TCP`).
44   @return Error code on failure, empty on success. 44   @return Error code on failure, empty on success.
45   */ 45   */
46   virtual std::error_code open_socket( 46   virtual std::error_code open_socket(
47   tcp_socket::implementation& impl, 47   tcp_socket::implementation& impl,
48   int family, 48   int family,
49   int type, 49   int type,
50   int protocol) = 0; 50   int protocol) = 0;
51   51  
52   /** Assign an existing native socket handle to a socket. 52   /** Assign an existing native socket handle to a socket.
53   53  
54   Adopts a pre-created socket handle. On success the impl 54   Adopts a pre-created socket handle. On success the impl
55   takes ownership and will close the handle. On failure the 55   takes ownership and will close the handle. On failure the
56   caller retains ownership and must close it. If the impl is 56   caller retains ownership and must close it. If the impl is
57   already open, its pending operations are cancelled and the 57   already open, its pending operations are cancelled and the
58   held socket is closed before the new one is adopted. 58   held socket is closed before the new one is adopted.
59   59  
60   @param impl The socket implementation to assign to. 60   @param impl The socket implementation to assign to.
61   @param fd The native socket handle to adopt. 61   @param fd The native socket handle to adopt.
62   @return Error code on failure, empty on success. 62   @return Error code on failure, empty on success.
63   */ 63   */
64   virtual std::error_code assign_socket( 64   virtual std::error_code assign_socket(
65   tcp_socket::implementation& impl, 65   tcp_socket::implementation& impl,
66   native_handle_type fd) = 0; 66   native_handle_type fd) = 0;
67   67  
68   /** Bind a stream socket to a local endpoint. 68   /** Bind a stream socket to a local endpoint.
69   69  
70   @param impl The socket implementation to bind. 70   @param impl The socket implementation to bind.
71   @param ep The local endpoint to bind to. 71   @param ep The local endpoint to bind to.
72   @return Error code on failure, empty on success. 72   @return Error code on failure, empty on success.
73   */ 73   */
74   virtual std::error_code 74   virtual std::error_code
75   bind_socket(tcp_socket::implementation& impl, endpoint ep) = 0; 75   bind_socket(tcp_socket::implementation& impl, endpoint ep) = 0;
76   76  
77   protected: 77   protected:
78   /// Construct the TCP service. 78   /// Construct the TCP service.
HITCBC 79   1533 tcp_service() = default; 79   1603 tcp_service() = default;
80   80  
81   /// Destroy the TCP service. 81   /// Destroy the TCP service.
HITCBC 82   1533 ~tcp_service() override = default; 82   1603 ~tcp_service() override = default;
83   }; 83   };
84   84  
85   } // namespace boost::corosio::detail 85   } // namespace boost::corosio::detail
86   86  
87   #endif // BOOST_COROSIO_DETAIL_TCP_SERVICE_HPP 87   #endif // BOOST_COROSIO_DETAIL_TCP_SERVICE_HPP