Skip to content

Commit

Permalink
io_service.hpp: adopt the latest liburing features
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Apr 5, 2022
1 parent 5e15c48 commit 9fd2590
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions include/liburing/io_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class io_service {
TEST_IORING_OP(IORING_OP_MKDIRAT);
TEST_IORING_OP(IORING_OP_SYMLINKAT);
TEST_IORING_OP(IORING_OP_LINKAT);
TEST_IORING_OP(IORING_OP_MSG_RING);
#undef TEST_IORING_OP

#define TEST_IORING_FEATURE(feature) if (p.features & feature) puts_if_verbose("\t" #feature)
Expand All @@ -113,6 +114,7 @@ class io_service {
TEST_IORING_FEATURE(IORING_FEAT_EXT_ARG);
TEST_IORING_FEATURE(IORING_FEAT_NATIVE_WORKERS);
TEST_IORING_FEATURE(IORING_FEAT_RSRC_TAGS);
TEST_IORING_FEATURE(IORING_FEAT_CQE_SKIP);
#undef TEST_IORING_FEATURE
}

Expand Down Expand Up @@ -145,6 +147,19 @@ class io_service {
return await_work(sqe, iflags);
}

sqe_awaitable readv2(
int fd,
const iovec* iovecs,
unsigned nr_vecs,
off_t offset,
int flags,
uint8_t iflags = 0
) noexcept {
auto* sqe = io_uring_get_sqe_safe();
io_uring_prep_readv2(sqe, fd, iovecs, nr_vecs, offset, flags);
return await_work(sqe, iflags);
}

/** Write data into multiple buffers asynchronously
* @see pwritev2(2)
* @see io_uring_enter(2) IORING_OP_WRITEV
Expand All @@ -163,6 +178,19 @@ class io_service {
return await_work(sqe, iflags);
}

sqe_awaitable writev2(
int fd,
const iovec* iovecs,
unsigned nr_vecs,
off_t offset,
int flags,
uint8_t iflags = 0
) noexcept {
auto* sqe = io_uring_get_sqe_safe();
io_uring_prep_writev2(sqe, fd, iovecs, nr_vecs, offset, flags);
return await_work(sqe, iflags);
}

/** Read from a file descriptor at a given offset asynchronously
* @see pread(2)
* @see io_uring_enter(2) IORING_OP_READ
Expand Down Expand Up @@ -620,6 +648,23 @@ class io_service {
return await_work(sqe, iflags);
}

/** Delete a name and possibly the file it refers to asynchronously
* @see io_uring_enter(2) IORING_OP_MSG_RING
* @param iflags IOSQE_* flags
* @return a task object for awaiting
*/
sqe_awaitable msg_ring(
int fd,
unsigned len,
uint64_t data,
unsigned flags,
uint8_t iflags = 0
) {
auto* sqe = io_uring_get_sqe_safe();
io_uring_prep_msg_ring(sqe, fd, len, data, flags);
return await_work(sqe, iflags);
}

private:
sqe_awaitable await_work(
io_uring_sqe* sqe,
Expand Down

0 comments on commit 9fd2590

Please sign in to comment.