include/boost/corosio/detail/local_datagram_service.hpp
100.0% Lines (2/2)
100.0% List of functions (2/2)
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/detail/platform.hpp> | ||
| 15 | |||
| 16 | #if BOOST_COROSIO_POSIX | ||
| 17 | |||
| 18 | #include <boost/corosio/local_datagram_socket.hpp> | ||
| 19 | #include <boost/corosio/local_endpoint.hpp> | ||
| 20 | #include <boost/capy/ex/execution_context.hpp> | ||
| 21 | #include <system_error> | ||
| 22 | |||
| 23 | namespace boost::corosio::detail { | ||
| 24 | |||
| 25 | /** Abstract local datagram service base class. | ||
| 26 | |||
| 27 | Concrete implementations (epoll, select, kqueue, IOCP) | ||
| 28 | inherit from this class and provide platform-specific | ||
| 29 | datagram socket operations for local (Unix domain) sockets. | ||
| 30 | |||
| 31 | Instances are looked up via key_type in the | ||
| 32 | execution_context. All errors are reported via the returned | ||
| 33 | std::error_code; these methods do not throw. | ||
| 34 | */ | ||
| 35 | class BOOST_COROSIO_DECL local_datagram_service | ||
| 36 | : public capy::execution_context::service | ||
| 37 | , public io_object::io_service | ||
| 38 | { | ||
| 39 | public: | ||
| 40 | /// Identifies this service for execution_context lookup. | ||
| 41 | using key_type = local_datagram_service; | ||
| 42 | |||
| 43 | /** Open a local (Unix domain) datagram socket. | ||
| 44 | |||
| 45 | Creates a socket and associates it with the platform | ||
| 46 | I/O backend (reactor or IOCP). | ||
| 47 | |||
| 48 | @param impl The socket implementation to open. | ||
| 49 | Must not already represent an open socket. | ||
| 50 | @param family Address family for local IPC. | ||
| 51 | @param type Socket type for datagram sockets. | ||
| 52 | @param protocol Protocol number (typically 0). | ||
| 53 | @return Error code on failure, empty on success. | ||
| 54 | */ | ||
| 55 | virtual std::error_code open_socket( | ||
| 56 | local_datagram_socket::implementation& impl, | ||
| 57 | int family, | ||
| 58 | int type, | ||
| 59 | int protocol) = 0; | ||
| 60 | |||
| 61 | /** Assign an existing native socket handle to a socket. | ||
| 62 | |||
| 63 | Adopts a pre-created socket handle. On success the | ||
| 64 | impl takes ownership and will close the handle. On | ||
| 65 | failure the caller retains ownership and must close | ||
| 66 | it. On platforms that do not support handle adoption, | ||
| 67 | returns @c operation_not_supported. | ||
| 68 | |||
| 69 | @param impl The socket implementation to assign to. | ||
| 70 | @param fd The native socket handle to adopt. | ||
| 71 | @return Error code on failure, empty on success. | ||
| 72 | */ | ||
| 73 | virtual std::error_code assign_socket( | ||
| 74 | local_datagram_socket::implementation& impl, | ||
| 75 | native_handle_type fd) = 0; | ||
| 76 | |||
| 77 | /** Bind a datagram socket to a local endpoint. | ||
| 78 | |||
| 79 | @pre @p impl represents an open socket (via | ||
| 80 | open_socket() or assign_socket()). | ||
| 81 | @param impl The socket implementation to bind. | ||
| 82 | @param ep The local endpoint to bind to. | ||
| 83 | Copied; need not remain valid after the call. | ||
| 84 | @return Error code on failure, empty on success. | ||
| 85 | */ | ||
| 86 | virtual std::error_code bind_socket( | ||
| 87 | local_datagram_socket::implementation& impl, | ||
| 88 | corosio::local_endpoint ep) = 0; | ||
| 89 | |||
| 90 | protected: | ||
| 91 | 619x | local_datagram_service() = default; | |
| 92 | 619x | ~local_datagram_service() override = default; | |
| 93 | }; | ||
| 94 | |||
| 95 | } // namespace boost::corosio::detail | ||
| 96 | |||
| 97 | #endif // BOOST_COROSIO_POSIX | ||
| 98 | |||
| 99 | #endif // BOOST_COROSIO_DETAIL_LOCAL_DATAGRAM_SERVICE_HPP | ||
| 100 |