LLFIO v2.00
Loading...
Searching...
No Matches
llfio_v2_xxx::byte_io_multiplexer Class Referenceabstract

A multiplexer of byte-orientated i/o. More...

#include "byte_io_multiplexer.hpp"

Inheritance diagram for llfio_v2_xxx::byte_io_multiplexer:
llfio_v2_xxx::handle

Classes

struct  _registered_buffer_type
 
struct  _synchronised_io_operation_state
 A synchronised i/o operation state. More...
 
struct  _unsynchronised_io_operation_state
 An unsynchronised i/o operation state. More...
 
struct  awaitable
 A convenience coroutine awaitable type returned by .co_read(), .co_write() and .co_barrier(). Blocks execution if no i/o multiplexer has been set on this handle! More...
 
struct  buffer_type
 
struct  check_for_any_completed_io_statistics
 Statistics about the just returned wait_for_completed_io() operation. More...
 
struct  const_buffer_type
 
struct  implementation_information_t
 The implementation information returned. More...
 
struct  io_operation_state
 An interface to a state for an i/o operation scheduled against an i/o multiplexer. More...
 
struct  io_operation_state_visitor
 Called by an i/o operation state to inform you of state change. Note that the i/o operation state lock is HELD during these calls! More...
 
struct  io_request
 The i/o request type used by this handle. Guaranteed to be TrivialType apart from construction, and StandardLayoutType. More...
 
struct  io_result
 The i/o result type used by this handle. Guaranteed to be TrivialType apart from construction. More...
 

Public Types

enum class  barrier_kind : uint8_t {
  nowait_view_only , wait_view_only , nowait_data_only , wait_data_only ,
  nowait_all , wait_all
}
 The kinds of write reordering barrier which can be performed. More...
 
using path_type = handle::path_type
 
using extent_type = handle::extent_type
 
using size_type = handle::size_type
 
using mode = handle::mode
 
using creation = handle::creation
 
using caching = handle::caching
 
using flag = handle::flag
 
using registered_buffer_type = std::shared_ptr< _registered_buffer_type >
 The registered buffer type used by this handle.
 
using buffers_type = span< buffer_type >
 The scatter buffers type used by this handle. Guaranteed to be TrivialType apart from construction, and StandardLayoutType.
 
using const_buffers_type = span< const_buffer_type >
 The gather buffers type used by this handle. Guaranteed to be TrivialType apart from construction, and StandardLayoutType.
 

Public Member Functions

 byte_io_multiplexer (byte_io_multiplexer &&)=default
 
 byte_io_multiplexer (const byte_io_multiplexer &)=delete
 
byte_io_multiplexeroperator= (byte_io_multiplexer &&)=default
 
byte_io_multiplexeroperator= (const byte_io_multiplexer &)=delete
 
virtual implementation_information_t implementation_information () const noexcept=0
 Returns implementation information about an i/o multiplexer.
 
virtual result< uint8_t > do_byte_io_handle_register (byte_io_handle *) noexcept
 
virtual result< void > do_byte_io_handle_deregister (byte_io_handle *) noexcept
 Implements byte_io_handle deregistration.
 
virtual result< uint8_t > do_byte_io_handle_register (listening_byte_socket_handle *) noexcept
 
virtual result< void > do_byte_io_handle_deregister (listening_byte_socket_handle *) noexcept
 Implements listening_byte_socket_handle deregistration.
 
virtual size_t do_byte_io_handle_max_buffers (const byte_io_handle *h) const noexcept
 Implements byte_io_handle::max_buffers()
 
virtual result< registered_buffer_typedo_byte_io_handle_allocate_registered_buffer (byte_io_handle *h, size_t &bytes) noexcept
 Implements byte_io_handle::allocate_registered_buffer()
 
virtual std::pair< size_t, size_t > io_state_requirements () noexcept=0
 Returns the number of bytes, and alignment required, for an io_operation_state for this multiplexer.
 
virtual io_operation_stateconstruct (span< byte > storage, byte_io_handle *_h, io_operation_state_visitor *_visitor, registered_buffer_type &&b, deadline d, io_request< buffers_type > reqs) noexcept=0
 Constructs either a unsynchronised_io_operation_state or a synchronised_io_operation_state for a read operation into the storage provided. The i/o is not initiated. The storage must meet the requirements from state_requirements().
 
virtual io_operation_stateconstruct (span< byte > storage, byte_io_handle *_h, io_operation_state_visitor *_visitor, registered_buffer_type &&b, deadline d, io_request< const_buffers_type > reqs) noexcept=0
 Constructs either a unsynchronised_io_operation_state or a synchronised_io_operation_state for a write operation into the storage provided. The i/o is not initiated. The storage must meet the requirements from state_requirements().
 
virtual io_operation_stateconstruct (span< byte > storage, byte_io_handle *_h, io_operation_state_visitor *_visitor, registered_buffer_type &&b, deadline d, io_request< const_buffers_type > reqs, barrier_kind kind) noexcept=0
 Constructs either a unsynchronised_io_operation_state or a synchronised_io_operation_state for a barrier operation into the storage provided. The i/o is not initiated. The storage must meet the requirements from state_requirements().
 
virtual io_operation_stateconstruct (span< byte > storage, byte_socket_handle *_h, io_operation_state_visitor *_visitor, deadline d, const ip::address &) noexcept
 Constructs either a unsynchronised_io_operation_state or a synchronised_io_operation_state for a byte_socket_handle read operation into the storage provided. The i/o is not initiated. The storage must meet the requirements from state_requirements().
 
virtual io_operation_stateconstruct (span< byte > storage, listening_byte_socket_handle *_h, io_operation_state_visitor *_visitor, deadline d, std::pair< byte_socket_handle, ip::address > &) noexcept
 Constructs either a unsynchronised_io_operation_state or a synchronised_io_operation_state for a listening_byte_socket_handle read operation into the storage provided. The i/o is not initiated. The storage must meet the requirements from state_requirements().
 
virtual io_operation_state_type init_io_operation (io_operation_state *state) noexcept=0
 Initiates the i/o in a previously constructed state. Note that you should always call .flush_inited_io_operations() after you finished initiating i/o. After this call returns, you cannot relocate in memory state until is_finished(state->current_state()) returns true.
 
