include/boost/corosio/detail/local_datagram_service.hpp

100.0% Lines (2/2) 100.0% List of functions (2/2)
local_datagram_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_DATAGRAM_SERVICE_HPP
11 #define BOOST_COROSIO_DETAIL_LOCAL_DATAGRAM_SERVICE_HPP
12
13 #include <boost/corosio/detail/config.hpp>
14 #include <boost/corosio/local_datagram_socket.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 datagram service base class.
22
23 Concrete implementations (epoll, select, kqueue) inherit from
24 this class and provide platform-specific datagram socket operations
25 for Unix domain sockets. The context constructor installs
26 whichever backend via make_service, and local_datagram_socket.cpp
27 retrieves it via use_service<local_datagram_service>().
28 */
29 class BOOST_COROSIO_DECL local_datagram_service
30 : public capy::execution_context::service
31 , public io_object::io_service
32 {
33 public:
34 /// Identifies this service for execution_context lookup.
35 using key_type = local_datagram_service;
36
37 /** Open a Unix datagram socket.
38
39 Creates a socket and associates it with the platform reactor.
40
41 @param impl The socket implementation to open.
42 @param family Address family (AF_UNIX).
43 @param type Socket type (SOCK_DGRAM).
44 @param protocol Protocol number (0).
45 @return Error code on failure, empty on success.
46 */
47 virtual std::error_code open_socket(
48 local_datagram_socket::implementation& impl,
49 int family,
50 int type,
51 int protocol) = 0;
52
53 /** Assign an existing file descriptor to a socket.
54
55 Used by socketpair() to adopt pre-created fds.
56
57 @param impl The socket implementation to assign to.
58 @param fd The file descriptor to adopt.
59 @return Error code on failure, empty on success.
60 */
61 virtual std::error_code assign_socket(
62 local_datagram_socket::implementation& impl,
63 int fd) = 0;
64
65 /** Bind a datagram socket to a local endpoint.
66
67 @param impl The socket implementation to bind.
68 @param ep The local endpoint to bind to.
69 @return Error code on failure, empty on success.
70 */
71 virtual std::error_code bind_socket(
72 local_datagram_socket::implementation& impl,
73 corosio::local_endpoint ep) = 0;
74
75 protected:
76 587x local_datagram_service() = default;
77 587x ~local_datagram_service() override = default;
78 };
79
80 } // namespace boost::corosio::detail
81
82 #endif // BOOST_COROSIO_DETAIL_LOCAL_DATAGRAM_SERVICE_HPP
83