1  
//
1  
//
2  
// Copyright (c) 2026 Steve Gerbino
2  
// Copyright (c) 2026 Steve Gerbino
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_SOCKET_SERVICE_HPP
10  
#ifndef BOOST_COROSIO_DETAIL_SOCKET_SERVICE_HPP
11  
#define BOOST_COROSIO_DETAIL_SOCKET_SERVICE_HPP
11  
#define BOOST_COROSIO_DETAIL_SOCKET_SERVICE_HPP
12  

12  

13  
#include <boost/corosio/detail/config.hpp>
13  
#include <boost/corosio/detail/config.hpp>
14  
#include <boost/corosio/tcp_socket.hpp>
14  
#include <boost/corosio/tcp_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 socket service base class.
20  
/** Abstract socket service base class.
21  

21  

22  
    Concrete implementations ( epoll_sockets, select_sockets, etc. )
22  
    Concrete implementations ( epoll_sockets, select_sockets, etc. )
23  
    inherit from this class and provide platform-specific socket
23  
    inherit from this class and provide platform-specific socket
24  
    operations. The context constructor installs whichever backend
24  
    operations. The context constructor installs whichever backend
25  
    via `make_service`, and `tcp_socket.cpp` retrieves it via
25  
    via `make_service`, and `tcp_socket.cpp` retrieves it via
26  
    `use_service<socket_service>()`.
26  
    `use_service<socket_service>()`.
27  
*/
27  
*/
28  
class BOOST_COROSIO_DECL socket_service
28  
class BOOST_COROSIO_DECL socket_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 = socket_service;
34  
    using key_type = socket_service;
35  

35  

36  
    /** Open a socket.
36  
    /** Open a socket.
37  

37  

38  
        Creates an IPv4 TCP socket and associates it with the platform reactor.
38  
        Creates an IPv4 TCP socket and associates it with the platform reactor.
39  

39  

40  
        @param impl The socket implementation to open.
40  
        @param impl The socket implementation to open.
41  
        @return Error code on failure, empty on success.
41  
        @return Error code on failure, empty on success.
42  
    */
42  
    */
43  
    virtual std::error_code open_socket(tcp_socket::implementation& impl) = 0;
43  
    virtual std::error_code open_socket(tcp_socket::implementation& impl) = 0;
44  

44  

45  
protected:
45  
protected:
46  
    /// Construct the socket service.
46  
    /// Construct the socket service.
47  
    socket_service() = default;
47  
    socket_service() = default;
48  

48  

49  
    /// Destroy the socket service.
49  
    /// Destroy the socket service.
50  
    ~socket_service() override = default;
50  
    ~socket_service() override = default;
51  
};
51  
};
52  

52  

53  
} // namespace boost::corosio::detail
53  
} // namespace boost::corosio::detail
54  

54  

55  
#endif // BOOST_COROSIO_DETAIL_SOCKET_SERVICE_HPP
55  
#endif // BOOST_COROSIO_DETAIL_SOCKET_SERVICE_HPP