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