LLFIO
v2.00
|
A handle to this, or another, process. More...
#include "process_handle.hpp"
Classes | |
struct | _byte_array_deleter |
Public Types | |
enum | bitfield__flag : unsigned { none = 0U , no_redirect_in_pipe = 1U << 1U , no_redirect_out_pipe = 1U << 2U , no_redirect_error_pipe = 1U << 3U , wait_on_close = 1U << 4U , release_pipes_on_close = 1U << 5U , no_multiplexable_pipes = 1U << 6U , no_redirect = no_redirect_in_pipe | no_redirect_out_pipe | no_redirect_error_pipe } |
The behaviour of theprocess handle. More... | |
using | path_type = handle::path_type |
using | extent_type = handle::extent_type |
using | size_type = handle::size_type |
enum class | mode : unsigned char { unchanged = 0 , none = 2 , attr_read = 4 , attr_write = 5 , read = 6 , write , append = 9 } |
The behaviour of the handle: does it read, read and write, or atomic append? More... | |
enum class | creation : unsigned char { open_existing = 0 , only_if_not_exist , if_needed , truncate_existing , always_new } |
On opening, do we also create a new file or truncate an existing one? More... | |
enum class | caching : unsigned char { unchanged = 0 , none , only_metadata , reads , reads_and_metadata , all , safety_barriers , temporary } |
What i/o on the handle may complete immediately due to kernel caching. More... | |
Public Member Functions | |
constexpr | process_handle () |
Default constructor. | |
constexpr | process_handle (native_handle_type h, flag flags=flag::none) noexcept |
Construct a handle from a supplied native handle. | |
constexpr | process_handle (handle &&o, flag flags=flag::none) noexcept |
Explicit conversion from handle permitted. | |
process_handle (const process_handle &)=delete | |
No copy construction (use clone()) | |
process_handle & | operator= (const process_handle &o)=delete |
No copy assignment. | |
constexpr | process_handle (process_handle &&o) noexcept |
Move the handle. | |
process_handle & | operator= (process_handle &&o) noexcept |
Move assignment of handle. | |
void | swap (process_handle &o) noexcept |
Swap with another instance. | |
pipe_handle & | in_pipe () noexcept |
const pipe_handle & | in_pipe () const noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
pipe_handle & | error_pipe () noexcept |
const pipe_handle & | error_pipe () const noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
pipe_handle & | out_pipe () noexcept |
const pipe_handle & | out_pipe () const noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
result< void > | close_pipes () noexcept |
Close or release all the pipes, depending on flag::release_pipes_on_close | |
bool | is_running () const noexcept |
Returns true if the process is currently running. | |
virtual result< path_type > | current_path () const noexcept override |
virtual result< void > | close () noexcept override |
Immediately close this handle, possibly closing the pipes, possibly blocking until a child process exits. | |
result< process_handle > | clone () const noexcept |
virtual result< void > | set_append_only (bool) noexcept override |
EXTENSION: Changes whether this handle is append only or not. More... | |
std::unique_ptr< span< path_view_component >, _byte_array_deleter > | environment () const noexcept |
result< intptr_t > | wait (deadline d={}) const noexcept |
template<class... Args> | |
bool | try_wait (Args &&... args) noexcept |
template<class... Args, class Rep , class Period > | |
bool | try_wait_for (Args &&... args, const std::chrono::duration< Rep, Period > &duration) noexcept |
template<class... Args, class Clock , class Duration > | |
bool | try_wait_until (Args &&... args, const std::chrono::time_point< Clock, Duration > &timeout) 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. More... | |
void | swap (handle &o) noexcept |
Swap with another instance. | |
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. | |
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 Public Member Functions | |
static const process_handle & | current () noexcept |
static result< process_handle > | launch_process (path_view path, span< path_view_component > args, span< path_view_component > env= *current().environment(), flag flags=flag::wait_on_close) noexcept |
static result< process_handle > | launch_process (path_view path, span< path_view_component > args, flag flags=flag::wait_on_close) noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Protected Attributes | |
flag | _flags {flag::none} |
pipe_handle | _in_pipe |
pipe_handle | _out_pipe |
pipe_handle | _error_pipe |
union { | |
native_handle_type _v | |
struct { | |
intptr_t _padding0_ | |
uint32_t _padding1_ | |
flag flags | |
uint16_t _padding2_ | |
} _ | |
}; | |
A handle to this, or another, process.
enum llfio_v2_xxx::process_handle::bitfield__flag : unsigned |
The behaviour of theprocess handle.
|
stronginherited |
What i/o on the handle may complete immediately due to kernel caching.
|
stronginherited |
On opening, do we also create a new file or truncate an existing one?
|
stronginherited |
The behaviour of the handle: does it read, read and write, or atomic append?
|
inlinenoexcept |
Clone this handle (copy constructor is disabled to avoid accidental copying)
|
inlinestaticnoexcept |
Return a process handle referring to the current process.
|
inlineoverridevirtualnoexcept |
Returns the current path of the binary the process is executing.
Reimplemented from llfio_v2_xxx::handle.
|
inlinenoexcept |
Retrieves the current environment of the process.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticnoexcept |
Create a new process launching the binary at path
.
path | The absolute path to the binary to launch. |
args | An array of arguments to pass to the process. |
env | An array of environment variables to set for the process, which defaults to the current process' environment. |
flags | Any additional custom behaviours. |
This is the only handle creation function in LLFIO which requires an absolute path. This is because no platform implements race-free process launch, and worse, there is no way of non-intrusively emulating race-free process launch either. So we accept the inevitable, launching child processes is always racy with respect to concurrent filesystem modification.
|
inlinenoexcept |
|
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.
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
|
inlineoverridevirtualnoexcept |
EXTENSION: Changes whether this handle is append only or not.
Reimplemented from llfio_v2_xxx::handle.
|
inlinenoexcept |
Waits until a process exits, returning its exit code.