io/uring/Ring: add io_uring_submit_and_wait_timeout() wrapper
This commit is contained in:
parent
b7655d38f7
commit
e014d31972
@ -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
|
||||
|
@ -101,6 +101,8 @@ public:
|
||||
while (WaitDispatchOneCompletion()) {}
|
||||
}
|
||||
|
||||
bool SubmitAndWaitDispatchOneCompletion(struct __kernel_timespec &timeout);
|
||||
|
||||
private:
|
||||
void DispatchOneCompletion(struct io_uring_cqe &cqe) noexcept;
|
||||
};
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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).
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user