virtual io_operation_stateconstruct_and_init_io_operation (span< byte > storage, byte_io_handle *_h, io_operation_state_visitor *_visitor, registered_buffer_type &&b, deadline d, io_request< buffers_type > reqs) noexcept
 Combines .construct() with .init_io_operation() in a single call for improved efficiency.
 
virtual io_operation_stateconstruct_and_init_io_operation (span< byte > storage, byte_io_handle *_h, io_operation_state_visitor *_visitor, registered_buffer_type &&b, deadline d, io_request< const_buffers_type > reqs) noexcept
 Combines .construct() with .init_io_operation() in a single call for improved efficiency.
 
virtual io_operation_stateconstruct_and_init_io_operation (span< byte > storage, byte_io_handle *_h, io_operation_state_visitor *_visitor, registered_buffer_type &&b, deadline d, io_request< const_buffers_type > reqs, barrier_kind kind) noexcept
 Combines .construct() with .init_io_operation() in a single call for improved efficiency.
 
virtual io_operation_stateconstruct_and_init_io_operation (span< byte > storage, byte_socket_handle *_h, io_operation_state_visitor *_visitor, deadline d, const ip::address &addr) noexcept
 Combines .construct() with .init_io_operation() in a single call for improved efficiency.
 
virtual io_operation_stateconstruct_and_init_io_operation (span< byte > storage, listening_byte_socket_handle *_h, io_operation_state_visitor *_visitor, deadline d, std::pair< byte_socket_handle, ip::address > &req) noexcept
 Combines .construct() with .init_io_operation() in a single call for improved efficiency.
 
virtual result< void > flush_inited_io_operations () noexcept
 Flushes any previously initiated i/o, if necessary for this i/o multiplexer.
 
virtual io_operation_state_type check_io_operation (io_operation_state *op) noexcept
 Asks the system for the current state of the i/o, returning its current state.
 
virtual result< io_operation_state_typecancel_io_operation (io_operation_state *op, deadline d={}) noexcept=0
 Cancel an initiated i/o, returning its current state if successful.
 
virtual result< check_for_any_completed_io_statisticscheck_for_any_completed_io (deadline d=std::chrono::seconds(0), size_t max_completions=(size_t) -1) noexcept=0
 Checks all i/o initiated on this i/o multiplexer to see which have completed, trying without guarantee to complete no more than max_completions completions or finisheds, and not to exceed d of waiting (this function never fails with timed out).
 
virtual result< void > wake_check_for_any_completed_io () noexcept=0
 Can be called from any thread to wake any other single thread currently blocked within check_for_any_completed_io(). Which thread is woken is not specified.
 
constexpr handle ()
 
constexpr handle (native_handle_type h, flag flags=flag::none) noexcept
 
 handle (const handle &)=delete
 
constexpr handle (handle &&o) noexcept
 
flag flags () const noexcept
 The flags this handle was opened with.
 
 QUICKCPPLIB_BITFIELD_BEGIN_T (flag, uint16_t)
 Bitwise flags which can be specified.
 
void swap (handle &o) noexcept
 Swap with another instance.
 
virtual result< path_type > current_path () const noexcept
 
virtual result< void > close () noexcept
 Immediately close the native handle type managed by this handle.
 
result< handleclone () const noexcept
 
virtual native_handle_type release () noexcept
 Release the native handle type managed by this handle.
 
bool is_valid () const noexcept
 True if the handle is valid (and usually open)
 
bool is_readable () const noexcept
 True if the handle is readable.
 
bool is_writable () const noexcept
 True if the handle is writable.
 
bool is_append_only () const noexcept
 True if the handle is append only.
 
virtual result< void > set_append_only (bool enable) noexcept
 EXTENSION: Changes whether this handle is append only or not.
 
bool is_multiplexable () const noexcept
 True if multiplexable.
 
bool is_nonblocking () const noexcept
 True if nonblocking.
 
bool is_seekable () const noexcept
 True if seekable.
 
bool requires_aligned_io () const noexcept
 True if requires aligned i/o.
 
bool is_kernel_handle () const noexcept
 True if native_handle() is a valid kernel handle.
 
bool is_regular () const noexcept
 True if a regular file or device.
 
bool is_directory () const noexcept
 True if a directory.
 
bool is_symlink () const noexcept
 True if a symlink.
 
bool is_pipe () const noexcept
 True if a pipe.
 
bool is_socket () const noexcept
 True if a socket.
 
bool is_multiplexer () const noexcept
 True if a multiplexer like BSD kqueues, Linux epoll or Windows IOCP.
 
bool is_process () const noexcept
 True if a process.
 
bool is_section () const noexcept
 True if a memory section.
 
bool is_allocation () const noexcept
 True if a memory allocation.
 
bool is_path () const noexcept
 True if a path or a directory.
 
bool is_tls_socket () const noexcept
 True if a TLS socket.
 
bool is_http_socket () const noexcept
 True if a HTTP socket.
 
caching kernel_caching () const noexcept
 Kernel cache strategy used by this handle.
 
bool are_reads_from_cache () const noexcept
 True if the handle uses the kernel page cache for reads.
 
bool are_writes_durable () const noexcept
 True if writes are safely on storage on completion.
 
bool are_safety_barriers_issued () const noexcept
 True if issuing safety fsyncs is on.
 
native_handle_type native_handle () const noexcept
 The native handle used by this handle.
 

Static Protected Member Functions

static io_result< buffers_type_result_type_from_io_operation_state (io_operation_state *state, buffers_type *) noexcept
 
static io_result< const_buffers_type_result_type_from_io_operation_state (io_operation_state *state, const_buffers_type *) noexcept
 

Protected Attributes

union { 
 
   native_handle_type   _v 
 
   struct { 
 
      intptr_t   _padding0_ 
 
      uint32_t   _padding1_ 
 
      flag   flags 
 
      uint16_t   _padding2_ 
 
   }   _ 
 
};  
 

Static Protected Attributes

static constexpr size_t _awaitable_size = 128
 

