Condy v1.3.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
async_operations.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
12#include "condy/concepts.hpp"
13#include "condy/condy_uring.hpp"
14#include "condy/helpers.hpp"
16
17namespace condy {
18
19namespace detail {
20
21template <AwaiterLike Awaiter>
22auto maybe_flag_fixed_fd(Awaiter &&op, const FixedFd &) {
23 return flag<IOSQE_FIXED_FILE>(std::forward<Awaiter>(op));
24}
25
26template <AwaiterLike Awaiter> auto maybe_flag_fixed_fd(Awaiter &&op, int) {
27 return std::forward<Awaiter>(op);
28}
29
30template <typename Fd>
31constexpr bool is_fixed_fd_v = std::is_same_v<std::decay_t<Fd>, FixedFd>;
32
33} // namespace detail
34
38template <FdLike Fd1, FdLike Fd2>
39inline auto async_splice(Fd1 fd_in, int64_t off_in, Fd2 fd_out, int64_t off_out,
40 unsigned int nbytes, unsigned int splice_flags) {
41 if constexpr (detail::is_fixed_fd_v<Fd1>) {
42 splice_flags |= SPLICE_F_FD_IN_FIXED;
43 }
44 auto op = make_op_awaiter(io_uring_prep_splice, fd_in, off_in, fd_out,
45 off_out, nbytes, splice_flags);
46 return detail::maybe_flag_fixed_fd(std::move(op), fd_out);
47}
48
52template <FdLike Fd1, FdLike Fd2>
53inline auto async_tee(Fd1 fd_in, Fd2 fd_out, unsigned int nbytes,
54 unsigned int splice_flags) {
55 if constexpr (detail::is_fixed_fd_v<Fd1>) {
56 splice_flags |= SPLICE_F_FD_IN_FIXED;
57 }
58 auto op =
59 make_op_awaiter(io_uring_prep_tee, fd_in, fd_out, nbytes, splice_flags);
60 return detail::maybe_flag_fixed_fd(std::move(op), fd_out);
61}
62
66template <FdLike Fd>
67inline auto async_readv(Fd fd, const struct iovec *iovecs, unsigned nr_vecs,
68 __u64 offset, int flags) {
69 auto op = make_op_awaiter(io_uring_prep_readv2, fd, iovecs, nr_vecs, offset,
70 flags);
71 return detail::maybe_flag_fixed_fd(std::move(op), fd);
72}
73
74#if !IO_URING_CHECK_VERSION(2, 10) // >= 2.10
78template <FdLike Fd>
79inline auto async_readv(Fd fd, detail::FixedBuffer<const iovec *> iovecs,
80 unsigned nr_vecs, __u64 offset, int flags) {
81 auto op = make_op_awaiter(io_uring_prep_readv_fixed, fd, iovecs.value,
82 nr_vecs, offset, flags, iovecs.buf_index);
83 return detail::maybe_flag_fixed_fd(std::move(op), fd);
84}
85#endif
86
87template <FdLike Fd>
91inline auto async_writev(Fd fd, const struct iovec *iovecs,
92 unsigned int nr_vecs, __u64 offset, int flags) {
93 auto op = make_op_awaiter(io_uring_prep_writev2, fd, iovecs, nr_vecs,
94 offset, flags);
95 return detail::maybe_flag_fixed_fd(std::move(op), fd);
96}
97
98#if !IO_URING_CHECK_VERSION(2, 10) // >= 2.10
102template <FdLike Fd>
103inline auto async_writev(Fd fd, detail::FixedBuffer<const iovec *> iovecs,
104 unsigned int nr_vecs, __u64 offset, int flags) {
105 auto op = make_op_awaiter(io_uring_prep_writev_fixed, fd, iovecs.value,
106 nr_vecs, offset, flags, iovecs.buf_index);
107 return detail::maybe_flag_fixed_fd(std::move(op), fd);
108}
109#endif
110
114template <FdLike Fd>
115inline auto async_recvmsg(Fd fd, struct msghdr *msg, unsigned flags) {
116 auto op = make_op_awaiter(io_uring_prep_recvmsg, fd, msg, flags);
117 return detail::maybe_flag_fixed_fd(std::move(op), fd);
118}
119
123template <FdLike Fd, typename MultiShotFunc, NotBundledBufferRing Buffer>
124inline auto async_recvmsg_multishot(Fd fd, struct msghdr *msg, unsigned flags,
125 Buffer &buf, MultiShotFunc &&func) {
127 std::forward<MultiShotFunc>(func), &buf,
128 io_uring_prep_recvmsg_multishot, fd, msg, flags);
129 return detail::maybe_flag_fixed_fd(std::move(op), fd);
130}
131
135template <FdLike Fd>
136inline auto async_sendmsg(Fd fd, const struct msghdr *msg, unsigned flags) {
137 auto op = make_op_awaiter(io_uring_prep_sendmsg, fd, msg, flags);
138 return detail::maybe_flag_fixed_fd(std::move(op), fd);
139}
140
144template <FdLike Fd, typename FreeFunc>
145inline auto async_sendmsg_zc(Fd fd, const struct msghdr *msg, unsigned flags,
146 FreeFunc &&func) {
148 std::forward<FreeFunc>(func), io_uring_prep_sendmsg_zc, fd, msg, flags);
149 return detail::maybe_flag_fixed_fd(std::move(op), fd);
150}
151
152#if !IO_URING_CHECK_VERSION(2, 10) // >= 2.10
156template <FdLike Fd, typename FreeFunc>
157inline auto async_sendmsg_zc(Fd fd, detail::FixedBuffer<const msghdr *> msg,
158 unsigned flags, FreeFunc &&func) {
159 auto op = make_zero_copy_op_awaiter(std::forward<FreeFunc>(func),
160 io_uring_prep_sendmsg_zc_fixed, fd,
161 msg.value, flags, msg.buf_index);
162 return detail::maybe_flag_fixed_fd(std::move(op), fd);
163}
164#endif
165
169template <FdLike Fd> inline auto async_fsync(Fd fd, unsigned fsync_flags) {
170 auto op = make_op_awaiter(io_uring_prep_fsync, fd, fsync_flags);
171 return detail::maybe_flag_fixed_fd(std::move(op), fd);
172}
173
177inline auto async_nop() { return make_op_awaiter(io_uring_prep_nop); }
178
179#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
183inline auto async_nop128() { return make_op_awaiter128(io_uring_prep_nop128); }
184#endif
185
189inline auto async_timeout(struct __kernel_timespec *ts, unsigned count,
190 unsigned flags) {
191 return make_op_awaiter(io_uring_prep_timeout, ts, count, flags);
192}
193
194#if !IO_URING_CHECK_VERSION(2, 4) // >= 2.4
195
199template <typename MultiShotFunc>
200inline auto async_timeout_multishot(struct __kernel_timespec *ts,
201 unsigned count, unsigned flags,
202 MultiShotFunc &&func) {
203 return make_multishot_op_awaiter(std::forward<MultiShotFunc>(func),
204 io_uring_prep_timeout, ts, count,
205 flags | IORING_TIMEOUT_MULTISHOT);
206}
207#endif
208
212template <FdLike Fd>
213inline auto async_accept(Fd fd, struct sockaddr *addr, socklen_t *addrlen,
214 int flags) {
215 auto op = make_op_awaiter(io_uring_prep_accept, fd, addr, addrlen, flags);
216 return detail::maybe_flag_fixed_fd(std::move(op), fd);
217}
218
222template <FdLike Fd>
223inline auto async_accept_direct(Fd fd, struct sockaddr *addr,
224 socklen_t *addrlen, int flags,
225 unsigned int file_index) {
226 auto op = make_op_awaiter(io_uring_prep_accept_direct, fd, addr, addrlen,
227 flags, file_index);
228 return detail::maybe_flag_fixed_fd(std::move(op), fd);
229}
230
234template <FdLike Fd, typename MultiShotFunc>
235inline auto async_multishot_accept(Fd fd, struct sockaddr *addr,
236 socklen_t *addrlen, int flags,
237 MultiShotFunc &&func) {
238 auto op = make_multishot_op_awaiter(std::forward<MultiShotFunc>(func),
239 io_uring_prep_multishot_accept, fd,
240 addr, addrlen, flags);
241 return detail::maybe_flag_fixed_fd(std::move(op), fd);
242}
243
247template <FdLike Fd, typename MultiShotFunc>
248inline auto async_multishot_accept_direct(Fd fd, struct sockaddr *addr,
249 socklen_t *addrlen, int flags,
250 MultiShotFunc &&func) {
251 auto op = make_multishot_op_awaiter(std::forward<MultiShotFunc>(func),
252 io_uring_prep_multishot_accept_direct,
253 fd, addr, addrlen, flags);
254 return detail::maybe_flag_fixed_fd(std::move(op), fd);
255}
256
260template <FdLike Fd> inline auto async_cancel_fd(Fd fd, unsigned int flags) {
261 if constexpr (detail::is_fixed_fd_v<Fd>) {
262 flags |= IORING_ASYNC_CANCEL_FD_FIXED;
263 }
264 return make_op_awaiter(io_uring_prep_cancel_fd, fd, flags);
265}
266
270inline auto async_link_timeout(struct __kernel_timespec *ts, unsigned flags) {
271 return make_op_awaiter(io_uring_prep_link_timeout, ts, flags);
272}
273
277template <FdLike Fd>
278inline auto async_connect(Fd fd, const struct sockaddr *addr,
279 socklen_t addrlen) {
280 auto op = make_op_awaiter(io_uring_prep_connect, fd, addr, addrlen);
281 return detail::maybe_flag_fixed_fd(std::move(op), fd);
282}
283
287inline auto async_files_update(int *fds, unsigned nr_fds, int offset) {
288 return make_op_awaiter(io_uring_prep_files_update, fds, nr_fds, offset);
289}
290
294template <FdLike Fd>
295inline auto async_fallocate(Fd fd, int mode, __u64 offset, __u64 len) {
296 auto op = make_op_awaiter(io_uring_prep_fallocate, fd, mode, offset, len);
297 return detail::maybe_flag_fixed_fd(std::move(op), fd);
298}
299
303inline auto async_openat(int dfd, const char *path, int flags, mode_t mode) {
304 return make_op_awaiter(io_uring_prep_openat, dfd, path, flags, mode);
305}
306
310inline auto async_openat_direct(int dfd, const char *path, int flags,
311 mode_t mode, unsigned file_index) {
312 return make_op_awaiter(io_uring_prep_openat_direct, dfd, path, flags, mode,
313 file_index);
314}
315
319inline auto async_open(const char *path, int flags, mode_t mode) {
320 return async_openat(AT_FDCWD, path, flags, mode);
321}
322
326inline auto async_open_direct(const char *path, int flags, mode_t mode,
327 unsigned file_index) {
328 return async_openat_direct(AT_FDCWD, path, flags, mode, file_index);
329}
330
334inline auto async_close(int fd) {
335 return make_op_awaiter(io_uring_prep_close, fd);
336}
337
341inline auto async_close(detail::FixedFd fd) {
342 return make_op_awaiter(io_uring_prep_close_direct, fd);
343}
344
348template <FdLike Fd, BufferLike Buffer>
349inline auto async_read(Fd fd, Buffer &&buf, __u64 offset) {
350 auto op =
351 make_op_awaiter(io_uring_prep_read, fd, buf.data(), buf.size(), offset);
352 return detail::maybe_flag_fixed_fd(std::move(op), fd);
353}
354
358template <FdLike Fd, BufferLike Buffer>
359inline auto async_read(Fd fd, detail::FixedBuffer<Buffer> buf, __u64 offset) {
360 auto op = make_op_awaiter(io_uring_prep_read_fixed, fd, buf.value.data(),
361 buf.value.size(), offset, buf.buf_index);
362 return detail::maybe_flag_fixed_fd(std::move(op), fd);
363}
364
368template <FdLike Fd, NotBundledBufferRing Buffer>
369inline auto async_read(Fd fd, Buffer &buf, __u64 offset) {
370 auto op = make_select_buffer_op_awaiter(&buf, io_uring_prep_read, fd,
371 nullptr, 0, offset);
372 return detail::maybe_flag_fixed_fd(std::move(op), fd);
373}
374
375#if !IO_URING_CHECK_VERSION(2, 6) // >= 2.6
379template <FdLike Fd, NotBundledBufferRing Buffer, typename MultiShotFunc>
380inline auto async_read_multishot(Fd fd, Buffer &buf, __u64 offset,
381 MultiShotFunc &&func) {
383 std::forward<MultiShotFunc>(func), &buf, io_uring_prep_read_multishot,
384 fd, 0, offset, buf.bgid());
385 return detail::maybe_flag_fixed_fd(std::move(op), fd);
386}
387#endif
388
392template <FdLike Fd, BufferLike Buffer>
393inline auto async_write(Fd fd, Buffer &&buf, __u64 offset) {
394 auto op = make_op_awaiter(io_uring_prep_write, fd, buf.data(), buf.size(),
395 offset);
396 return detail::maybe_flag_fixed_fd(std::move(op), fd);
397}
398
402template <FdLike Fd, BufferLike Buffer>
403inline auto async_write(Fd fd, detail::FixedBuffer<Buffer> buf, __u64 offset) {
404 auto op = make_op_awaiter(io_uring_prep_write_fixed, fd, buf.value.data(),
405 buf.value.size(), offset, buf.buf_index);
406 return detail::maybe_flag_fixed_fd(std::move(op), fd);
407}
408
412inline auto async_statx(int dfd, const char *path, int flags, unsigned mask,
413 struct statx *statxbuf) {
414 return make_op_awaiter(io_uring_prep_statx, dfd, path, flags, mask,
415 statxbuf);
416}
417
421template <FdLike Fd>
422inline auto async_fadvise(Fd fd, __u64 offset, off_t len, int advice) {
423 auto op = make_op_awaiter(io_uring_prep_fadvise, fd, offset, len, advice);
424 return detail::maybe_flag_fixed_fd(std::move(op), fd);
425}
426
427#if !IO_URING_CHECK_VERSION(2, 7) // >= 2.7
431template <FdLike Fd>
432inline auto async_fadvise64(Fd fd, __u64 offset, off_t len, int advice) {
433 auto op = make_op_awaiter(io_uring_prep_fadvise64, fd, offset, len, advice);
434 return detail::maybe_flag_fixed_fd(std::move(op), fd);
435}
436#endif
437
441inline auto async_madvise(void *addr, __u32 length, int advice) {
442 return make_op_awaiter(io_uring_prep_madvise, addr, length, advice);
443}
444
445#if !IO_URING_CHECK_VERSION(2, 7) // >= 2.7
449inline auto async_madvise64(void *addr, off_t length, int advice) {
450 auto op = make_op_awaiter(io_uring_prep_madvise64, addr, length, advice);
451 return op;
452}
453#endif
454
455namespace detail {
456
457inline void prep_sendto(io_uring_sqe *sqe, int sockfd, const void *buf,
458 size_t len, int flags, const struct sockaddr *addr,
459 socklen_t addrlen) {
460 io_uring_prep_send(sqe, sockfd, buf, len, flags);
461 io_uring_prep_send_set_addr(sqe, addr, addrlen);
462}
463
464inline void prep_send_fixed(io_uring_sqe *sqe, int sockfd, const void *buf,
465 size_t len, int flags, int buf_index) {
466 io_uring_prep_send(sqe, sockfd, buf, len, flags);
467 sqe->ioprio |= IORING_RECVSEND_FIXED_BUF;
468 sqe->buf_index = buf_index;
469}
470
471inline void prep_sendto_fixed(io_uring_sqe *sqe, int sockfd, const void *buf,
472 size_t len, int flags,
473 const struct sockaddr *addr, socklen_t addrlen,
474 int buf_index) {
475 prep_sendto(sqe, sockfd, buf, len, flags, addr, addrlen);
476 sqe->ioprio |= IORING_RECVSEND_FIXED_BUF;
477 sqe->buf_index = buf_index;
478}
479
480inline void prep_sendto_zc(io_uring_sqe *sqe, int sockfd, const void *buf,
481 size_t len, int flags, const struct sockaddr *addr,
482 socklen_t addrlen, unsigned zc_flags) {
483 io_uring_prep_send_zc(sqe, sockfd, buf, len, flags, zc_flags);
484 io_uring_prep_send_set_addr(sqe, addr, addrlen);
485}
486
487inline void prep_sendto_zc_fixed(io_uring_sqe *sqe, int sockfd, const void *buf,
488 size_t len, int flags,
489 const struct sockaddr *addr, socklen_t addrlen,
490 unsigned zc_flags, int buf_index) {
491 prep_sendto_zc(sqe, sockfd, buf, len, flags, addr, addrlen, zc_flags);
492 sqe->ioprio |= IORING_RECVSEND_FIXED_BUF;
493 sqe->buf_index = buf_index;
494}
495
496} // namespace detail
497
501template <FdLike Fd, BufferLike Buffer>
502inline auto async_send(Fd sockfd, Buffer &&buf, int flags) {
503 auto op = make_op_awaiter(io_uring_prep_send, sockfd, buf.data(),
504 buf.size(), flags);
505 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
506}
507
511template <FdLike Fd>
512inline auto async_send(Fd sockfd, ProvidedBufferQueue &buf, int flags) {
513 auto op = make_select_buffer_op_awaiter(&buf, io_uring_prep_send, sockfd,
514 nullptr, 0, flags);
515 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
516}
517
518#if !IO_URING_CHECK_VERSION(2, 7) // >= 2.7
522template <FdLike Fd>
523inline auto async_send(Fd sockfd, BundledProvidedBufferQueue &buf, int flags) {
524 auto op = make_bundle_select_buffer_op_awaiter(&buf, io_uring_prep_send,
525 sockfd, nullptr, 0, flags);
526 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
527}
528#endif
529
533template <FdLike Fd, BufferLike Buffer>
534inline auto async_sendto(Fd sockfd, Buffer &&buf, int flags,
535 const struct sockaddr *addr, socklen_t addrlen) {
536 auto op = make_op_awaiter(detail::prep_sendto, sockfd, buf.data(),
537 buf.size(), flags, addr, addrlen);
538 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
539}
540
544template <FdLike Fd>
545inline auto async_sendto(Fd sockfd, ProvidedBufferQueue &buf, int flags,
546 const struct sockaddr *addr, socklen_t addrlen) {
547 auto op = make_select_buffer_op_awaiter(&buf, detail::prep_sendto, sockfd,
548 nullptr, 0, flags, addr, addrlen);
549 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
550}
551
552#if !IO_URING_CHECK_VERSION(2, 7) // >= 2.7
556template <FdLike Fd>
557inline auto async_sendto(Fd sockfd, BundledProvidedBufferQueue &buf, int flags,
558 const struct sockaddr *addr, socklen_t addrlen) {
560 &buf, detail::prep_sendto, sockfd, nullptr, 0, flags, addr, addrlen);
561 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
562}
563#endif
564
568template <FdLike Fd, typename Buffer, typename FreeFunc>
569inline auto async_send_zc(Fd sockfd, Buffer &&buf, int flags, unsigned zc_flags,
570 FreeFunc &&func) {
572 std::forward<FreeFunc>(func), io_uring_prep_send_zc, sockfd, buf.data(),
573 buf.size(), flags, zc_flags);
574 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
575}
576
580template <FdLike Fd, BufferLike Buffer, typename FreeFunc>
581inline auto async_send_zc(Fd sockfd, detail::FixedBuffer<Buffer> buf, int flags,
582 unsigned zc_flags, FreeFunc &&func) {
584 std::forward<FreeFunc>(func), io_uring_prep_send_zc_fixed, sockfd,
585 buf.value.data(), buf.value.size(), flags, zc_flags, buf.buf_index);
586 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
587}
588
592template <FdLike Fd, BufferLike Buffer, typename FreeFunc>
593inline auto async_sendto_zc(Fd sockfd, Buffer &&buf, int flags,
594 const struct sockaddr *addr, socklen_t addrlen,
595 unsigned zc_flags, FreeFunc &&func) {
597 std::forward<FreeFunc>(func), detail::prep_sendto_zc, sockfd,
598 buf.data(), buf.size(), flags, addr, addrlen, zc_flags);
599 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
600}
601
605template <FdLike Fd, BufferLike Buffer, typename FreeFunc>
606inline auto async_sendto_zc(Fd sockfd, detail::FixedBuffer<Buffer> buf,
607 int flags, const struct sockaddr *addr,
608 socklen_t addrlen, unsigned zc_flags,
609 FreeFunc &&func) {
611 std::forward<FreeFunc>(func), detail::prep_sendto_zc_fixed, sockfd,
612 buf.value.data(), buf.value.size(), flags, addr, addrlen, zc_flags,
613 buf.buf_index);
614 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
615}
616
620template <FdLike Fd, BufferLike Buffer>
621inline auto async_recv(Fd sockfd, Buffer &&buf, int flags) {
622 auto op = make_op_awaiter(io_uring_prep_recv, sockfd, buf.data(),
623 buf.size(), flags);
624 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
625}
626
630template <FdLike Fd, NotBundledBufferRing Buffer>
631inline auto async_recv(Fd sockfd, Buffer &buf, int flags) {
632 auto op = make_select_buffer_op_awaiter(&buf, io_uring_prep_recv, sockfd,
633 nullptr, 0, flags);
634 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
635}
636
637#if !IO_URING_CHECK_VERSION(2, 7) // >= 2.7
641template <FdLike Fd, BundledBufferRing Buffer>
642inline auto async_recv(Fd sockfd, Buffer &buf, int flags) {
643 auto op = make_bundle_select_buffer_op_awaiter(&buf, io_uring_prep_recv,
644 sockfd, nullptr, 0, flags);
645 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
646}
647#endif
648
652template <FdLike Fd, NotBundledBufferRing Buffer, typename MultiShotFunc>
653inline auto async_recv_multishot(Fd sockfd, Buffer &buf, int flags,
654 MultiShotFunc &&func) {
656 std::forward<MultiShotFunc>(func), &buf, io_uring_prep_recv_multishot,
657 sockfd, nullptr, 0, flags);
658 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
659}
660
661#if !IO_URING_CHECK_VERSION(2, 7) // >= 2.7
665template <FdLike Fd, BundledBufferRing Buffer, typename MultiShotFunc>
666inline auto async_recv_multishot(Fd sockfd, Buffer &buf, int flags,
667 MultiShotFunc &&func) {
669 std::forward<MultiShotFunc>(func), &buf, io_uring_prep_recv_multishot,
670 sockfd, nullptr, 0, flags);
671 return detail::maybe_flag_fixed_fd(std::move(op), sockfd);
672}
673#endif
674
678inline auto async_openat2(int dfd, const char *path, struct open_how *how) {
679 return make_op_awaiter(io_uring_prep_openat2, dfd, path, how);
680}
681
685inline auto async_openat2_direct(int dfd, const char *path,
686 struct open_how *how, unsigned file_index) {
687 return make_op_awaiter(io_uring_prep_openat2_direct, dfd, path, how,
688 file_index);
689}
690
694template <FdLike Fd> inline auto async_shutdown(Fd fd, int how) {
695 auto op = make_op_awaiter(io_uring_prep_shutdown, fd, how);
696 return detail::maybe_flag_fixed_fd(std::move(op), fd);
697}
698
702inline auto async_unlinkat(int dfd, const char *path, int flags) {
703 return make_op_awaiter(io_uring_prep_unlinkat, dfd, path, flags);
704}
705
709inline auto async_unlink(const char *path, int flags) {
710 return async_unlinkat(AT_FDCWD, path, flags);
711}
712
716inline auto async_renameat(int olddfd, const char *oldpath, int newdfd,
717 const char *newpath, unsigned int flags) {
718 return make_op_awaiter(io_uring_prep_renameat, olddfd, oldpath, newdfd,
719 newpath, flags);
720}
721
725inline auto async_rename(const char *oldpath, const char *newpath) {
726 return async_renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0);
727}
728
732template <FdLike Fd>
733inline auto async_sync_file_range(Fd fd, unsigned len, __u64 offset,
734 int flags) {
735 auto op =
736 make_op_awaiter(io_uring_prep_sync_file_range, fd, len, offset, flags);
737 return detail::maybe_flag_fixed_fd(std::move(op), fd);
738}
739
743inline auto async_mkdirat(int dfd, const char *path, mode_t mode) {
744 return make_op_awaiter(io_uring_prep_mkdirat, dfd, path, mode);
745}
746
750inline auto async_mkdir(const char *path, mode_t mode) {
751 return async_mkdirat(AT_FDCWD, path, mode);
752}
753
757inline auto async_symlinkat(const char *target, int newdirfd,
758 const char *linkpath) {
759 return make_op_awaiter(io_uring_prep_symlinkat, target, newdirfd, linkpath);
760}
761
765inline auto async_symlink(const char *target, const char *linkpath) {
766 return async_symlinkat(target, AT_FDCWD, linkpath);
767}
768
772inline auto async_linkat(int olddfd, const char *oldpath, int newdfd,
773 const char *newpath, int flags) {
774 return make_op_awaiter(io_uring_prep_linkat, olddfd, oldpath, newdfd,
775 newpath, flags);
776}
777
781inline auto async_link(const char *oldpath, const char *newpath, int flags) {
782 return async_linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, flags);
783}
784
788inline auto async_getxattr(const char *name, char *value, const char *path,
789 unsigned int len) {
790 return make_op_awaiter(io_uring_prep_getxattr, name, value, path, len);
791}
792
796inline auto async_setxattr(const char *name, const char *value,
797 const char *path, int flags, unsigned int len) {
798 return make_op_awaiter(io_uring_prep_setxattr, name, value, path, flags,
799 len);
800}
801
805inline auto async_fgetxattr(int fd, const char *name, char *value,
806 unsigned int len) {
807 return make_op_awaiter(io_uring_prep_fgetxattr, fd, name, value, len);
808}
809
813inline auto async_fsetxattr(int fd, const char *name, const char *value,
814 int flags, unsigned int len) {
815 return make_op_awaiter(io_uring_prep_fsetxattr, fd, name, value, flags,
816 len);
817}
818
822inline auto async_socket(int domain, int type, int protocol,
823 unsigned int flags) {
824 return make_op_awaiter(io_uring_prep_socket, domain, type, protocol, flags);
825}
826
830inline auto async_socket_direct(int domain, int type, int protocol,
831 unsigned file_index, unsigned int flags) {
832 return make_op_awaiter(io_uring_prep_socket_direct, domain, type, protocol,
833 file_index, flags);
834}
835
836#if !IO_URING_CHECK_VERSION(2, 5) // >= 2.5
840template <FdLike Fd>
841inline auto async_cmd_sock(int cmd_op, Fd fd, int level, int optname,
842 void *optval, int optlen) {
843 auto op = make_op_awaiter(io_uring_prep_cmd_sock, cmd_op, fd, level,
844 optname, optval, optlen);
845 return detail::maybe_flag_fixed_fd(std::move(op), fd);
846}
847#endif
848
849#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
853template <FdLike Fd>
854inline auto async_cmd_getsockname(Fd fd, struct sockaddr *sockaddr,
855 socklen_t *sockaddr_len, int peer) {
856 auto op = make_op_awaiter(io_uring_prep_cmd_getsockname, fd, sockaddr,
857 sockaddr_len, peer);
858 return detail::maybe_flag_fixed_fd(std::move(op), fd);
859}
860#endif
861
862#if !IO_URING_CHECK_VERSION(2, 6) // >= 2.6
866inline auto async_waitid(idtype_t idtype, id_t id, siginfo_t *infop,
867 int options, unsigned int flags) {
868 return make_op_awaiter(io_uring_prep_waitid, idtype, id, infop, options,
869 flags);
870}
871#endif
872
873#if !IO_URING_CHECK_VERSION(2, 6) // >= 2.6
877inline auto async_futex_wake(uint32_t *futex, uint64_t val, uint64_t mask,
878 uint32_t futex_flags, unsigned int flags) {
879 return make_op_awaiter(io_uring_prep_futex_wake, futex, val, mask,
880 futex_flags, flags);
881}
882#endif
883
884#if !IO_URING_CHECK_VERSION(2, 6) // >= 2.6
888inline auto async_futex_wait(uint32_t *futex, uint64_t val, uint64_t mask,
889 uint32_t futex_flags, unsigned int flags) {
890 return make_op_awaiter(io_uring_prep_futex_wait, futex, val, mask,
891 futex_flags, flags);
892}
893#endif
894
895#if !IO_URING_CHECK_VERSION(2, 6) // >= 2.6
899inline auto async_futex_waitv(struct futex_waitv *futex, uint32_t nr_futex,
900 unsigned int flags) {
901 return make_op_awaiter(io_uring_prep_futex_waitv, futex, nr_futex, flags);
902}
903#endif
904
905#if !IO_URING_CHECK_VERSION(2, 6) // >= 2.6
909inline auto async_fixed_fd_install(int fixed_fd, unsigned int flags) {
910 return make_op_awaiter(io_uring_prep_fixed_fd_install, fixed_fd, flags);
911}
912#endif
913
914#if !IO_URING_CHECK_VERSION(2, 4) // >= 2.4
918inline auto async_fixed_fd_send(FdTable &dst, int source_fd, int target_fd,
919 unsigned int flags) {
920 void *payload = nullptr;
921 if (static_cast<unsigned int>(target_fd) != CONDY_FILE_INDEX_ALLOC) {
922 // NOLINTNEXTLINE(performance-no-int-to-ptr)
923 payload = reinterpret_cast<void *>((target_fd + 1) << 3);
924 }
925 return make_op_awaiter(
926 io_uring_prep_msg_ring_fd, dst.ring_.ring_fd, source_fd, target_fd,
927 reinterpret_cast<uint64_t>(encode_work(payload, WorkType::SendFd)),
928 flags);
929}
930#endif
931
932#if !IO_URING_CHECK_VERSION(2, 6) // >= 2.6
936template <FdLike Fd> inline auto async_ftruncate(Fd fd, loff_t len) {
937 auto op = make_op_awaiter(io_uring_prep_ftruncate, fd, len);
938 return detail::maybe_flag_fixed_fd(std::move(op), fd);
939}
940#endif
941
942#if !IO_URING_CHECK_VERSION(2, 8) // >= 2.8
946template <FdLike Fd>
947inline auto async_cmd_discard(Fd fd, uint64_t offset, uint64_t nbytes) {
948 auto op = make_op_awaiter(io_uring_prep_cmd_discard, fd, offset, nbytes);
949 return detail::maybe_flag_fixed_fd(std::move(op), fd);
950}
951#endif
952
953#if !IO_URING_CHECK_VERSION(2, 7) // >= 2.7
957template <FdLike Fd>
958inline auto async_bind(Fd fd, struct sockaddr *addr, socklen_t addrlen) {
959 auto op = make_op_awaiter(io_uring_prep_bind, fd, addr, addrlen);
960 return detail::maybe_flag_fixed_fd(std::move(op), fd);
961}
962#endif
963
964#if !IO_URING_CHECK_VERSION(2, 7) // >= 2.7
968template <FdLike Fd> inline auto async_listen(Fd fd, int backlog) {
969 auto op = make_op_awaiter(io_uring_prep_listen, fd, backlog);
970 return detail::maybe_flag_fixed_fd(std::move(op), fd);
971}
972#endif
973
977inline auto async_epoll_ctl(int epfd, int fd, int op, struct epoll_event *ev) {
978 return make_op_awaiter(io_uring_prep_epoll_ctl, epfd, fd, op, ev);
979}
980
981#if !IO_URING_CHECK_VERSION(2, 10) // >= 2.10
985inline auto async_epoll_wait(int fd, struct epoll_event *events, int maxevents,
986 unsigned flags) {
987 return make_op_awaiter(io_uring_prep_epoll_wait, fd, events, maxevents,
988 flags);
989}
990#endif
991
992#if !IO_URING_CHECK_VERSION(2, 12) // >= 2.12
996inline auto async_pipe(int *fds, int pipe_flags) {
997 return make_op_awaiter(io_uring_prep_pipe, fds, pipe_flags);
998}
999#endif
1000
1001#if !IO_URING_CHECK_VERSION(2, 12) // >= 2.12
1005inline auto async_pipe_direct(int *fds, int pipe_flags,
1006 unsigned int file_index) {
1007 return make_op_awaiter(io_uring_prep_pipe_direct, fds, pipe_flags,
1008 file_index);
1009}
1010#endif
1011
1012} // namespace condy
Helper functions for composing asynchronous operations.
Helper functions for asynchronous operations.
#define CONDY_FILE_INDEX_ALLOC
Placeholder to let io_uring allocate a direct file descriptor.
Definition helpers.hpp:20
The main namespace for the Condy library.
Definition condy.hpp:28
auto async_read_multishot(Fd fd, Buffer &buf, __u64 offset, MultiShotFunc &&func)
See io_uring_prep_read_multishot.
auto make_multishot_select_buffer_op_awaiter(MultiShotFunc &&multishot_func, Br *buffers, Func &&func, Args &&...args)
This function creates a variant of OpAwaiter. OpAwaiter represents an asynchronous operation that can...
auto async_symlinkat(const char *target, int newdirfd, const char *linkpath)
See io_uring_prep_symlinkat.
auto make_op_awaiter(Func &&func, Args &&...args)
This function creates a variant of OpAwaiter. OpAwaiter represents an asynchronous operation that can...
auto async_splice(Fd1 fd_in, int64_t off_in, Fd2 fd_out, int64_t off_out, unsigned int nbytes, unsigned int splice_flags)
See io_uring_prep_splice.
auto async_fsetxattr(int fd, const char *name, const char *value, int flags, unsigned int len)
See io_uring_prep_fsetxattr.
auto async_fadvise(Fd fd, __u64 offset, off_t len, int advice)
See io_uring_prep_fadvise.
auto async_writev(Fd fd, const struct iovec *iovecs, unsigned int nr_vecs, __u64 offset, int flags)
See io_uring_prep_writev2.
auto async_fixed_fd_install(int fixed_fd, unsigned int flags)
See io_uring_prep_fixed_fd_install.
auto make_bundle_select_buffer_op_awaiter(Br *buffers, Func &&func, Args &&...args)
This function creates a variant of OpAwaiter. OpAwaiter represents an asynchronous operation that can...
auto async_socket_direct(int domain, int type, int protocol, unsigned file_index, unsigned int flags)
See io_uring_prep_socket_direct.
auto async_madvise64(void *addr, off_t length, int advice)
See io_uring_prep_madvise64.
auto async_fsync(Fd fd, unsigned fsync_flags)
See io_uring_prep_fsync.
auto async_cmd_getsockname(Fd fd, struct sockaddr *sockaddr, socklen_t *sockaddr_len, int peer)
See io_uring_prep_cmd_getsockname.
auto async_ftruncate(Fd fd, loff_t len)
See io_uring_prep_ftruncate.
auto async_recvmsg(Fd fd, struct msghdr *msg, unsigned flags)
See io_uring_prep_recvmsg.
auto async_openat2(int dfd, const char *path, struct open_how *how)
See io_uring_prep_openat2.
auto async_nop128()
See io_uring_prep_nop128.
auto async_open_direct(const char *path, int flags, mode_t mode, unsigned file_index)
See io_uring_prep_openat_direct.
auto async_write(Fd fd, Buffer &&buf, __u64 offset)
See io_uring_prep_write.
auto async_getxattr(const char *name, char *value, const char *path, unsigned int len)
See io_uring_prep_getxattr.
auto async_unlinkat(int dfd, const char *path, int flags)
See io_uring_prep_unlinkat.
auto make_multishot_op_awaiter(MultiShotFunc &&multishot_func, Func &&func, Args &&...args)
This function creates a variant of OpAwaiter. OpAwaiter represents an asynchronous operation that can...
auto async_openat_direct(int dfd, const char *path, int flags, mode_t mode, unsigned file_index)
See io_uring_prep_openat_direct.
auto async_epoll_ctl(int epfd, int fd, int op, struct epoll_event *ev)
See io_uring_prep_epoll_ctl.
auto async_mkdir(const char *path, mode_t mode)
See io_uring_prep_mkdirat.
auto async_fgetxattr(int fd, const char *name, char *value, unsigned int len)
See io_uring_prep_fgetxattr.
auto async_statx(int dfd, const char *path, int flags, unsigned mask, struct statx *statxbuf)
See io_uring_prep_statx.
auto async_sendto_zc(Fd sockfd, Buffer &&buf, int flags, const struct sockaddr *addr, socklen_t addrlen, unsigned zc_flags, FreeFunc &&func)
See io_uring_prep_send_zc and io_uring_prep_send_set_addr.
auto make_zero_copy_op_awaiter(FreeFunc &&free_func, Func &&func, Args &&...args)
This function creates a variant of OpAwaiter. OpAwaiter represents an asynchronous operation that can...
auto async_cmd_discard(Fd fd, uint64_t offset, uint64_t nbytes)
See io_uring_prep_cmd_discard.
auto async_link(const char *oldpath, const char *newpath, int flags)
See io_uring_prep_linkat.
auto async_multishot_accept_direct(Fd fd, struct sockaddr *addr, socklen_t *addrlen, int flags, MultiShotFunc &&func)
See io_uring_prep_multishot_accept_direct.
auto async_sendto(Fd sockfd, Buffer &&buf, int flags, const struct sockaddr *addr, socklen_t addrlen)
See io_uring_prep_send and io_uring_prep_send_set_addr.
auto async_futex_wake(uint32_t *futex, uint64_t val, uint64_t mask, uint32_t futex_flags, unsigned int flags)
See io_uring_prep_futex_wake.
auto make_op_awaiter128(Func &&func, Args &&...args)
This function creates a variant of OpAwaiter. OpAwaiter represents an asynchronous operation that can...
auto async_recv_multishot(Fd sockfd, Buffer &buf, int flags, MultiShotFunc &&func)
See io_uring_prep_recv_multishot.
auto async_recv(Fd sockfd, Buffer &&buf, int flags)
See io_uring_prep_recv.
auto async_multishot_accept(Fd fd, struct sockaddr *addr, socklen_t *addrlen, int flags, MultiShotFunc &&func)
See io_uring_prep_multishot_accept.
auto make_select_buffer_op_awaiter(Br *buffers, Func &&func, Args &&...args)
This function creates a variant of OpAwaiter. OpAwaiter represents an asynchronous operation that can...
auto async_fallocate(Fd fd, int mode, __u64 offset, __u64 len)
See io_uring_prep_fallocate.
auto async_madvise(void *addr, __u32 length, int advice)
See io_uring_prep_madvise.
auto async_epoll_wait(int fd, struct epoll_event *events, int maxevents, unsigned flags)
See io_uring_prep_epoll_wait.
auto async_symlink(const char *target, const char *linkpath)
See io_uring_prep_symlinkat.
auto async_sync_file_range(Fd fd, unsigned len, __u64 offset, int flags)
See io_uring_prep_sync_file_range.
auto async_fadvise64(Fd fd, __u64 offset, off_t len, int advice)
See io_uring_prep_fadvise64.
auto async_bind(Fd fd, struct sockaddr *addr, socklen_t addrlen)
See io_uring_prep_bind.
auto async_connect(Fd fd, const struct sockaddr *addr, socklen_t addrlen)
See io_uring_prep_connect.
auto async_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options, unsigned int flags)
See io_uring_prep_waitid.
auto async_files_update(int *fds, unsigned nr_fds, int offset)
See io_uring_prep_files_update.
auto async_cmd_sock(int cmd_op, Fd fd, int level, int optname, void *optval, int optlen)
See io_uring_prep_cmd_sock.
auto async_tee(Fd1 fd_in, Fd2 fd_out, unsigned int nbytes, unsigned int splice_flags)
See io_uring_prep_tee.
auto async_recvmsg_multishot(Fd fd, struct msghdr *msg, unsigned flags, Buffer &buf, MultiShotFunc &&func)
See io_uring_prep_recvmsg_multishot.
auto async_futex_wait(uint32_t *futex, uint64_t val, uint64_t mask, uint32_t futex_flags, unsigned int flags)
See io_uring_prep_futex_wait.
auto async_sendmsg(Fd fd, const struct msghdr *msg, unsigned flags)
See io_uring_prep_sendmsg.
auto async_read(Fd fd, Buffer &&buf, __u64 offset)
See io_uring_prep_read.
auto async_cancel_fd(Fd fd, unsigned int flags)
See io_uring_prep_cancel_fd.
auto async_pipe_direct(int *fds, int pipe_flags, unsigned int file_index)
See io_uring_prep_pipe_direct.
auto async_link_timeout(struct __kernel_timespec *ts, unsigned flags)
See io_uring_prep_link_timeout.
auto async_nop()
See io_uring_prep_nop.
auto async_sendmsg_zc(Fd fd, const struct msghdr *msg, unsigned flags, FreeFunc &&func)
See io_uring_prep_sendmsg_zc.
auto async_close(int fd)
See io_uring_prep_close.
auto async_open(const char *path, int flags, mode_t mode)
See io_uring_prep_openat.
auto flag(Awaiter &&awaiter)
Decorates an awaiter with specific io_uring sqe flags.
auto async_listen(Fd fd, int backlog)
See io_uring_prep_listen.
auto async_send(Fd sockfd, Buffer &&buf, int flags)
See io_uring_prep_send.
auto async_renameat(int olddfd, const char *oldpath, int newdfd, const char *newpath, unsigned int flags)
See io_uring_prep_renameat.
auto async_accept_direct(Fd fd, struct sockaddr *addr, socklen_t *addrlen, int flags, unsigned int file_index)
See io_uring_prep_accept_direct.
auto async_timeout(struct __kernel_timespec *ts, unsigned count, unsigned flags)
See io_uring_prep_timeout.
auto async_rename(const char *oldpath, const char *newpath)
See io_uring_prep_renameat.
auto async_setxattr(const char *name, const char *value, const char *path, int flags, unsigned int len)
See io_uring_prep_setxattr.
auto async_send_zc(Fd sockfd, Buffer &&buf, int flags, unsigned zc_flags, FreeFunc &&func)
See io_uring_prep_send_zc.
auto async_openat2_direct(int dfd, const char *path, struct open_how *how, unsigned file_index)
See io_uring_prep_openat2_direct.
auto async_unlink(const char *path, int flags)
See io_uring_prep_unlinkat.
auto async_accept(Fd fd, struct sockaddr *addr, socklen_t *addrlen, int flags)
See io_uring_prep_accept.
auto async_mkdirat(int dfd, const char *path, mode_t mode)
See io_uring_prep_mkdirat.
auto async_readv(Fd fd, const struct iovec *iovecs, unsigned nr_vecs, __u64 offset, int flags)
See io_uring_prep_readv2.
auto async_openat(int dfd, const char *path, int flags, mode_t mode)
See io_uring_prep_openat.
auto make_multishot_bundle_select_buffer_op_awaiter(MultiShotFunc &&multishot_func, Br *buffers, Func &&func, Args &&...args)
This function creates a variant of OpAwaiter. OpAwaiter represents an asynchronous operation that can...
auto async_timeout_multishot(struct __kernel_timespec *ts, unsigned count, unsigned flags, MultiShotFunc &&func)
See io_uring_prep_timeout.
auto async_linkat(int olddfd, const char *oldpath, int newdfd, const char *newpath, int flags)
See io_uring_prep_linkat.
auto async_pipe(int *fds, int pipe_flags)
See io_uring_prep_pipe.
auto async_fixed_fd_send(FdTable &dst, int source_fd, int target_fd, unsigned int flags)
See io_uring_prep_msg_ring_fd.
auto async_futex_waitv(struct futex_waitv *futex, uint32_t nr_futex, unsigned int flags)
See io_uring_prep_futex_waitv.
auto async_shutdown(Fd fd, int how)
See io_uring_prep_shutdown.
auto async_socket(int domain, int type, int protocol, unsigned int flags)
See io_uring_prep_socket.
Support for io_uring provided buffers.