Skip to content

Commit

Permalink
io/uring/Ring: add io_uring_submit_and_wait_timeout() wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Feb 4, 2025
1 parent 479adc8 commit 02c692a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/io/uring/Queue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@ Queue::WaitDispatchOneCompletion()
return true;
}

bool
Queue::SubmitAndWaitDispatchOneCompletion(struct __kernel_timespec &timeout)
{
auto *cqe = ring.SubmitAndWaitCompletion(timeout);
if (cqe == nullptr)
return false;

DispatchOneCompletion(*cqe);
return true;
}

} // namespace Uring
2 changes: 2 additions & 0 deletions src/io/uring/Queue.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public:
while (WaitDispatchOneCompletion()) {}
}

bool SubmitAndWaitDispatchOneCompletion(struct __kernel_timespec &timeout);

private:
void DispatchOneCompletion(struct io_uring_cqe &cqe) noexcept;
};
Expand Down
15 changes: 15 additions & 0 deletions src/io/uring/Ring.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ Ring::WaitCompletion()
return cqe;
}

struct io_uring_cqe *
Ring::SubmitAndWaitCompletion(struct __kernel_timespec &timeout)
{
struct io_uring_cqe *cqe;
if (int error = io_uring_submit_and_wait_timeout(&ring, &cqe, 1, &timeout, nullptr);
error < 0) {
if (error == -ETIME || error == -EAGAIN)
return nullptr;

throw MakeErrno(-error, "io_uring_submit_and_wait_timeout() failed");
}

return cqe;
}

struct io_uring_cqe *
Ring::PeekCompletion()
{
Expand Down
10 changes: 10 additions & 0 deletions src/io/uring/Ring.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public:
*/
struct io_uring_cqe *WaitCompletion();

/**
* Submit requests and wait for one completion (or a timeout).
* Wrapper for io_uring_submit_and_wait_timeout().
*
* Throws on error.
*
* @return a completion queue entry or nullptr on EAGAIN/ETIME
*/
struct io_uring_cqe *SubmitAndWaitCompletion(struct __kernel_timespec &timeout);

/**
* Peek one completion (non-blocking).
*
Expand Down

0 comments on commit 02c692a

Please sign in to comment.