Detailed Description

A multiplexer of byte-orientated i/o.

LLFIO does not provide out-of-the-box multiplexing of byte i/o, however it does provide the ability to create byte_io_handle instances with the handle::flag::multiplexable set. With that flag set, the following LLFIO classes change how they create handles with the kernel:

LLFIO i/o classPOSIXWindows
directory_handleNo effectCreates HANDLE as OVERLAPPED
file_handleNo effectCreates HANDLE as OVERLAPPED
map_handleNo effectNo effect
mapped_file_handleNo effectCreates HANDLE as OVERLAPPED, but i/o is to map not file
pipe_handleCreates file descriptor as non-blockingCreates HANDLE as OVERLAPPED
section_handleNo effectCreates HANDLE as OVERLAPPED
socket_handleCreates file descriptor as non-blockingCreates HANDLE as OVERLAPPED and as non-blocking
symlink_handleNo effectCreates HANDLE as OVERLAPPED

If the i/o handle's multiplexer pointer is not null, the multiplexer instance is invoked to implement byte_io_handle::read(), byte_io_handle::write() and byte_io_handle::barrier() by constructing an i/o operation state on the stack, calling .init_io_operation() followed by .flush_inited_io_operations(), and then spinning on .check_io_operation() and .check_for_any_completed_io() with the deadline specified to the original blocking operation.

If the i/o handle's multiplexer pointer is null, byte_io_handle::read(), byte_io_handle::write() and byte_io_handle::barrier() all use virtually overridable implementations. The default implementations emulate blocking semantics using the kernel's i/o poll function (literally poll() on POSIX, NtWaitForSingleObject() on Windows) to sleep the thread until at least one byte of i/o occurs, or the deadline specified is exceeded. This, obviously enough, can double the number of kernel syscalls done per i/o, so using handles with the handle::flag::multiplexable flag set is not wise unless you really need non-infinite deadline i/o.

Member Enumeration Documentation

◆ barrier_kind

The kinds of write reordering barrier which can be performed.

Enumerator
nowait_view_only 

Barrier mapped data only, non-blocking. This is highly optimised on NV-DIMM storage, but consider using nvram_barrier() for even better performance.

wait_view_only 

Barrier mapped data only, block until it is done. This is highly optimised on NV-DIMM storage, but consider using nvram_barrier() for even better performance.

nowait_data_only 

Barrier data only, non-blocking. This is highly optimised on NV-DIMM storage, but consider using nvram_barrier() for even better performance.

wait_data_only 

Barrier data only, block until it is done. This is highly optimised on NV-DIMM storage, but consider using nvram_barrier() for even better performance.

nowait_all 

Barrier data and the metadata to retrieve it, non-blocking.

wait_all 

Barrier data and the metadata to retrieve it, block until it is done.

202 {
203 nowait_view_only, //!< Barrier mapped data only, non-blocking. This is highly optimised on NV-DIMM storage, but consider using `nvram_barrier()` for even better performance.
204 wait_view_only, //!< Barrier mapped data only, block until it is done. This is highly optimised on NV-DIMM storage, but consider using `nvram_barrier()` for even better performance.
205 nowait_data_only, //!< Barrier data only, non-blocking. This is highly optimised on NV-DIMM storage, but consider using `nvram_barrier()` for even better performance.
206 wait_data_only, //!< Barrier data only, block until it is done. This is highly optimised on NV-DIMM storage, but consider using `nvram_barrier()` for even better performance.
207 nowait_all, //!< Barrier data and the metadata to retrieve it, non-blocking.
208 wait_all //!< Barrier data and the metadata to retrieve it, block until it is done.
209 };
@ nowait_data_only
Barrier data only, non-blocking. This is highly optimised on NV-DIMM storage, but consider using nvra...
@ nowait_view_only
Barrier mapped data only, non-blocking. This is highly optimised on NV-DIMM storage,...
@ wait_all
Barrier data and the metadata to retrieve it, block until it is done.
@ wait_view_only
Barrier mapped data only, block until it is done. This is highly optimised on NV-DIMM storage,...
@ nowait_all
Barrier data and the metadata to retrieve it, non-blocking.
@ wait_data_only
Barrier data only, block until it is done. This is highly optimised on NV-DIMM storage,...

Constructor & Destructor Documentation

◆ byte_io_multiplexer()

constexpr llfio_v2_xxx::byte_io_multiplexer::byte_io_multiplexer ( )
inlineconstexpr
487{}

Member Function Documentation

◆ _result_type_from_io_operation_state() [1/2]

static io_result< buffers_type > llfio_v2_xxx::byte_io_multiplexer::_result_type_from_io_operation_state ( io_operation_state state,
buffers_type  
)
inlinestaticprotectednoexcept
1176 {
1177 return std::move(*state).get_completed_read();
1178 }

◆ _result_type_from_io_operation_state() [2/2]

static io_result< const_buffers_type > llfio_v2_xxx::byte_io_multiplexer::_result_type_from_io_operation_state ( io_operation_state state,
const_buffers_type  
)
inlinestaticprotectednoexcept
1180 {
1181 return std::move(*state).get_completed_write_or_barrier();
1182 }

◆ are_reads_from_cache()

bool llfio_v2_xxx::handle::are_reads_from_cache ( ) const
inlinenoexceptinherited

True if the handle uses the kernel page cache for reads.

410{ return !!(_v.behaviour & native_handle_type::disposition::cache_reads); }

◆ are_safety_barriers_issued()

bool llfio_v2_xxx::handle::are_safety_barriers_issued ( ) const
inlinenoexceptinherited

True if issuing safety fsyncs is on.

414{ return !!(_v.behaviour & native_handle_type::disposition::safety_barriers); }

◆ are_writes_durable()

bool llfio_v2_xxx::handle::are_writes_durable ( ) const
inlinenoexceptinherited

True if writes are safely on storage on completion.

412{ return !(_v.behaviour & native_handle_type::disposition::cache_writes); }

◆ check_io_operation()

virtual io_operation_state_type llfio_v2_xxx::byte_io_multiplexer::check_io_operation ( io_operation_state op)
inlinevirtualnoexcept

