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_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP
10  
#ifndef BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP
11  
#define BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP
11  
#define BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP
12  

12  

13  
#include <boost/corosio/detail/platform.hpp>
13  
#include <boost/corosio/detail/platform.hpp>
14  

14  

15  
#if BOOST_COROSIO_HAS_SELECT
15  
#if BOOST_COROSIO_HAS_SELECT
16  

16  

17 -
#include <boost/corosio/tcp_acceptor.hpp>
17 +
#include <boost/corosio/native/detail/reactor/reactor_acceptor.hpp>
18 -
#include <boost/capy/ex/executor_ref.hpp>
 
19 -
#include <boost/corosio/detail/intrusive.hpp>
 
20 -

 
21  
#include <boost/corosio/native/detail/select/select_op.hpp>
18  
#include <boost/corosio/native/detail/select/select_op.hpp>
22 -

19 +
#include <boost/capy/ex/executor_ref.hpp>
23 -
#include <memory>
 
24  

20  

25  
namespace boost::corosio::detail {
21  
namespace boost::corosio::detail {
26  

22  

27 -
class select_socket_service;
 
28  
class select_acceptor_service;
23  
class select_acceptor_service;
29  

24  

30  
/// Acceptor implementation for select backend.
25  
/// Acceptor implementation for select backend.
31  
class select_acceptor final
26  
class select_acceptor final
32 -
    : public tcp_acceptor::implementation
27 +
    : public reactor_acceptor<
33 -
    , public std::enable_shared_from_this<select_acceptor>
28 +
          select_acceptor,
34 -
    , public intrusive_list<select_acceptor>::node
29 +
          select_acceptor_service,
 
30 +
          select_op,
 
31 +
          select_accept_op,
 
32 +
          select_descriptor_state>
35  
{
33  
{
36  
    friend class select_acceptor_service;
34  
    friend class select_acceptor_service;
37  

35  

38  
public:
36  
public:
39  
    explicit select_acceptor(select_acceptor_service& svc) noexcept;
37  
    explicit select_acceptor(select_acceptor_service& svc) noexcept;
40  

38  

41  
    std::coroutine_handle<> accept(
39  
    std::coroutine_handle<> accept(
42  
        std::coroutine_handle<>,
40  
        std::coroutine_handle<>,
43  
        capy::executor_ref,
41  
        capy::executor_ref,
44  
        std::stop_token,
42  
        std::stop_token,
45  
        std::error_code*,
43  
        std::error_code*,
46  
        io_object::implementation**) override;
44  
        io_object::implementation**) override;
47 -
    int native_handle() const noexcept
 
48 -
    {
 
49 -
        return fd_;
 
50 -
    }
 
51 -
    endpoint local_endpoint() const noexcept override
 
52 -
    {
 
53 -
        return local_endpoint_;
 
54 -
    }
 
55 -
    bool is_open() const noexcept override
 
56 -
    {
 
57 -
        return fd_ >= 0;
 
58 -
    }
 
59  

45  

60 -

 
61 -
    std::error_code set_option(
 
62 -
        int level,
 
63 -
        int optname,
 
64 -
        void const* data,
 
65 -
        std::size_t size) noexcept override;
 
66 -
    std::error_code
 
67 -
    get_option(int level, int optname, void* data, std::size_t* size)
 
68 -
        const noexcept override;
 
69 -
    void cancel_single_op(select_op& op) noexcept;
 
70  
    void cancel() noexcept override;
46  
    void cancel() noexcept override;
71 -
    void set_local_endpoint(endpoint ep) noexcept
 
72 -
    {
 
73 -
        local_endpoint_ = ep;
 
74 -
    }
 
75 -

 
76 -
    select_acceptor_service& service() noexcept
 
77 -
    {
 
78 -
        return svc_;
 
79 -
    }
 
80 -

 
81 -
    select_accept_op acc_;
 
82 -

 
83 -
private:
 
84 -
    select_acceptor_service& svc_;
 
85 -
    int fd_ = -1;
 
86 -
    endpoint local_endpoint_;
 
87  
    void close_socket() noexcept;
47  
    void close_socket() noexcept;
88  
};
48  
};
89  

49  

90  
} // namespace boost::corosio::detail
50  
} // namespace boost::corosio::detail
91  

51  

92  
#endif // BOOST_COROSIO_HAS_SELECT
52  
#endif // BOOST_COROSIO_HAS_SELECT
93  

53  

94  
#endif // BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP
54  
#endif // BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_ACCEPTOR_HPP