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_ACCEPTOR_SERVICE_HPP
10  
#ifndef BOOST_COROSIO_DETAIL_ACCEPTOR_SERVICE_HPP
11  
#define BOOST_COROSIO_DETAIL_ACCEPTOR_SERVICE_HPP
11  
#define BOOST_COROSIO_DETAIL_ACCEPTOR_SERVICE_HPP
12  

12  

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

18  

19  
namespace boost::corosio::detail {
19  
namespace boost::corosio::detail {
20  

20  

21  
/** Abstract acceptor service base class.
21  
/** Abstract acceptor service base class.
22  

22  

23  
    Concrete implementations ( epoll_acceptors, select_acceptors, etc. )
23  
    Concrete implementations ( epoll_acceptors, select_acceptors, etc. )
24  
    inherit from this class and provide platform-specific acceptor
24  
    inherit from this class and provide platform-specific acceptor
25  
    operations. The context constructor installs whichever backend
25  
    operations. The context constructor installs whichever backend
26  
    via `make_service`, and `tcp_acceptor.cpp` retrieves it via
26  
    via `make_service`, and `tcp_acceptor.cpp` retrieves it via
27  
    `use_service<acceptor_service>()`.
27  
    `use_service<acceptor_service>()`.
28  
*/
28  
*/
29  
class BOOST_COROSIO_DECL acceptor_service
29  
class BOOST_COROSIO_DECL acceptor_service
30  
    : public capy::execution_context::service
30  
    : public capy::execution_context::service
31  
    , public io_object::io_service
31  
    , public io_object::io_service
32  
{
32  
{
33  
public:
33  
public:
34  
    /// Identifies this service for `execution_context` lookup.
34  
    /// Identifies this service for `execution_context` lookup.
35  
    using key_type = acceptor_service;
35  
    using key_type = acceptor_service;
36  

36  

37  
    /** Open an acceptor.
37  
    /** Open an acceptor.
38  

38  

39  
        Creates an IPv4 TCP socket, binds it to the specified endpoint,
39  
        Creates an IPv4 TCP socket, binds it to the specified endpoint,
40  
        and begins listening for incoming connections.
40  
        and begins listening for incoming connections.
41  

41  

42  
        @param impl The acceptor implementation to open.
42  
        @param impl The acceptor implementation to open.
43  
        @param ep The local endpoint to bind to.
43  
        @param ep The local endpoint to bind to.
44  
        @param backlog The maximum length of the queue of pending connections.
44  
        @param backlog The maximum length of the queue of pending connections.
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_acceptor(
47  
    virtual std::error_code open_acceptor(
48  
        tcp_acceptor::implementation& impl, endpoint ep, int backlog) = 0;
48  
        tcp_acceptor::implementation& impl, endpoint ep, int backlog) = 0;
49  

49  

50  
protected:
50  
protected:
51  
    /// Construct the acceptor service.
51  
    /// Construct the acceptor service.
52  
    acceptor_service() = default;
52  
    acceptor_service() = default;
53  

53  

54  
    /// Destroy the acceptor service.
54  
    /// Destroy the acceptor service.
55  
    ~acceptor_service() override = default;
55  
    ~acceptor_service() override = default;
56  
};
56  
};
57  

57  

58  
} // namespace boost::corosio::detail
58  
} // namespace boost::corosio::detail
59  

59  

60  
#endif // BOOST_COROSIO_DETAIL_ACCEPTOR_SERVICE_HPP
60  
#endif // BOOST_COROSIO_DETAIL_ACCEPTOR_SERVICE_HPP