Asks the system for the current state of the i/o, returning its current state.

1460{ return op->current_state(); }

◆ clone()

result< handle > llfio_v2_xxx::handle::clone ( ) const
noexceptinherited

Clone this handle (copy constructor is disabled to avoid accidental copying)

Errors returnable\n Any of the values POSIX dup() or DuplicateHandle() can return.

◆ close()

◆ construct() [1/2]

virtual io_operation_state * llfio_v2_xxx::byte_io_multiplexer::construct ( span< byte >  storage,
byte_socket_handle _h,
io_operation_state_visitor _visitor,
deadline  d,
const ip::address  
)
inlinevirtualnoexcept

Constructs either a unsynchronised_io_operation_state or a synchronised_io_operation_state for a byte_socket_handle read operation into the storage provided. The i/o is not initiated. The storage must meet the requirements from state_requirements().

1362 {
1363 (void) storage;
1364 (void) _h;
1365 (void) _visitor;
1366 (void) d;
1367 return nullptr;
1368 }

◆ construct() [2/2]

virtual io_operation_state * llfio_v2_xxx::byte_io_multiplexer::construct ( span< byte >  storage,
listening_byte_socket_handle _h,
io_operation_state_visitor _visitor,
deadline  d,
std::pair< byte_socket_handle, ip::address > &   
)
inlinevirtualnoexcept

Constructs either a unsynchronised_io_operation_state or a synchronised_io_operation_state for a listening_byte_socket_handle read operation into the storage provided. The i/o is not initiated. The storage must meet the requirements from state_requirements().

1376 {
1377 (void) storage;
1378 (void) _h;
1379 (void) _visitor;
1380 (void) d;
1381 return nullptr;
1382 }

◆ construct_and_init_io_operation() [1/5]

virtual io_operation_state * llfio_v2_xxx::byte_io_multiplexer::construct_and_init_io_operation ( span< byte >  storage,
byte_io_handle _h,
io_operation_state_visitor _visitor,
registered_buffer_type &&  b,
deadline  d,
io_request< buffers_type reqs 
)
inlinevirtualnoexcept

Combines .construct() with .init_io_operation() in a single call for improved efficiency.

1394 {
1395 io_operation_state *state = construct(storage, _h, _visitor, std::move(b), d, std::move(reqs));
1396 if(state != nullptr)
1397 {
1398 init_io_operation(state);
1399 }
1400 return state;
1401 }
virtual io_operation_state * construct(span< byte > storage, byte_io_handle *_h, io_operation_state_visitor *_visitor, registered_buffer_type &&b, deadline d, io_request< buffers_type > reqs) noexcept=0
Constructs either a unsynchronised_io_operation_state or a synchronised_io_operation_state for a read...
virtual io_operation_state_type init_io_operation(io_operation_state *state) noexcept=0
Initiates the i/o in a previously constructed state. Note that you should always call ....

◆ construct_and_init_io_operation() [2/5]

virtual io_operation_state * llfio_v2_xxx::byte_io_multiplexer::construct_and_init_io_operation ( span< byte >  storage,
byte_io_handle _h,
io_operation_state_visitor _visitor,
registered_buffer_type &&  b,
deadline  d,
io_request< const_buffers_type reqs 
)
inlinevirtualnoexcept

Combines .construct() with .init_io_operation() in a single call for improved efficiency.

1407 {
1408 io_operation_state *state = construct(storage, _h, _visitor, std::move(b), d, std::move(reqs));
1409 if(state != nullptr)
1410 {
1411 init_io_operation(state);
1412 }
1413 return state;
1414 }

◆ construct_and_init_io_operation() [3/5]

virtual io_operation_state * llfio_v2_xxx::byte_io_multiplexer::construct_and_init_io_operation ( span< byte >  storage,
byte_io_handle _h,
io_operation_state_visitor _visitor,
registered_buffer_type &&  b,
deadline  d,
io_request< const_buffers_type reqs,
barrier_kind  kind 
)
inlinevirtualnoexcept

Combines .construct() with .init_io_operation() in a single call for improved efficiency.

1421 {
1422 io_operation_state *state = construct(storage, _h, _visitor, std::move(b), d, std::move(reqs), kind);
1423 if(state != nullptr)
1424 {
1425 init_io_operation(state);
1426 }
1427 return state;
1428 }

◆ construct_and_init_io_operation() [4/5]

virtual io_operation_state * llfio_v2_xxx::byte_io_multiplexer::construct_and_init_io_operation ( span< byte >  storage,
byte_socket_handle _h,
io_operation_state_visitor _visitor,
deadline  d,
const ip::address addr 
)
inlinevirtualnoexcept

Combines .construct() with .init_io_operation() in a single call for improved efficiency.

1434 {
1435 io_operation_state *state = construct(storage, _h, _visitor, d, addr);
1436 if(state != nullptr)
1437 {
1438 init_io_operation(state);
1439 }
1440 return state;
1441 }

◆ construct_and_init_io_operation() [5/5]

virtual io_operation_state * llfio_v2_xxx::byte_io_multiplexer::construct_and_init_io_operation ( span< byte >  storage,
listening_byte_socket_handle _h,
io_operation_state_visitor _visitor,
deadline  d,
std::pair< byte_socket_handle, ip::address > &  req 
)
inlinevirtualnoexcept

Combines .construct() with .init_io_operation() in a single call for improved efficiency.

1447 {
1448 io_operation_state *state = construct(storage, _h, _visitor, d, req);
1449 if(state != nullptr)
1450 {
1451 init_io_operation(state);
1452 }
1453 return state;
1454 }

◆ current_path()

virtual result< path_type > llfio_v2_xxx::handle::current_path ( ) const
virtualnoexceptinherited

Returns the current path of the open handle as said by the operating system. Note that you are NOT guaranteed that any path refreshed bears any resemblance to the original, some operating systems will return some different path which still reaches the same inode via some other route e.g. hardlinks, dereferenced symbolic links, etc. Windows and Linux correctly track changes to the specific path the handle was opened with, not getting confused by other hard links. MacOS nearly gets it right, but under some circumstances e.g. renaming may switch to a different hard link's path which is almost certainly a bug.

