include/boost/corosio/detail/local_stream_service.hpp

100.0% Lines (2/2) 100.0% List of functions (2/2)
local_stream_service.hpp
f(x) Functions (2)
Line TLA Hits 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_SERVICE_HPP
11 #define BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP
12
13 #include <boost/corosio/detail/config.hpp>
14 #include <boost/corosio/local_stream_socket.hpp>
15 #include <boost/capy/ex/execution_context.hpp>
16 #include <system_error>
17
18 namespace boost::corosio::detail {
19
20 /* Abstract local stream service base class.
21
22 Concrete implementations (epoll, select, kqueue) inherit from
23 this class and provide platform-specific stream socket operations
24 for Unix domain sockets. The context constructor installs
25 whichever backend via make_service, and local_stream_socket.cpp
26 retrieves it via use_service<local_stream_service>().
27 */
28 class BOOST_COROSIO_DECL local_stream_service
29 : public capy::execution_context::service
30 , public io_object::io_service
31 {
32 public:
33 /// Identifies this service for execution_context lookup.
34 using key_type = local_stream_service;
35
36 /** Open a local (Unix domain) stream socket.
37
38 Creates a socket and associates it with the platform
39 I/O backend (reactor or IOCP).
40
41 @param impl The socket implementation to open.
42 @param family Address family for local IPC.
43 @param type Socket type for stream sockets.
44 @param protocol Protocol number (typically 0).
45 @return Error code on failure, empty on success.
46 */
47 virtual std::error_code open_socket(
48 local_stream_socket::implementation& impl,
49 int family,
50 int type,
51 int protocol) = 0;
52
53 /** Assign an existing native socket handle to a socket.
54
55 Adopts a pre-created socket handle (e.g. from a
56 platform-specific pair creation API). On success the
57 impl takes ownership and will close the handle. On
58 failure the caller retains ownership and must close
59 it. On platforms that do not support handle adoption,
60 returns @c operation_not_supported.
61
62 @param impl The socket implementation to assign to.
63 @param fd The native socket handle to adopt.
64 @return Error code on failure, empty on success.
65 */
66 virtual std::error_code assign_socket(
67 local_stream_socket::implementation& impl,
68 native_handle_type fd) = 0;
69
70 protected:
71 583x local_stream_service() = default;
72 583x ~local_stream_service() override = default;
73 };
74
75 } // namespace boost::corosio::detail
76
77 #endif // BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP
78