1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 | #include "uring.hpp"
#include <poll.h>
#include <iostream>
struct felspar::io::uring_warden::close_completion : public completion<void> {
close_completion(uring_warden *s, int fd, std::source_location const loc)
: completion<void>{s, {}, loc}, fd{fd} {}
int fd;
std::coroutine_handle<> await_suspend(std::coroutine_handle<> h) override {
auto sqe = setup_submission(h);
::io_uring_prep_close(sqe, fd);
return setup_timeout(sqe);
}
};
felspar::io::iop<void> felspar::io::uring_warden::do_close(
int fd, std::source_location const loc) {
return {new close_completion{this, fd, loc}};
}
struct felspar::io::uring_warden::sleep_completion : public completion<void> {
sleep_completion(
uring_warden *s,
std::chrono::nanoseconds ns,
std::source_location const loc)
: completion<void>{s, {}, loc} {
kts = {{}, ns.count()};
}
std::coroutine_handle<> await_suspend(std::coroutine_handle<> h) override {
auto sqe = setup_submission(h);
::io_uring_prep_timeout(sqe, &kts, 0, 0);
::io_uring_sqe_set_data(sqe, this);
return std::noop_coroutine();
}
void deliver(int result) override {
completion<void>::deliver(result == -ETIME ? 0 : result);
}
};
felspar::io::iop<void> felspar::io::uring_warden::do_sleep(
std::chrono::nanoseconds ns, std::source_location const loc) {
return {new sleep_completion{this, ns, loc}};
}
struct felspar::io::uring_warden::read_some_completion :
public completion<std::size_t> {
read_some_completion(
uring_warden *s,
int f,
std::span<std::byte> b,
std::optional<io::deadline> t,
std::source_location const loc)
: completion<std::size_t>{s, t, loc}, fd{f}, bytes{b} {}
int fd;
std::span<std::byte> bytes;
std::coroutine_handle<> await_suspend(std::coroutine_handle<> h) override {
auto sqe = setup_submission(h);
::io_uring_prep_read(sqe, fd, bytes.data(), bytes.size(), 0);
return setup_timeout(sqe);
}
};
felspar::io::iop<std::size_t> felspar::io::uring_warden::do_read_some(
socket_descriptor fd,
std::span<std::byte> b,
std::optional<deadline> timeout,
std::source_location const loc) {
return {new read_some_completion{this, fd, b, timeout, loc}};
}
struct felspar::io::uring_warden::write_some_completion :
public completion<std::size_t> {
write_some_completion(
uring_warden *s,
socket_descriptor f,
std::span<std::byte const> b,
std::optional<io::deadline> t,
std::source_location const loc)
: completion<std::size_t>{s, t, loc}, fd{f}, bytes{b} {}
socket_descriptor fd;
std::span<std::byte const> bytes;
std::coroutine_handle<> await_suspend(std::coroutine_handle<> h) override {
auto sqe = setup_submission(h);
::io_uring_prep_write(sqe, fd, bytes.data(), bytes.size(), 0);
return setup_timeout(sqe);
}
};
felspar::io::iop<std::size_t> felspar::io::uring_warden::do_write_some(
socket_descriptor fd,
std::span<std::byte const> b,
std::optional<deadline> t,
std::source_location const loc) {
return {new write_some_completion{this, fd, b, t, loc}};
}
struct felspar::io::uring_warden::accept_completion :
public completion<socket_descriptor> {
accept_completion(
uring_warden *s,
socket_descriptor f,
std::optional<io::deadline> t,
std::source_location const loc)
: completion<socket_descriptor>{s, t, loc}, fd{f} {}
socket_descriptor fd = {};
sockaddr addr = {};
socklen_t addrlen = {};
std::coroutine_handle<> await_suspend(std::coroutine_handle<> h) override {
auto sqe = setup_submission(h);
::io_uring_prep_accept(sqe, fd, &addr, &addrlen, 0);
return setup_timeout(sqe);
}
};
felspar::io::iop<felspar::io::socket_descriptor>
felspar::io::uring_warden::do_accept(
socket_descriptor fd,
std::optional<deadline> timeout,
std::source_location const loc) {
return {new accept_completion{this, fd, timeout, loc}};
}
struct felspar::io::uring_warden::connect_completion : public completion<void> {
connect_completion(
uring_warden *s,
socket_descriptor f,
sockaddr const *a,
socklen_t l,
std::optional<io::deadline> t,
std::source_location const loc)
: completion<void>{s, t, loc}, fd{f}, addr{a}, addrlen{l} {}
socket_descriptor fd = {};
sockaddr const *addr = {};
socklen_t addrlen = {};
std::coroutine_handle<> await_suspend(std::coroutine_handle<> h) override {
auto sqe = setup_submission(h);
::io_uring_prep_connect(sqe, fd, addr, addrlen);
return setup_timeout(sqe);
}
};
felspar::io::iop<void> felspar::io::uring_warden::do_connect(
socket_descriptor fd,
sockaddr const *addr,
socklen_t addrlen,
std::optional<deadline> timeout,
std::source_location const loc) {
return {new connect_completion{this, fd, addr, addrlen, timeout, loc}};
}
struct felspar::io::uring_warden::poll_completion : public completion<void> {
poll_completion(
uring_warden *s,
socket_descriptor f,
short m,
std::optional<io::deadline> t,
std::source_location const loc)
: completion<void>{s, t, loc}, fd{f}, mask{m} {}
socket_descriptor fd = {};
short mask = {};
std::coroutine_handle<> await_suspend(std::coroutine_handle<> h) override {
auto sqe = setup_submission(h);
::io_uring_prep_poll_add(sqe, fd, mask);
return setup_timeout(sqe);
}
};
felspar::io::iop<void> felspar::io::uring_warden::do_read_ready(
socket_descriptor fd,
std::optional<deadline> timeout,
std::source_location const loc) {
return {new poll_completion{this, fd, POLLIN, timeout, loc}};
}
felspar::io::iop<void> felspar::io::uring_warden::do_write_ready(
socket_descriptor fd,
std::optional<deadline> timeout,
std::source_location const loc) {
return {new poll_completion{this, fd, POLLOUT, timeout, loc}};
}
|