If LLFIO was not able to determine the current path for this open handle e.g. the inode has been unlinked, it returns an empty path. Be aware that FreeBSD can return an empty (deleted) path for file inodes no longer cached by the kernel path cache, LLFIO cannot detect the difference. FreeBSD will also return any path leading to the inode if it is hard linked. FreeBSD does implement path retrieval for directory inodes correctly however, and see algorithm::cached_parent_handle_adapter<T> for a handle adapter which makes use of that.

On Linux if /proc is not mounted, this call fails with an error. All APIs in LLFIO which require the use of current_path() can be told to not use it e.g. flag::disable_safety_unlinks. It is up to you to detect if current_path() is not working, and to change how you call LLFIO appropriately.

On Windows, you will almost certainly get back a path of the form \!!\Device\HarddiskVolume10\Users\ned\.... See path_view for what all the path prefix sequences mean, but to summarise the \!!\ prefix is LLFIO-only and will not be accepted by other Windows APIs. Pass LLFIO derived paths through the function to_win32_path() to Win32-ise them. This function is also available on Linux where it does nothing, so you can use it in portable code.

Warning
This call is expensive, it always asks the kernel for the current path, and no checking is done to ensure what the kernel returns is accurate or even sensible. Be aware that despite these precautions, paths are unstable and can change randomly at any moment. Most code written to use absolute file systems paths is racy, so don't do it, use path_handle to fix a base location on the file system and work from that anchor instead!
Memory Allocations\n At least one malloc for the path_type, likely several more.
See also
algorithm::cached_parent_handle_adapter<T> which overrides this with an implementation based on retrieving the current path of a cached handle to the parent directory. On platforms with instability or failure to retrieve the correct current path for regular files, the cached parent handle adapter works around the problem by taking advantage of directory inodes not having the same instability problems on any platform.

Reimplemented in llfio_v2_xxx::process_handle.

◆ do_byte_io_handle_allocate_registered_buffer()

result< byte_io_multiplexer::registered_buffer_type > llfio_v2_xxx::byte_io_multiplexer::do_byte_io_handle_allocate_registered_buffer ( byte_io_handle h,
size_t &  bytes 
)
inlinevirtualnoexcept

Implements byte_io_handle::allocate_registered_buffer()

539{
540 return h->_do_allocate_registered_buffer(bytes);
541}

◆ do_byte_io_handle_deregister() [1/2]

virtual result< void > llfio_v2_xxx::byte_io_multiplexer::do_byte_io_handle_deregister ( byte_io_handle )
inlinevirtualnoexcept

Implements byte_io_handle deregistration.

542{ return success(); }

◆ do_byte_io_handle_deregister() [2/2]

virtual result< void > llfio_v2_xxx::byte_io_multiplexer::do_byte_io_handle_deregister ( listening_byte_socket_handle )
inlinevirtualnoexcept

Implements listening_byte_socket_handle deregistration.

548{ return errc::operation_not_supported; }

◆ do_byte_io_handle_max_buffers()

size_t llfio_v2_xxx::byte_io_multiplexer::do_byte_io_handle_max_buffers ( const byte_io_handle h) const
inlinevirtualnoexcept

Implements byte_io_handle::max_buffers()

534{
535 return h->_do_max_buffers();
536}

◆ do_byte_io_handle_register() [1/2]

virtual result< uint8_t > llfio_v2_xxx::byte_io_multiplexer::do_byte_io_handle_register ( byte_io_handle )
inlinevirtualnoexcept

Implements byte_io_handle registration. The bottom two bits of the returned value are set into _v.behaviour's _multiplexer_state_bit0 and _multiplexer_state_bit

540{ return (uint8_t) 0; }

◆ do_byte_io_handle_register() [2/2]

virtual result< uint8_t > llfio_v2_xxx::byte_io_multiplexer::do_byte_io_handle_register ( listening_byte_socket_handle )
inlinevirtualnoexcept

Implements listening_byte_socket_handle registration. The bottom two bits of the returned value are set into _v.behaviour's _multiplexer_state_bit0 and _multiplexer_state_bit

546{ return errc::operation_not_supported; }

◆ flags()

flag llfio_v2_xxx::handle::flags ( ) const
inlinenoexceptinherited

The flags this handle was opened with.

417{ return _.flags; }

◆ flush_inited_io_operations()

virtual result< void > llfio_v2_xxx::byte_io_multiplexer::flush_inited_io_operations ( )
inlinevirtualnoexcept

Flushes any previously initiated i/o, if necessary for this i/o multiplexer.

1457{ return success(); }

◆ handle() [1/4]

constexpr llfio_v2_xxx::handle::handle ( )
inlineconstexpr
Todo:
Why is io_result<buffers_type> not a standard layout type?
224 : _v()
225 {
226 } // NOLINT

◆ handle() [2/4]

llfio_v2_xxx::handle::handle ( const handle )
delete
Todo:
Why is io_result<buffers_type> not a standard layout type?

◆ handle() [3/4]

constexpr llfio_v2_xxx::handle::handle ( handle &&  o)
inlineconstexprnoexcept
Todo:
Why is io_result<buffers_type> not a standard layout type?
239 : _v(std::move(o._v))
240 {
241 o._v = native_handle_type();
242 }

◆ handle() [4/4]

constexpr llfio_v2_xxx::handle::handle ( native_handle_type  h,
flag  flags = flag::none 
)
inlineexplicitconstexprnoexcept
Todo:
Why is io_result<buffers_type> not a standard layout type?
229 : _v(std::move(h), /* special move constructor to work around a constexpr bug in clang*/ uint16_t(flags))
230 {
231 }

◆ is_allocation()

bool llfio_v2_xxx::handle::is_allocation ( ) const
inlinenoexceptinherited

True if a memory allocation.

371{ return _v.is_allocation(); }
constexpr bool is_allocation() const noexcept
True if a memory allocation.
Definition native_handle_type.hpp:209

◆ is_append_only()

bool llfio_v2_xxx::handle::is_append_only ( ) const
inlinenoexceptinherited

