12
12
#if CPPCORO_OS_WINNT
13
13
# include < cppcoro/detail/win32.hpp>
14
14
# include < cppcoro/detail/win32_overlapped_operation.hpp>
15
+ #elif CPPCORO_OS_LINUX
16
+ # include < cppcoro/detail/linux_io_operation.hpp>
17
+ #endif
15
18
16
- # include < atomic>
17
- # include < optional>
19
+ #include < cppcoro/coroutine.hpp>
20
+ #include < atomic>
21
+ #include < optional>
18
22
19
23
namespace cppcoro
20
24
{
@@ -33,41 +37,53 @@ namespace cppcoro
33
37
, m_acceptingSocket(acceptingSocket)
34
38
{}
35
39
36
- bool try_start (cppcoro::detail::win32_overlapped_operation_base & operation) noexcept ;
37
- void cancel (cppcoro::detail::win32_overlapped_operation_base & operation) noexcept ;
38
- void get_result (cppcoro::detail::win32_overlapped_operation_base & operation);
40
+ bool try_start (cppcoro::detail::io_operation_base & operation) noexcept ;
41
+ void cancel (cppcoro::detail::io_operation_base & operation) noexcept ;
42
+ void get_result (cppcoro::detail::io_operation_base & operation);
39
43
40
44
private:
41
45
42
46
#if CPPCORO_COMPILER_MSVC
43
47
# pragma warning(push)
44
- # pragma warning(disable : 4324) // Structure padded due to alignment
48
+ # pragma warning(disable : 4324) // Structure padded due to alignment
45
49
#endif
46
50
47
51
socket& m_listeningSocket;
48
52
socket& m_acceptingSocket;
49
53
alignas (8 ) std::uint8_t m_addressBuffer[88 ];
50
54
55
+ #if CPPCORO_OS_LINUX
56
+ socklen_t m_addressBufferLength = sizeof (m_addressBuffer);
57
+ #endif
58
+
51
59
#if CPPCORO_COMPILER_MSVC
52
- # pragma warning(pop)
60
+ #pragma warning(pop)
53
61
#endif
54
62
55
63
};
56
64
57
65
class socket_accept_operation
58
- : public cppcoro::detail::win32_overlapped_operation <socket_accept_operation>
66
+ : public cppcoro::detail::io_operation <socket_accept_operation>
59
67
{
60
68
public:
61
69
62
70
socket_accept_operation (
71
+ #if CPPCORO_OS_LINUX
72
+ detail::lnx::io_queue& ioQueue,
73
+ #endif
63
74
socket& listeningSocket,
64
75
socket& acceptingSocket) noexcept
65
- : m_impl(listeningSocket, acceptingSocket)
76
+ : cppcoro::detail::io_operation<socket_accept_operation>{
77
+ #if CPPCORO_OS_LINUX
78
+ ioQueue,
79
+ #endif
80
+ }
81
+ , m_impl(listeningSocket, acceptingSocket)
66
82
{}
67
83
68
84
private:
69
85
70
- friend class cppcoro ::detail::win32_overlapped_operation <socket_accept_operation>;
86
+ friend cppcoro::detail::io_operation <socket_accept_operation>;
71
87
72
88
bool try_start () noexcept { return m_impl.try_start (*this ); }
73
89
void get_result () { m_impl.get_result (*this ); }
@@ -77,21 +93,28 @@ namespace cppcoro
77
93
};
78
94
79
95
class socket_accept_operation_cancellable
80
- : public cppcoro::detail::win32_overlapped_operation_cancellable <socket_accept_operation_cancellable>
96
+ : public cppcoro::detail::io_operation_cancellable <socket_accept_operation_cancellable>
81
97
{
82
98
public:
83
99
84
100
socket_accept_operation_cancellable (
101
+ #if CPPCORO_OS_LINUX
102
+ detail::lnx::io_queue& ioQueue,
103
+ #endif
85
104
socket& listeningSocket,
86
105
socket& acceptingSocket,
87
106
cancellation_token&& ct) noexcept
88
- : cppcoro::detail::win32_overlapped_operation_cancellable<socket_accept_operation_cancellable>(std::move(ct))
107
+ : cppcoro::detail::io_operation_cancellable<socket_accept_operation_cancellable>(
108
+ #if CPPCORO_OS_LINUX
109
+ ioQueue,
110
+ #endif
111
+ std::move (ct))
89
112
, m_impl(listeningSocket, acceptingSocket)
90
113
{}
91
114
92
115
private:
93
116
94
- friend class cppcoro ::detail::win32_overlapped_operation_cancellable <socket_accept_operation_cancellable>;
117
+ friend cppcoro::detail::io_operation_cancellable <socket_accept_operation_cancellable>;
95
118
96
119
bool try_start () noexcept { return m_impl.try_start (*this ); }
97
120
void cancel () noexcept { m_impl.cancel (*this ); }
@@ -100,9 +123,7 @@ namespace cppcoro
100
123
socket_accept_operation_impl m_impl;
101
124
102
125
};
103
- }
104
- }
105
-
106
- #endif // CPPCORO_OS_WINNT
126
+ } // namespace net
127
+ } // namespace cppcoro
107
128
108
129
#endif
0 commit comments