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_DETAIL_LOCAL_STREAM_ACCEPTOR_SERVICE_HPP
11 : #define BOOST_COROSIO_DETAIL_LOCAL_STREAM_ACCEPTOR_SERVICE_HPP
12 :
13 : #include <boost/corosio/detail/config.hpp>
14 : #include <boost/corosio/local_stream_acceptor.hpp>
15 : #include <boost/corosio/local_endpoint.hpp>
16 : #include <boost/capy/ex/execution_context.hpp>
17 : #include <system_error>
18 :
19 : namespace boost::corosio::detail {
20 :
21 : /** Abstract local stream acceptor service base class.
22 :
23 : Concrete implementations (epoll, select, kqueue, IOCP)
24 : inherit from this class and provide platform-specific
25 : acceptor operations for local (Unix domain) sockets.
26 :
27 : Instances are looked up via key_type in the
28 : execution_context. The backend's construct() function
29 : installs the appropriate derived service.
30 :
31 : All errors are reported via the returned std::error_code;
32 : these methods do not throw.
33 : */
34 : class BOOST_COROSIO_DECL local_stream_acceptor_service
35 : : public capy::execution_context::service
36 : , public io_object::io_service
37 : {
38 : public:
39 : /// Identifies this service for execution_context lookup.
40 : using key_type = local_stream_acceptor_service;
41 :
42 : /** Create the acceptor socket.
43 :
44 : @param impl The acceptor implementation to open.
45 : Must not already represent an open socket.
46 : @param family Address family for local IPC.
47 : @param type Socket type for stream sockets.
48 : @param protocol Protocol number (typically 0).
49 : @return Error code on failure, empty on success.
50 : */
51 : virtual std::error_code open_acceptor_socket(
52 : local_stream_acceptor::implementation& impl,
53 : int family,
54 : int type,
55 : int protocol) = 0;
56 :
57 : /** Adopt an existing listening socket.
58 :
59 : Validates @p fd, closes any socket the implementation already
60 : holds, and registers the adopted descriptor with the backend.
61 : Listen state is not verified.
62 :
63 : @param impl The acceptor implementation to assign to.
64 : @param fd The native socket to adopt. Ownership transfers only
65 : on success.
66 : @return Error code on failure, empty on success.
67 : */
68 : virtual std::error_code assign_socket(
69 : local_stream_acceptor::implementation& impl, native_handle_type fd) = 0;
70 :
71 : /** Bind an open acceptor to a local endpoint.
72 :
73 : @pre @p impl was opened via open_acceptor_socket().
74 : @param impl The acceptor implementation to bind.
75 : @param ep The local endpoint (path) to bind to.
76 : Copied; need not remain valid after the call.
77 : @return Error code on failure, empty on success.
78 : */
79 : virtual std::error_code bind_acceptor(
80 : local_stream_acceptor::implementation& impl, local_endpoint ep) = 0;
81 :
82 : /** Start listening for incoming connections.
83 :
84 : @pre @p impl was bound via bind_acceptor().
85 : @param impl The acceptor implementation to listen on.
86 : @param backlog The maximum pending connection queue length.
87 : @return Error code on failure, empty on success.
88 : */
89 : virtual std::error_code listen_acceptor(
90 : local_stream_acceptor::implementation& impl, int backlog) = 0;
91 :
92 : protected:
93 HIT 2106 : local_stream_acceptor_service() = default;
94 2106 : ~local_stream_acceptor_service() override = default;
95 : };
96 :
97 : } // namespace boost::corosio::detail
98 :
99 : #endif // BOOST_COROSIO_DETAIL_LOCAL_STREAM_ACCEPTOR_SERVICE_HPP
|