True if the handle is append only.

330{ return _v.is_append_only(); }
constexpr bool is_append_only() const noexcept
True if the handle is append only.
Definition native_handle_type.hpp:181

◆ is_directory()

bool llfio_v2_xxx::handle::is_directory ( ) const
inlinenoexceptinherited

True if a directory.

357{ return _v.is_directory(); }
constexpr bool is_directory() const noexcept
True if a directory.
Definition native_handle_type.hpp:195

◆ is_http_socket()

bool llfio_v2_xxx::handle::is_http_socket ( ) const
inlinenoexceptinherited

True if a HTTP socket.

377{ return _v.is_http_socket(); }
constexpr bool is_http_socket() const noexcept
True if a HTTP socket.
Definition native_handle_type.hpp:215

◆ is_kernel_handle()

bool llfio_v2_xxx::handle::is_kernel_handle ( ) const
inlinenoexceptinherited

True if native_handle() is a valid kernel handle.

352{ return _v.is_kernel_handle(); }
constexpr bool is_kernel_handle() const noexcept
True if handle is a valid kernel handle.
Definition native_handle_type.hpp:190

◆ is_multiplexable()

bool llfio_v2_xxx::handle::is_multiplexable ( ) const
inlinenoexceptinherited

True if multiplexable.

344{ return !!(_.flags & flag::multiplexable); }

◆ is_multiplexer()

bool llfio_v2_xxx::handle::is_multiplexer ( ) const
inlinenoexceptinherited

True if a multiplexer like BSD kqueues, Linux epoll or Windows IOCP.

365{ return _v.is_multiplexer(); }
constexpr bool is_multiplexer() const noexcept
True if a multiplexer like BSD kqueues, Linux epoll or Windows IOCP.
Definition native_handle_type.hpp:203

◆ is_nonblocking()

bool llfio_v2_xxx::handle::is_nonblocking ( ) const
inlinenoexceptinherited

True if nonblocking.

346{ return _v.is_nonblocking(); }
constexpr bool is_nonblocking() const noexcept
True if nonblocking.
Definition native_handle_type.hpp:184

◆ is_path()

bool llfio_v2_xxx::handle::is_path ( ) const
inlinenoexceptinherited

True if a path or a directory.

373{ return _v.is_path(); }
constexpr bool is_path() const noexcept
True if a path or a directory.
Definition native_handle_type.hpp:211

◆ is_pipe()

bool llfio_v2_xxx::handle::is_pipe ( ) const
inlinenoexceptinherited

True if a pipe.

361{ return _v.is_pipe(); }
constexpr bool is_pipe() const noexcept
True if a pipe.
Definition native_handle_type.hpp:199

◆ is_process()

bool llfio_v2_xxx::handle::is_process ( ) const
inlinenoexceptinherited

True if a process.

367{ return _v.is_process(); }
constexpr bool is_process() const noexcept
True if a process.
Definition native_handle_type.hpp:205

◆ is_readable()

bool llfio_v2_xxx::handle::is_readable ( ) const
inlinenoexceptinherited

True if the handle is readable.

326{ return _v.is_readable(); }
constexpr bool is_readable() const noexcept
True if the handle is readable.
Definition native_handle_type.hpp:177

◆ is_regular()

bool llfio_v2_xxx::handle::is_regular ( ) const
inlinenoexceptinherited

True if a regular file or device.

355{ return _v.is_regular(); }
constexpr bool is_regular() const noexcept
True if a regular file or device.
Definition native_handle_type.hpp:193

◆ is_section()

bool llfio_v2_xxx::handle::is_section ( ) const
inlinenoexceptinherited

True if a memory section.

369{ return _v.is_section(); }
constexpr bool is_section() const noexcept
True if a memory section.
Definition native_handle_type.hpp:207

◆ is_seekable()

bool llfio_v2_xxx::handle::is_seekable ( ) const
inlinenoexceptinherited

True if seekable.

348{ return _v.is_seekable(); }
constexpr bool is_seekable() const noexcept
True if seekable.
Definition native_handle_type.hpp:186

◆ is_socket()

bool llfio_v2_xxx::handle::is_socket ( ) const
inlinenoexceptinherited

True if a socket.

363{ return _v.is_socket(); }
constexpr bool is_socket() const noexcept
True if a socket.
Definition native_handle_type.hpp:201

◆ is_symlink()

bool llfio_v2_xxx::handle::is_symlink ( ) const
inlinenoexceptinherited

True if a symlink.

359{ return _v.is_symlink(); }
constexpr bool is_symlink() const noexcept
True if a symlink.
Definition native_handle_type.hpp:197

◆ is_tls_socket()

bool llfio_v2_xxx::handle::is_tls_socket ( ) const
inlinenoexceptinherited

True if a TLS socket.

375{ return _v.is_tls_socket(); }
constexpr bool is_tls_socket() const noexcept
True if a TLS socket.
Definition native_handle_type.hpp:213

◆ is_valid()

bool llfio_v2_xxx::handle::is_valid ( ) const
inlinenoexceptinherited

True if the handle is valid (and usually open)

323{ return _v.is_valid(); }
constexpr bool is_valid() const noexcept
True if the handle is valid.
Definition native_handle_type.hpp:174

◆ is_writable()

bool llfio_v2_xxx::handle::is_writable ( ) const
inlinenoexceptinherited

True if the handle is writable.

328{ return _v.is_writable(); }
constexpr bool is_writable() const noexcept
True if the handle is writable.
Definition native_handle_type.hpp:179

◆ kernel_caching()

caching llfio_v2_xxx::handle::kernel_caching ( ) const
inlinenoexceptinherited

Kernel cache strategy used by this handle.

