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_EPOLL_EPOLL_ACCEPTOR_HPP
10  
#ifndef BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_ACCEPTOR_HPP
11  
#define BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_ACCEPTOR_HPP
11  
#define BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_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_EPOLL
15  
#if BOOST_COROSIO_HAS_EPOLL
16  

16  

17  
#include <boost/corosio/tcp_acceptor.hpp>
17  
#include <boost/corosio/tcp_acceptor.hpp>
18  
#include <boost/capy/ex/executor_ref.hpp>
18  
#include <boost/capy/ex/executor_ref.hpp>
19  
#include <boost/corosio/detail/intrusive.hpp>
19  
#include <boost/corosio/detail/intrusive.hpp>
20  

20  

21  
#include <boost/corosio/native/detail/epoll/epoll_op.hpp>
21  
#include <boost/corosio/native/detail/epoll/epoll_op.hpp>
22  

22  

23  
#include <memory>
23  
#include <memory>
24  

24  

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

26  

27  
class epoll_acceptor_service;
27  
class epoll_acceptor_service;
28  

28  

29  
/// Acceptor implementation for epoll backend.
29  
/// Acceptor implementation for epoll backend.
30  
class epoll_acceptor final
30  
class epoll_acceptor final
31  
    : public tcp_acceptor::implementation
31  
    : public tcp_acceptor::implementation
32  
    , public std::enable_shared_from_this<epoll_acceptor>
32  
    , public std::enable_shared_from_this<epoll_acceptor>
33  
    , public intrusive_list<epoll_acceptor>::node
33  
    , public intrusive_list<epoll_acceptor>::node
34  
{
34  
{
35  
    friend class epoll_acceptor_service;
35  
    friend class epoll_acceptor_service;
36  

36  

37  
public:
37  
public:
38  
    explicit epoll_acceptor(epoll_acceptor_service& svc) noexcept;
38  
    explicit epoll_acceptor(epoll_acceptor_service& svc) noexcept;
39  

39  

40  
    std::coroutine_handle<> accept(
40  
    std::coroutine_handle<> accept(
41  
        std::coroutine_handle<>,
41  
        std::coroutine_handle<>,
42  
        capy::executor_ref,
42  
        capy::executor_ref,
43  
        std::stop_token,
43  
        std::stop_token,
44  
        std::error_code*,
44  
        std::error_code*,
45  
        io_object::implementation**) override;
45  
        io_object::implementation**) override;
46  

46  

47  
    int native_handle() const noexcept
47  
    int native_handle() const noexcept
48  
    {
48  
    {
49  
        return fd_;
49  
        return fd_;
50  
    }
50  
    }
51  
    endpoint local_endpoint() const noexcept override
51  
    endpoint local_endpoint() const noexcept override
52  
    {
52  
    {
53  
        return local_endpoint_;
53  
        return local_endpoint_;
54  
    }
54  
    }
55  
    bool is_open() const noexcept override
55  
    bool is_open() const noexcept override
56  
    {
56  
    {
57  
        return fd_ >= 0;
57  
        return fd_ >= 0;
58  
    }
58  
    }
59  
    void cancel() noexcept override;
59  
    void cancel() noexcept override;
60  

60  

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

75  

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

80  

81  
    epoll_accept_op acc_;
81  
    epoll_accept_op acc_;
82  
    descriptor_state desc_state_;
82  
    descriptor_state desc_state_;
83  

83  

84  
private:
84  
private:
85  
    epoll_acceptor_service& svc_;
85  
    epoll_acceptor_service& svc_;
86  
    int fd_ = -1;
86  
    int fd_ = -1;
87  
    endpoint local_endpoint_;
87  
    endpoint local_endpoint_;
88  
};
88  
};
89  

89  

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

91  

92  
#endif // BOOST_COROSIO_HAS_EPOLL
92  
#endif // BOOST_COROSIO_HAS_EPOLL
93  

93  

94  
#endif // BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_ACCEPTOR_HPP
94  
#endif // BOOST_COROSIO_NATIVE_DETAIL_EPOLL_EPOLL_ACCEPTOR_HPP