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_ACCEPTOR_SERVICE_HPP | 10 | #ifndef BOOST_COROSIO_DETAIL_TCP_ACCEPTOR_SERVICE_HPP | |||||
| 11 | #define BOOST_COROSIO_DETAIL_TCP_ACCEPTOR_SERVICE_HPP | 11 | #define BOOST_COROSIO_DETAIL_TCP_ACCEPTOR_SERVICE_HPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/corosio/detail/config.hpp> | 13 | #include <boost/corosio/detail/config.hpp> | |||||
| 14 | #include <boost/corosio/tcp_acceptor.hpp> | 14 | #include <boost/corosio/tcp_acceptor.hpp> | |||||
| 15 | #include <boost/corosio/endpoint.hpp> | 15 | #include <boost/corosio/endpoint.hpp> | |||||
| 16 | #include <boost/capy/ex/execution_context.hpp> | 16 | #include <boost/capy/ex/execution_context.hpp> | |||||
| 17 | #include <system_error> | 17 | #include <system_error> | |||||
| 18 | 18 | |||||||
| 19 | namespace boost::corosio::detail { | 19 | namespace boost::corosio::detail { | |||||
| 20 | 20 | |||||||
| 21 | /** Abstract acceptor service base class. | 21 | /** Abstract acceptor service base class. | |||||
| 22 | 22 | |||||||
| 23 | Concrete implementations ( epoll_acceptors, select_acceptors, etc. ) | 23 | Concrete implementations ( epoll_acceptors, select_acceptors, etc. ) | |||||
| 24 | inherit from this class and provide platform-specific acceptor | 24 | inherit from this class and provide platform-specific acceptor | |||||
| 25 | operations. The context constructor installs whichever backend | 25 | operations. The context constructor installs whichever backend | |||||
| 26 | via `make_service`, and `tcp_acceptor.cpp` retrieves it via | 26 | via `make_service`, and `tcp_acceptor.cpp` retrieves it via | |||||
| 27 | `use_service<tcp_acceptor_service>()`. | 27 | `use_service<tcp_acceptor_service>()`. | |||||
| 28 | */ | 28 | */ | |||||
| 29 | class BOOST_COROSIO_DECL tcp_acceptor_service | 29 | class BOOST_COROSIO_DECL tcp_acceptor_service | |||||
| 30 | : public capy::execution_context::service | 30 | : public capy::execution_context::service | |||||
| 31 | , public io_object::io_service | 31 | , public io_object::io_service | |||||
| 32 | { | 32 | { | |||||
| 33 | public: | 33 | public: | |||||
| 34 | /// Identifies this service for `execution_context` lookup. | 34 | /// Identifies this service for `execution_context` lookup. | |||||
| 35 | using key_type = tcp_acceptor_service; | 35 | using key_type = tcp_acceptor_service; | |||||
| 36 | 36 | |||||||
| 37 | /** Create the acceptor socket without binding or listening. | 37 | /** Create the acceptor socket without binding or listening. | |||||
| 38 | 38 | |||||||
| 39 | Creates a socket with dual-stack enabled for IPv6 but does | 39 | Creates a socket with dual-stack enabled for IPv6 but does | |||||
| 40 | not bind or listen. Does not set SO_REUSEADDR. | 40 | not bind or listen. Does not set SO_REUSEADDR. | |||||
| 41 | 41 | |||||||
| 42 | @param impl The acceptor implementation to open. | 42 | @param impl The acceptor implementation to open. | |||||
| 43 | @param family Address family (e.g. `AF_INET`, `AF_INET6`). | 43 | @param family Address family (e.g. `AF_INET`, `AF_INET6`). | |||||
| 44 | @param type Socket type (e.g. `SOCK_STREAM`). | 44 | @param type Socket type (e.g. `SOCK_STREAM`). | |||||
| 45 | @param protocol Protocol number (e.g. `IPPROTO_TCP`). | 45 | @param protocol Protocol number (e.g. `IPPROTO_TCP`). | |||||
| 46 | @return Error code on failure, empty on success. | 46 | @return Error code on failure, empty on success. | |||||
| 47 | */ | 47 | */ | |||||
| 48 | virtual std::error_code open_acceptor_socket( | 48 | virtual std::error_code open_acceptor_socket( | |||||
| 49 | tcp_acceptor::implementation& impl, | 49 | tcp_acceptor::implementation& impl, | |||||
| 50 | int family, | 50 | int family, | |||||
| 51 | int type, | 51 | int type, | |||||
| 52 | int protocol) = 0; | 52 | int protocol) = 0; | |||||
| 53 | 53 | |||||||
| 54 | /** Adopt an existing listening socket. | 54 | /** Adopt an existing listening socket. | |||||
| 55 | 55 | |||||||
| 56 | Validates @p fd, closes any socket the implementation already | 56 | Validates @p fd, closes any socket the implementation already | |||||
| 57 | holds, and registers the adopted descriptor with the backend. | 57 | holds, and registers the adopted descriptor with the backend. | |||||
| 58 | Listen state is not verified. | 58 | Listen state is not verified. | |||||
| 59 | 59 | |||||||
| 60 | @param impl The acceptor implementation to assign to. | 60 | @param impl The acceptor implementation to assign to. | |||||
| 61 | @param fd The native socket to adopt. Ownership transfers only | 61 | @param fd The native socket to adopt. Ownership transfers only | |||||
| 62 | on success. | 62 | on success. | |||||
| 63 | @return Error code on failure, empty on success. | 63 | @return Error code on failure, empty on success. | |||||
| 64 | */ | 64 | */ | |||||
| 65 | virtual std::error_code assign_socket( | 65 | virtual std::error_code assign_socket( | |||||
| 66 | tcp_acceptor::implementation& impl, | 66 | tcp_acceptor::implementation& impl, | |||||
| 67 | native_handle_type fd) = 0; | 67 | native_handle_type fd) = 0; | |||||
| 68 | 68 | |||||||
| 69 | /** Bind an open acceptor to a local endpoint. | 69 | /** Bind an open acceptor to a local endpoint. | |||||
| 70 | 70 | |||||||
| 71 | @param impl The acceptor implementation to bind. | 71 | @param impl The acceptor implementation to bind. | |||||
| 72 | @param ep The local endpoint to bind to. | 72 | @param ep The local endpoint to bind to. | |||||
| 73 | @return Error code on failure, empty on success. | 73 | @return Error code on failure, empty on success. | |||||
| 74 | */ | 74 | */ | |||||
| 75 | virtual std::error_code | 75 | virtual std::error_code | |||||
| 76 | bind_acceptor(tcp_acceptor::implementation& impl, endpoint ep) = 0; | 76 | bind_acceptor(tcp_acceptor::implementation& impl, endpoint ep) = 0; | |||||
| 77 | 77 | |||||||
| 78 | /** Start listening for incoming connections. | 78 | /** Start listening for incoming connections. | |||||
| 79 | 79 | |||||||
| 80 | Registers the acceptor with the platform reactor after | 80 | Registers the acceptor with the platform reactor after | |||||
| 81 | calling `::listen()`. | 81 | calling `::listen()`. | |||||
| 82 | 82 | |||||||
| 83 | @param impl The acceptor implementation to listen on. | 83 | @param impl The acceptor implementation to listen on. | |||||
| 84 | @param backlog The maximum length of the pending connection queue. | 84 | @param backlog The maximum length of the pending connection queue. | |||||
| 85 | @return Error code on failure, empty on success. | 85 | @return Error code on failure, empty on success. | |||||
| 86 | */ | 86 | */ | |||||
| 87 | virtual std::error_code | 87 | virtual std::error_code | |||||
| 88 | listen_acceptor(tcp_acceptor::implementation& impl, int backlog) = 0; | 88 | listen_acceptor(tcp_acceptor::implementation& impl, int backlog) = 0; | |||||
| 89 | 89 | |||||||
| 90 | protected: | 90 | protected: | |||||
| 91 | /// Construct the acceptor service. | 91 | /// Construct the acceptor service. | |||||
| HITCBC | 92 | 1533 | tcp_acceptor_service() = default; | 92 | 1603 | tcp_acceptor_service() = default; | ||
| 93 | 93 | |||||||
| 94 | /// Destroy the acceptor service. | 94 | /// Destroy the acceptor service. | |||||
| HITCBC | 95 | 1533 | ~tcp_acceptor_service() override = default; | 95 | 1603 | ~tcp_acceptor_service() override = default; | ||
| 96 | }; | 96 | }; | |||||
| 97 | 97 | |||||||
| 98 | } // namespace boost::corosio::detail | 98 | } // namespace boost::corosio::detail | |||||
| 99 | 99 | |||||||
| 100 | #endif // BOOST_COROSIO_DETAIL_TCP_ACCEPTOR_SERVICE_HPP | 100 | #endif // BOOST_COROSIO_DETAIL_TCP_ACCEPTOR_SERVICE_HPP | |||||