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,
70 : native_handle_type fd) = 0;
71 :
72 : /** Bind an open acceptor to a local endpoint.
73 :
74 : @pre @p impl was opened via open_acceptor_socket().
75 : @param impl The acceptor implementation to bind.
76 : @param ep The local endpoint (path) to bind to.
77 : Copied; need not remain valid after the call.
78 : @return Error code on failure, empty on success.
79 : */
80 : virtual std::error_code bind_acceptor(
81 : local_stream_acceptor::implementation& impl,
82 : local_endpoint ep) = 0;
83 :
84 : /** Start listening for incoming connections.
85 :
86 : @pre @p impl was bound via bind_acceptor().
87 : @param impl The acceptor implementation to listen on.
88 : @param backlog The maximum pending connection queue length.
89 : @return Error code on failure, empty on success.
90 : */
91 : virtual std::error_code listen_acceptor(
92 : local_stream_acceptor::implementation& impl,
93 : int backlog) = 0;
94 :
95 : protected:
96 HIT 1603 : local_stream_acceptor_service() = default;
97 1603 : ~local_stream_acceptor_service() override = default;
98 : };
99 :
100 : } // namespace boost::corosio::detail
101 :
102 : #endif // BOOST_COROSIO_DETAIL_LOCAL_STREAM_ACCEPTOR_SERVICE_HPP
|