381 {
382 const bool safety_barriers = !!(_v.behaviour & native_handle_type::disposition::safety_barriers);
383 const bool cache_metadata = !!(_v.behaviour & native_handle_type::disposition::cache_metadata);
384 const bool cache_reads = !!(_v.behaviour & native_handle_type::disposition::cache_reads);
385 const bool cache_writes = !!(_v.behaviour & native_handle_type::disposition::cache_writes);
386 const bool cache_temporary = !!(_v.behaviour & native_handle_type::disposition::cache_temporary);
387 if(cache_temporary)
388 {
389 return caching::temporary;
390 }
391 if(cache_metadata && cache_reads && cache_writes)
392 {
394 }
395 if(cache_metadata && cache_reads)
396 {
398 }
399 if(cache_reads)
400 {
401 return caching::reads;
402 }
403 if(cache_metadata)
404 {
406 }
407 return caching::none;
408 }
@ reads
Cache reads only. Writes of data and metadata do not complete until reaching storage (O_SYNC)....
@ none
No caching whatsoever, all reads and writes come from storage (i.e. O_DIRECT|O_SYNC)....
@ safety_barriers
Cache reads and writes of data and metadata so they complete immediately, but issue safety barriers a...
@ all
Cache reads and writes of data and metadata so they complete immediately, sending writes to storage a...
@ only_metadata
Cache reads and writes of metadata but avoid caching data (O_DIRECT), thus i/o here does not affect o...
@ temporary
Cache reads and writes of data and metadata so they complete immediately, only sending any updates to...
@ reads_and_metadata
Cache reads and writes of metadata, but writes of data do not complete until reaching storage (O_DSYN...

◆ native_handle()

native_handle_type llfio_v2_xxx::handle::native_handle ( ) const
inlinenoexceptinherited

The native handle used by this handle.

419{ return _v; }

◆ QUICKCPPLIB_BITFIELD_BEGIN_T()

llfio_v2_xxx::handle::QUICKCPPLIB_BITFIELD_BEGIN_T ( flag  ,
uint16_t   
)
inlineinherited

Bitwise flags which can be specified.

< No flags

Unlinks the file on handle close. On POSIX, this simply unlinks whatever is pointed to by path() upon the call of close() if and only if the inode matches. On Windows, if you are on Windows 10 1709 or later, exactly the same thing occurs. If on previous editions of Windows, the file entry does not disappears but becomes unavailable for anyone else to open with an errc::resource_unavailable_try_again error return. Because this is confusing, unless the win_disable_unlink_emulation flag is also specified, this POSIX behaviour is somewhat emulated by LLFIO on older Windows by renaming the file to a random name on close() causing it to appear to have been unlinked immediately.

Some kernel caching modes have unhelpfully inconsistent behaviours in getting your data onto storage, so by default unless this flag is specified LLFIO adds extra fsyncs to the following operations for the caching modes specified below: truncation of file length either explicitly or during file open. closing of the handle either explicitly or in the destructor.

Additionally on Linux only to prevent loss of file metadata: On the parent directory whenever a file might have been created. On the parent directory on file close.

This only occurs for these kernel caching modes: caching::none caching::reads caching::reads_and_metadata caching::safety_barriers

file_handle::unlink() could accidentally delete the wrong file if someone has renamed the open file handle since the time it was opened. To prevent this occuring, where the OS doesn't provide race free unlink-by-open-handle we compare the inode of the path we are about to unlink with that of the open handle before unlinking.

Warning
This does not prevent races where in between the time of checking the inode and executing the unlink a third party changes the item about to be unlinked. Only operating systems with a true race-free unlink syscall are race free.

Ask the OS to disable prefetching of data. This can improve random i/o performance.

Ask the OS to maximise prefetching of data, possibly prefetching the entire file into kernel cache. This can improve sequential i/o performance.

< See the documentation for unlink_on_first_close

Microsoft Windows NTFS, having been created in the late 1980s, did not originally implement extents-based storage and thus could only represent sparse files via efficient compression of intermediate zeros. With NTFS v3.0 (Microsoft Windows 2000), a proper extents-based on-storage representation was added, thus allowing only 64Kb extent chunks written to be stored irrespective of whatever the maximum file extent was set to.

For various historical reasons, extents-based storage is disabled by default in newly created files on NTFS, unlike in almost every other major filing system. You have to explicitly "opt in" to extents-based storage.

As extents-based storage is nearly cost free on NTFS, LLFIO by default opts in to extents-based storage for any empty file it creates. If you don't want this, you can specify this flag to prevent that happening.

Filesystems tend to be embarrassingly parallel for operations performed to different inodes. Where LLFIO performs i/o to multiple inodes at a time, it will use OpenMP or the Parallelism or Concurrency standard library extensions to usually complete the operation in constant rather than linear time. If you don't want this default, you can disable default using this flag.

Microsoft Windows NTFS has the option, when creating a directory, to set whether leafname lookup will be case sensitive. This is the only way of getting exact POSIX semantics on Windows without resorting to editing the system registry, however it also affects all code doing lookups within that directory, so we must default it to off.

Create the handle in a way where i/o upon it can be multiplexed with other i/o on the same initiating thread of execution i.e. you can perform more than one read concurrently, without using threads. The blocking operations .read() and .write() may have to use a less efficient, but cancellable, blocking implementation for handles created in this way. On Microsoft Windows, this creates handles with OVERLAPPED semantics. On POSIX, this creates handles with nonblocking semantics for non-file handles such as pipes and sockets, however for file, directory and symlink handles it does not set nonblocking, as it is non-portable.

< Using insane POSIX byte range locks

< This is an inode created with no representation on the filing system

110 {
111 none = uint16_t(0), //!< No flags
112 /*! Unlinks the file on handle close. On POSIX, this simply unlinks whatever is pointed
113 to by `path()` upon the call of `close()` if and only if the inode matches. On Windows,
114 if you are on Windows 10 1709 or later, exactly the same thing occurs. If on previous
115 editions of Windows, the file entry does not disappears but becomes unavailable for
116 anyone else to open with an `errc::resource_unavailable_try_again` error return. Because this is confusing, unless the
117 `win_disable_unlink_emulation` flag is also specified, this POSIX behaviour is
118 somewhat emulated by LLFIO on older Windows by renaming the file to a random name on `close()`
119 causing it to appear to have been unlinked immediately.
120 */
121 unlink_on_first_close = uint16_t(1U << 0U),
122
123 /*! Some kernel caching modes have unhelpfully inconsistent behaviours
124 in getting your data onto storage, so by default unless this flag is
125 specified LLFIO adds extra fsyncs to the following operations for the
126 caching modes specified below:
127 * truncation of file length either explicitly or during file open.
128 * closing of the handle either explicitly or in the destructor.
129
130 Additionally on Linux only to prevent loss of file metadata:
131 * On the parent directory whenever a file might have been created.
132 * On the parent directory on file close.
133
134 This only occurs for these kernel caching modes:
135 * caching::none
136 * caching::reads
137 * caching::reads_and_metadata
138 * caching::safety_barriers
139 */
140 disable_safety_barriers = uint16_t(1U << 2U),
141 /*! `file_handle::unlink()` could accidentally delete the wrong file if someone has
142 renamed the open file handle since the time it was opened. To prevent this occuring,
143 where the OS doesn't provide race free unlink-by-open-handle we compare the inode of
144 the path we are about to unlink with that of the open handle before unlinking.
145 \warning This does not prevent races where in between the time of checking the inode
146 and executing the unlink a third party changes the item about to be unlinked. Only
147 operating systems with a true race-free unlink syscall are race free.
148 */
149 disable_safety_unlinks = uint16_t(1U << 3U),
150 /*! Ask the OS to disable prefetching of data. This can improve random
151 i/o performance.
152 */
153 disable_prefetching = uint16_t(1U << 4U),
154 /*! Ask the OS to maximise prefetching of data, possibly prefetching the entire file
155 into kernel cache. This can improve sequential i/o performance.
156 */
157 maximum_prefetching = uint16_t(1U << 5U),
158
159 win_disable_unlink_emulation = uint16_t(1U << 9U), //!< See the documentation for `unlink_on_first_close`
160 /*! Microsoft Windows NTFS, having been created in the late 1980s, did not originally
161 implement extents-based storage and thus could only represent sparse files via
162 efficient compression of intermediate zeros. With NTFS v3.0 (Microsoft Windows 2000),
163 a proper extents-based on-storage representation was added, thus allowing only 64Kb
164 extent chunks written to be stored irrespective of whatever the maximum file extent
165 was set to.
166
167 For various historical reasons, extents-based storage is disabled by default in newly
168 created files on NTFS, unlike in almost every other major filing system. You have to
169 explicitly "opt in" to extents-based storage.
170
171 As extents-based storage is nearly cost free on NTFS, LLFIO by default opts in to
172 extents-based storage for any empty file it creates. If you don't want this, you
173 can specify this flag to prevent that happening.
174 */
175 win_disable_sparse_file_creation = uint16_t(1U << 10U),
176 /*! Filesystems tend to be embarrassingly parallel for operations performed to different
177 inodes. Where LLFIO performs i/o to multiple inodes at a time, it will use OpenMP or
178 the Parallelism or Concurrency standard library extensions to usually complete the
179 operation in constant rather than linear time. If you don't want this default, you can
180 disable default using this flag.
181 */
182 disable_parallelism = uint16_t(1U << 11U),
183 /*! Microsoft Windows NTFS has the option, when creating a directory, to set whether
184 leafname lookup will be case sensitive. This is the only way of getting exact POSIX
185 semantics on Windows without resorting to editing the system registry, however it also
186 affects all code doing lookups within that directory, so we must default it to off.
187 */
188 win_create_case_sensitive_directory = uint16_t(1U << 12U),
189
190 /*! Create the handle in a way where i/o upon it can be multiplexed with other i/o
191 on the same initiating thread of execution i.e. you can perform more than one read
192 concurrently, without using threads. The blocking operations `.read()` and `.write()`
193 may have to use a less efficient, but cancellable, blocking implementation for handles created
194 in this way. On Microsoft Windows, this creates handles with `OVERLAPPED` semantics.
195 On POSIX, this creates handles with nonblocking semantics for non-file handles such
196 as pipes and sockets, however for file, directory and symlink handles it does not set
197 nonblocking, as it is non-portable.
198 */
199 multiplexable = uint16_t(1U << 13U),
200
201 // NOTE: IF UPDATING THIS UPDATE THE std::ostream PRINTER BELOW!!!
202
203 byte_lock_insanity = uint16_t(1U << 14U), //!< Using insane POSIX byte range locks
204 anonymous_inode = uint16_t(1U << 15U) //!< This is an inode created with no representation on the filing system
205 } QUICKCPPLIB_BITFIELD_END(flag)
@ none
No ability to read or write anything, but can synchronise (SYNCHRONIZE or 0)

◆ release()

virtual native_handle_type llfio_v2_xxx::handle::release ( )
inlinevirtualnoexceptinherited

Release the native handle type managed by this handle.

Reimplemented in llfio_v2_xxx::map_handle, and llfio_v2_xxx::mapped_file_handle.

317 {
318 native_handle_type ret(std::move(_v));
319 return ret;
320 }

◆ requires_aligned_io()

bool llfio_v2_xxx::handle::requires_aligned_io ( ) const
inlinenoexceptinherited

True if requires aligned i/o.

350{ return _v.requires_aligned_io(); }
constexpr bool requires_aligned_io() const noexcept
True if requires aligned i/o.
Definition native_handle_type.hpp:188

◆ set_append_only()

virtual result< void > llfio_v2_xxx::handle::set_append_only ( bool  enable)
virtualnoexceptinherited

EXTENSION: Changes whether this handle is append only or not.

Warning
On Windows this is implemented as a bit of a hack to make it fast like on POSIX, so make sure you open the handle for read/write originally. Note unlike on POSIX the append_only disposition will be the only one toggled, seekable and readable will remain turned on.
Errors returnable\n Whatever POSIX fcntl() returns. On Windows nothing is changed on the handle.
Memory Allocations\n No memory allocation.

Reimplemented in llfio_v2_xxx::process_handle.

◆ swap()

void llfio_v2_xxx::handle::swap ( handle o)
inlinenoexceptinherited

Swap with another instance.

257 {
258 handle temp(std::move(*this));
259 *this = std::move(o);
260 o = std::move(temp);
261 }
constexpr handle()
Default constructor.
Definition handle.hpp:223

The documentation for this class was generated from the following files: