1  
//
1  
//
2  
// Copyright (c) 2026 Michael Vandeberg
2  
// Copyright (c) 2026 Michael Vandeberg
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/cppalliance/corosio
7  
// Official repository: https://github.com/cppalliance/corosio
8  
//
8  
//
9  

9  

10  
#ifndef BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP
10  
#ifndef BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP
11  
#define BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP
11  
#define BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP
12  

12  

13  
#include <boost/corosio/detail/config.hpp>
13  
#include <boost/corosio/detail/config.hpp>
14  
#include <boost/corosio/local_stream_socket.hpp>
14  
#include <boost/corosio/local_stream_socket.hpp>
15  
#include <boost/capy/ex/execution_context.hpp>
15  
#include <boost/capy/ex/execution_context.hpp>
16  
#include <system_error>
16  
#include <system_error>
17  

17  

18  
namespace boost::corosio::detail {
18  
namespace boost::corosio::detail {
19  

19  

20  
/* Abstract local stream service base class.
20  
/* Abstract local stream service base class.
21  

21  

22  
   Concrete implementations (epoll, select, kqueue) inherit from
22  
   Concrete implementations (epoll, select, kqueue) inherit from
23  
   this class and provide platform-specific stream socket operations
23  
   this class and provide platform-specific stream socket operations
24  
   for Unix domain sockets. The context constructor installs
24  
   for Unix domain sockets. The context constructor installs
25  
   whichever backend via make_service, and local_stream_socket.cpp
25  
   whichever backend via make_service, and local_stream_socket.cpp
26  
   retrieves it via use_service<local_stream_service>().
26  
   retrieves it via use_service<local_stream_service>().
27  
*/
27  
*/
28  
class BOOST_COROSIO_DECL local_stream_service
28  
class BOOST_COROSIO_DECL local_stream_service
29  
    : public capy::execution_context::service
29  
    : public capy::execution_context::service
30  
    , public io_object::io_service
30  
    , public io_object::io_service
31  
{
31  
{
32  
public:
32  
public:
33  
    /// Identifies this service for execution_context lookup.
33  
    /// Identifies this service for execution_context lookup.
34  
    using key_type = local_stream_service;
34  
    using key_type = local_stream_service;
35  

35  

36  
    /** Open a local (Unix domain) stream socket.
36  
    /** Open a local (Unix domain) stream socket.
37  

37  

38  
        Creates a socket and associates it with the platform
38  
        Creates a socket and associates it with the platform
39  
        I/O backend (reactor or IOCP).
39  
        I/O backend (reactor or IOCP).
40  

40  

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

52  

53  
    /** Assign an existing native socket handle to a socket.
53  
    /** Assign an existing native socket handle to a socket.
54  

54  

55  
        Adopts a pre-created socket handle (e.g. from a
55  
        Adopts a pre-created socket handle (e.g. from a
56  
        platform-specific pair creation API). On success the
56  
        platform-specific pair creation API). On success the
57  
        impl takes ownership and will close the handle. On
57  
        impl takes ownership and will close the handle. On
58  
        failure the caller retains ownership and must close
58  
        failure the caller retains ownership and must close
59  
        it. On platforms that do not support handle adoption,
59  
        it. On platforms that do not support handle adoption,
60  
        returns @c operation_not_supported.
60  
        returns @c operation_not_supported.
61  

61  

62  
        @param impl The socket implementation to assign to.
62  
        @param impl The socket implementation to assign to.
63  
        @param fd The native socket handle to adopt.
63  
        @param fd The native socket handle to adopt.
64  
        @return Error code on failure, empty on success.
64  
        @return Error code on failure, empty on success.
65  
    */
65  
    */
66  
    virtual std::error_code assign_socket(
66  
    virtual std::error_code assign_socket(
67  
        local_stream_socket::implementation& impl,
67  
        local_stream_socket::implementation& impl,
68  
        native_handle_type fd) = 0;
68  
        native_handle_type fd) = 0;
69  

69  

70  
protected:
70  
protected:
71  
    local_stream_service() = default;
71  
    local_stream_service() = default;
72  
    ~local_stream_service() override = default;
72  
    ~local_stream_service() override = default;
73  
};
73  
};
74  

74  

75  
} // namespace boost::corosio::detail
75  
} // namespace boost::corosio::detail
76  

76  

77  
#endif // BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP
77  
#endif // BOOST_COROSIO_DETAIL_LOCAL_STREAM_SERVICE_HPP