io/uring/Close: wrapper for io_uring_prep_close()
This commit is contained in:
parent
26577d1301
commit
d9b1f6223e
25
src/io/uring/Close.cxx
Normal file
25
src/io/uring/Close.cxx
Normal 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
21
src/io/uring/Close.hxx
Normal 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
|
@ -21,6 +21,7 @@ uring = static_library(
|
|||||||
'Ring.cxx',
|
'Ring.cxx',
|
||||||
'Queue.cxx',
|
'Queue.cxx',
|
||||||
'Operation.cxx',
|
'Operation.cxx',
|
||||||
|
'Close.cxx',
|
||||||
'ReadOperation.cxx',
|
'ReadOperation.cxx',
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
|
Loading…
Reference in New Issue
Block a user