24#include <seastar/core/sstring.hh>
25#include <seastar/core/on_internal_error.hh>
30#include <sys/socket.h>
39 enum class operation :
char { read, readv, write, writev, fdatasync, recv, recvmsg, send, sendmsg, accept,
connect, poll_add, poll_remove, cancel };
75 using send_op = recv_op;
76 using sendmsg_op = recvmsg_op;
77 using write_op = read_op;
78 using writev_op = readv_op;
87 socklen_t* socklen_ptr;
101 struct poll_remove_op {
121 fdatasync_op _fdatasync;
124 poll_add_op _poll_add;
125 poll_remove_op _poll_remove;
130 static io_request make_read(
int fd, uint64_t pos,
void* address,
size_t size,
bool nowait_works) {
133 .op = operation::read,
134 .nowait_works = nowait_works,
137 .addr =
reinterpret_cast<char*
>(address),
143 static io_request make_readv(
int fd, uint64_t pos, std::vector<iovec>& iov,
bool nowait_works) {
146 .op = operation::readv,
147 .nowait_works = nowait_works,
151 .iov_len = iov.size(),
156 static io_request make_recv(
int fd,
void* address,
size_t size,
int flags) {
159 .op = operation::recv,
161 .addr =
reinterpret_cast<char*
>(address),
168 static io_request make_recvmsg(
int fd, ::msghdr* msg,
int flags) {
171 .op = operation::recvmsg,
179 static io_request make_send(
int fd,
const void* address,
size_t size,
int flags) {
182 .op = operation::send,
184 .addr =
const_cast<char*
>(
reinterpret_cast<const char*
>(address)),
191 static io_request make_sendmsg(
int fd, ::msghdr* msg,
int flags) {
194 .op = operation::sendmsg,
202 static io_request make_write(
int fd, uint64_t pos,
const void* address,
size_t size,
bool nowait_works) {
205 .op = operation::write,
206 .nowait_works = nowait_works,
209 .addr =
const_cast<char*
>(
reinterpret_cast<const char*
>(address)),
215 static io_request make_writev(
int fd, uint64_t pos, std::vector<iovec>& iov,
bool nowait_works) {
218 .op = operation::writev,
219 .nowait_works = nowait_works,
223 .iov_len = iov.size(),
228 static io_request make_fdatasync(
int fd) {
231 .op = operation::fdatasync,
237 static io_request make_accept(
int fd,
struct sockaddr* addr, socklen_t* addrlen,
int flags) {
240 .op = operation::accept,
243 .socklen_ptr = addrlen,
249 static io_request make_connect(
int fd,
struct sockaddr* addr, socklen_t addrlen) {
252 .op = operation::connect,
260 static io_request make_poll_add(
int fd,
int events) {
263 .op = operation::poll_add,
270 static io_request make_poll_remove(
int fd,
void *addr) {
273 .op = operation::poll_remove,
275 .addr =
reinterpret_cast<char*
>(addr),
280 static io_request make_cancel(
int fd,
void *addr) {
283 .op = operation::cancel,
285 .addr =
reinterpret_cast<char*
>(addr),
290 bool is_read()
const {
292 case operation::read:
293 case operation::readv:
294 case operation::recvmsg:
295 case operation::recv:
302 bool is_write()
const {
304 case operation::write:
305 case operation::writev:
306 case operation::send:
307 case operation::sendmsg:
314 sstring opname()
const;
319 operation opcode()
const {
323 template <operation Op>
325 if constexpr (Op == operation::read) {
328 if constexpr (Op == operation::readv) {
331 if constexpr (Op == operation::recv) {
334 if constexpr (Op == operation::recvmsg) {
337 if constexpr (Op == operation::send) {
340 if constexpr (Op == operation::sendmsg) {
343 if constexpr (Op == operation::write) {
346 if constexpr (Op == operation::writev) {
349 if constexpr (Op == operation::fdatasync) {
352 if constexpr (Op == operation::accept) {
355 if constexpr (Op == operation::connect) {
358 if constexpr (Op == operation::poll_add) {
361 if constexpr (Op == operation::poll_remove) {
364 if constexpr (Op == operation::cancel) {
370 std::vector<part> split(
size_t max_length);
373 io_request sub_req_buffer(
size_t pos,
size_t len)
const {
378 auto& sub_op = sub_req._read;
381 .nowait_works = op.nowait_works,
384 .addr = op.addr + pos,
389 std::vector<part> split_buffer(
size_t max_length);
391 io_request sub_req_iovec(
size_t pos, std::vector<iovec>& iov)
const {
396 auto& sub_op = sub_req._readv;
399 .nowait_works = op.nowait_works,
403 .iov_len = iov.size(),
407 std::vector<part> split_iovec(
size_t max_length);
410struct io_request::part {
413 std::vector<::iovec> iovecs;
417struct io_direction_and_length {
418 size_t _directed_length;
421 size_t length() const noexcept {
return _directed_length >> 1; }
422 int rw_idx() const noexcept {
return _directed_length & 0x1; }
423 static constexpr int read_idx = 1;
424 static constexpr int write_idx = 0;
426 io_direction_and_length(
int idx,
size_t val) noexcept
427 : _directed_length((val << 1) | idx)
429 assert(idx == read_idx || idx == write_idx);
future< connected_socket > connect(socket_address sa)
Seastar API namespace.
Definition: abort_on_ebadf.hh:26