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 Unix stream socket.
 
37 +

 
38 +
        Creates a socket and associates it with the platform reactor.
 
39 +

 
40 +
        @param impl The socket implementation to open.
 
41 +
        @param family Address family (AF_UNIX).
 
42 +
        @param type Socket type (SOCK_STREAM).
 
43 +
        @param protocol Protocol number (0).
 
44 +
        @return Error code on failure, empty on success.
 
45 +
    */
 
46 +
    virtual std::error_code open_socket(
 
47 +
        local_stream_socket::implementation& impl,
 
48 +
        int family,
 
49 +
        int type,
 
50 +
        int protocol) = 0;
 
51 +

 
52 +
    /** Assign an existing file descriptor to a socket.
 
53 +

 
54 +
        Used by socketpair() to adopt pre-created fds.
 
55 +

 
56 +
        @param impl The socket implementation to assign to.
 
57 +
        @param fd The file descriptor to adopt.
 
58 +
        @return Error code on failure, empty on success.
 
59 +
    */
 
60 +
    virtual std::error_code assign_socket(
 
61 +
        local_stream_socket::implementation& impl,
 
62 +
        int fd) = 0;
 
63 +

 
64 +
protected:
 
65 +
    local_stream_service() = default;
 
66 +
    ~local_stream_service() override = default;
 
67 +
};
 
68 +

 
69 +
} // namespace boost::corosio::detail
 
70 +

 
71 +
#endif // BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP