File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ class acceptor : public io_object
154154 @param other The acceptor to move from.
155155 */
156156 acceptor (acceptor&& other) noexcept
157- : ctx_ (other.ctx_ )
157+ : io_object (other.context() )
158158 {
159159 impl_ = other.impl_ ;
160160 other.impl_ = nullptr ;
Original file line number Diff line number Diff line change 1111#define BOOST_COROSIO_IO_OBJECT_HPP
1212
1313#include < boost/corosio/detail/config.hpp>
14+ #include < boost/capy/execution_context.hpp>
1415
1516namespace boost {
1617namespace corosio {
@@ -40,10 +41,28 @@ class io_object
4041 virtual void release () = 0;
4142 };
4243
44+ /* * Return the execution context.
45+
46+ @return Reference to the execution context that owns this socket.
47+ */
48+ auto
49+ context () const noexcept ->
50+ capy::execution_context&
51+ {
52+ return *ctx_;
53+ }
54+
4355protected:
4456 virtual ~io_object () = default ;
45- io_object () = default ;
46-
57+
58+ explicit
59+ io_object (
60+ capy::execution_context& ctx) noexcept
61+ : ctx_(&ctx)
62+ {
63+ }
64+
65+ capy::execution_context* ctx_ = nullptr ;
4766 io_object_impl* impl_ = nullptr ;
4867};
4968
Original file line number Diff line number Diff line change @@ -27,25 +27,6 @@ namespace corosio {
2727class io_stream : public io_object
2828{
2929public:
30- struct io_stream_impl : io_object_impl
31- {
32- virtual void read_some (
33- std::coroutine_handle<>,
34- capy::any_dispatcher,
35- any_bufref&,
36- std::stop_token,
37- system::error_code*,
38- std::size_t *) = 0;
39-
40- virtual void write_some (
41- std::coroutine_handle<>,
42- capy::any_dispatcher,
43- any_bufref&,
44- std::stop_token,
45- system::error_code*,
46- std::size_t *) = 0;
47- };
48-
4930 /* * Initiate an asynchronous read operation.
5031
5132 Reads available data into the provided buffer sequence. The
@@ -213,6 +194,34 @@ class io_stream : public io_object
213194 }
214195 };
215196
197+ public:
198+ struct io_stream_impl : io_object_impl
199+ {
200+ virtual void read_some (
201+ std::coroutine_handle<>,
202+ capy::any_dispatcher,
203+ any_bufref&,
204+ std::stop_token,
205+ system::error_code*,
206+ std::size_t *) = 0;
207+
208+ virtual void write_some (
209+ std::coroutine_handle<>,
210+ capy::any_dispatcher,
211+ any_bufref&,
212+ std::stop_token,
213+ system::error_code*,
214+ std::size_t *) = 0;
215+ };
216+
217+ protected:
218+ explicit
219+ io_stream (
220+ capy::execution_context& ctx) noexcept
221+ : io_object(ctx)
222+ {
223+ }
224+
216225private:
217226 io_stream_impl& get () const noexcept
218227 {
Original file line number Diff line number Diff line change @@ -72,6 +72,26 @@ namespace corosio {
7272*/
7373class socket : public io_stream
7474{
75+ friend class acceptor ;
76+
77+ struct socket_impl ;
78+
79+ inline socket_impl& get () const noexcept
80+ {
81+ return *static_cast <socket_impl*>(impl_);
82+ }
83+
84+ public:
85+ struct socket_impl : io_stream_impl
86+ {
87+ virtual void connect (
88+ std::coroutine_handle<>,
89+ capy::any_dispatcher,
90+ endpoint,
91+ std::stop_token,
92+ system::error_code*) = 0;
93+ };
94+
7595 struct connect_awaitable
7696 {
7797 socket& s_;
@@ -154,7 +174,7 @@ class socket : public io_stream
154174 @param other The socket to move from.
155175 */
156176 socket (socket&& other) noexcept
157- : ctx_ (other.ctx_ )
177+ : io_stream (other.context() )
158178 {
159179 impl_ = other.impl_ ;
160180 other.impl_ = nullptr ;
@@ -261,37 +281,6 @@ class socket : public io_stream
261281 */
262282 BOOST_COROSIO_DECL
263283 void cancel ();
264-
265- /* * Return the execution context.
266-
267- @return Reference to the execution context that owns this socket.
268- */
269- auto
270- context () const noexcept ->
271- capy::execution_context&
272- {
273- return *ctx_;
274- }
275-
276- struct socket_impl : io_stream_impl
277- {
278- virtual void connect (
279- std::coroutine_handle<>,
280- capy::any_dispatcher,
281- endpoint,
282- std::stop_token,
283- system::error_code*) = 0;
284- };
285-
286- private:
287- friend class acceptor ;
288-
289- inline socket_impl& get () const noexcept
290- {
291- return *static_cast <socket_impl*>(impl_);
292- }
293-
294- capy::execution_context* ctx_;
295284};
296285
297286} // namespace corosio
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ acceptor::
3939acceptor::
4040acceptor (
4141 capy::execution_context& ctx)
42- : ctx_(& ctx)
42+ : io_object( ctx)
4343{
4444}
4545
Original file line number Diff line number Diff line change @@ -95,19 +95,22 @@ class win_socket_impl
9595 explicit win_socket_impl (win_iocp_sockets& svc) noexcept ;
9696
9797 void release () override ;
98+
9899 void connect (
99100 std::coroutine_handle<>,
100101 capy::any_dispatcher,
101102 endpoint,
102103 std::stop_token,
103104 system::error_code*) override ;
105+
104106 void read_some (
105107 std::coroutine_handle<>,
106108 capy::any_dispatcher,
107109 any_bufref&,
108110 std::stop_token,
109111 system::error_code*,
110112 std::size_t *) override ;
113+
111114 void write_some (
112115 std::coroutine_handle<>,
113116 capy::any_dispatcher,
@@ -150,6 +153,7 @@ class win_acceptor_impl
150153 explicit win_acceptor_impl (win_iocp_sockets& svc) noexcept ;
151154
152155 void release () override ;
156+
153157 void accept (
154158 std::coroutine_handle<>,
155159 capy::any_dispatcher,
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ socket::
3939socket::
4040socket (
4141 capy::execution_context& ctx)
42- : ctx_(& ctx)
42+ : io_stream( ctx)
4343{
4444}
4545
Original file line number Diff line number Diff line change @@ -678,7 +678,8 @@ struct wolfssl_stream_impl_
678678
679679wolfssl_stream::
680680wolfssl_stream (io_stream& stream)
681- : s_(stream)
681+ : io_stream(stream.context())
682+ , s_(stream)
682683{
683684 construct ();
684685}
You can’t perform that action at this time.
0 commit comments