io/uring/Close: wrapper for io_uring_prep_close()

This commit is contained in:
Max Kellermann 2023-03-23 06:09:20 +01:00 committed by Max Kellermann
parent 26577d1301
commit d9b1f6223e
3 changed files with 47 additions and 0 deletions

25
src/io/uring/Close.cxx Normal file
View File

@ -0,0 +1,25 @@
// SPDX-License-Identifier: BSD-2-Clause
// Copyright CM4all GmbH
// author: Max Kellermann <mk@cm4all.com>
#include "Close.hxx"
#include "Queue.hxx"
#include "io/FileDescriptor.hxx"
namespace Uring {
void
Close(Queue *queue, FileDescriptor fd) noexcept
{
if (auto *s = queue != nullptr ? queue->GetSubmitEntry() : nullptr) {
io_uring_prep_close(s, fd.Get());
io_uring_sqe_set_data(s, nullptr);
queue->Submit();
} else {
/* io_uring not available or queue full: fall back to
the classic close() system call */
fd.Close();
}
}
} // namespace Uring

21
src/io/uring/Close.hxx Normal file
View File

@ -0,0 +1,21 @@
// SPDX-License-Identifier: BSD-2-Clause
// Copyright CM4all GmbH
// author: Max Kellermann <mk@cm4all.com>
#pragma once
class FileDescriptor;
namespace Uring {
class Queue;
/**
* Schedule a close() on the given file descriptor. If no
* #io_uring_sqe is available, this function falls back to close().
* No callback will be invoked.
*/
void
Close(Queue *queue, FileDescriptor fd) noexcept;
} // namespace Uring

View File

@ -21,6 +21,7 @@ uring = static_library(
'Ring.cxx',
'Queue.cxx',
'Operation.cxx',
'Close.cxx',
'ReadOperation.cxx',
include_directories: inc,
dependencies: [