TLA Line data Source code
1 : //
2 : // Copyright (c) 2026 Steve Gerbino
3 : //
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)
6 : //
7 : // Official repository: https://github.com/cppalliance/corosio
8 : //
9 :
10 : #ifndef BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_SOCKET_HPP
11 : #define BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_SOCKET_HPP
12 :
13 : #include <boost/corosio/detail/platform.hpp>
14 :
15 : #if BOOST_COROSIO_HAS_SELECT
16 :
17 : #include <boost/corosio/tcp_socket.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>
22 :
23 : #include <memory>
24 :
25 : namespace boost::corosio::detail {
26 :
27 : class select_socket_service;
28 :
29 : /// Socket implementation for select backend.
30 : class select_socket final
31 : : public tcp_socket::implementation
32 : , public std::enable_shared_from_this<select_socket>
33 : , public intrusive_list<select_socket>::node
34 : {
35 : friend class select_socket_service;
36 :
37 : public:
38 : explicit select_socket(select_socket_service& svc) noexcept;
39 :
40 : std::coroutine_handle<> connect(
41 : std::coroutine_handle<>,
42 : capy::executor_ref,
43 : endpoint,
44 : std::stop_token,
45 : std::error_code*) override;
46 :
47 : std::coroutine_handle<> read_some(
48 : std::coroutine_handle<>,
49 : capy::executor_ref,
50 : buffer_param,
51 : std::stop_token,
52 : std::error_code*,
53 : std::size_t*) override;
54 :
55 : std::coroutine_handle<> write_some(
56 : std::coroutine_handle<>,
57 : capy::executor_ref,
58 : buffer_param,
59 : std::stop_token,
60 : std::error_code*,
61 : std::size_t*) override;
62 :
63 : std::error_code shutdown(tcp_socket::shutdown_type what) noexcept override;
64 :
65 HIT 21335 : native_handle_type native_handle() const noexcept override
66 : {
67 21335 : return fd_;
68 : }
69 :
70 : std::error_code set_option(
71 : int level,
72 : int optname,
73 : void const* data,
74 : std::size_t size) noexcept override;
75 : std::error_code
76 : get_option(int level, int optname, void* data, std::size_t* size)
77 : const noexcept override;
78 :
79 19 : endpoint local_endpoint() const noexcept override
80 : {
81 19 : return local_endpoint_;
82 : }
83 21 : endpoint remote_endpoint() const noexcept override
84 : {
85 21 : return remote_endpoint_;
86 : }
87 : bool is_open() const noexcept
88 : {
89 : return fd_ >= 0;
90 : }
91 : void cancel() noexcept override;
92 : void cancel_single_op(select_op& op) noexcept;
93 : void close_socket() noexcept;
94 3495 : void set_socket(int fd) noexcept
95 : {
96 3495 : fd_ = fd;
97 3495 : }
98 6990 : void set_endpoints(endpoint local, endpoint remote) noexcept
99 : {
100 6990 : local_endpoint_ = local;
101 6990 : remote_endpoint_ = remote;
102 6990 : }
103 :
104 : select_connect_op conn_;
105 : select_read_op rd_;
106 : select_write_op wr_;
107 :
108 : private:
109 : select_socket_service& svc_;
110 : int fd_ = -1;
111 : endpoint local_endpoint_;
112 : endpoint remote_endpoint_;
113 : };
114 :
115 : } // namespace boost::corosio::detail
116 :
117 : #endif // BOOST_COROSIO_HAS_SELECT
118 :
119 : #endif // BOOST_COROSIO_NATIVE_DETAIL_SELECT_SELECT_SOCKET_HPP
|