LLFIO v2.00
Loading...
Searching...
No Matches
llfio_v2_xxx::process_handle Class Reference

A handle to this, or another, process. More...

#include "process_handle.hpp"

Inheritance diagram for llfio_v2_xxx::process_handle:
llfio_v2_xxx::handle

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_handleoperator= (const process_handle &o)=delete
 No copy assignment.
 
constexpr process_handle (process_handle &&o) noexcept
 Move the handle.
 
process_handleoperator= (process_handle &&o) noexcept
 Move assignment of handle.
 
void swap (process_handle &o) noexcept
 Swap with another instance.
 
pipe_handlein_pipe () noexcept
 
const pipe_handlein_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_handleerror_pipe () noexcept
 
const pipe_handleerror_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_handleout_pipe () noexcept
 
const pipe_handleout_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_handleclone () const noexcept
 
virtual result< void > set_append_only (bool) noexcept override
 EXTENSION: Changes whether this handle is append only or not.
 
std::unique_ptr< span< path_view_component >, _byte_array_deleterenvironment () 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
 
 QUICKCPPLIB_BITFIELD_BEGIN_T (flag, uint16_t)
 Bitwise flags which can be specified.
 
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.
 
flag flags () const noexcept
 The flags this handle was opened with.
 
native_handle_type native_handle () const noexcept
 The native handle used by this handle.
 

Static Public Member Functions

static const process_handlecurrent () noexcept
 
static result< process_handlelaunch_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_handlelaunch_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
 

Detailed Description

A handle to this, or another, process.

Member Enumeration Documentation

◆ bitfield__flag

The behaviour of theprocess handle.

Enumerator
none 

No flags.

no_redirect_in_pipe 

Do not redirect the stdin for a launched process.

no_redirect_out_pipe 

Do not redirect the stdout for a launched process.

no_redirect_error_pipe 

Do not redirect the stderr for a launched process.

wait_on_close 

Wait for the process to exit in .close()

release_pipes_on_close 

Release the pipes in .close(). They are closed otherwise.

no_multiplexable_pipes 

Do not create any redirected pipes as multiplexable.

51 {none = 0U, //!< No flags
52 no_redirect_in_pipe = 1U << 1U, //!< Do not redirect the `stdin` for a launched process
53 no_redirect_out_pipe = 1U << 2U, //!< Do not redirect the `stdout` for a launched process
54 no_redirect_error_pipe = 1U << 3U, //!< Do not redirect the `stderr` for a launched process
55
56 wait_on_close = 1U << 4U, //!< Wait for the process to exit in `.close()`
57 release_pipes_on_close = 1U << 5U, //!< Release the pipes in `.close()`. They are closed otherwise.
58 no_multiplexable_pipes = 1U << 6U, //!< Do not create any redirected pipes as multiplexable
59
60 // NOTE: IF UPDATING THIS UPDATE THE std::ostream PRINTER BELOW!!!
61 no_redirect = no_redirect_in_pipe | no_redirect_out_pipe | no_redirect_error_pipe} QUICKCPPLIB_BITFIELD_END(flag)
@ no_redirect_out_pipe
Do not redirect the stdout for a launched process.
Definition process_handle.hpp:53
@ no_multiplexable_pipes
Do not create any redirected pipes as multiplexable.
Definition process_handle.hpp:58
@ wait_on_close
Wait for the process to exit in .close()
Definition process_handle.hpp:56
@ none
No flags.
Definition process_handle.hpp:51
@ no_redirect_error_pipe
Do not redirect the stderr for a launched process.
Definition process_handle.hpp:54
@ release_pipes_on_close
Release the pipes in .close(). They are closed otherwise.
Definition process_handle.hpp:57
@ no_redirect_in_pipe
Do not redirect the stdin for a launched process.
Definition process_handle.hpp:52

◆ caching

enum class llfio_v2_xxx::handle::caching : unsigned char
stronginherited

What i/o on the handle may complete immediately due to kernel caching.

Enumerator
none 

No caching whatsoever, all reads and writes come from storage (i.e. O_DIRECT|O_SYNC). Align all i/o to 4Kb boundaries for this to work. disable_safety_barriers can be used here.

only_metadata 

Cache reads and writes of metadata but avoid caching data (O_DIRECT), thus i/o here does not affect other cached data for other handles. Align all i/o to 4Kb boundaries for this to work.

reads 

Cache reads only. Writes of data and metadata do not complete until reaching storage (O_SYNC). disable_safety_barriers can be used here.

reads_and_metadata 

Cache reads and writes of metadata, but writes of data do not complete until reaching storage (O_DSYNC). disable_safety_barriers can be used here.

all 

Cache reads and writes of data and metadata so they complete immediately, sending writes to storage at some point when the kernel decides (this is the default file system caching on a system).

safety_barriers 

Cache reads and writes of data and metadata so they complete immediately, but issue safety barriers at certain points. See documentation for disable_safety_barriers.

temporary 

Cache reads and writes of data and metadata so they complete immediately, only sending any updates to storage on last handle close in the system or if memory becomes tight as this file is expected to be temporary (Windows and FreeBSD only).

97 {
98 unchanged = 0,
99 none =
100 1, //!< No caching whatsoever, all reads and writes come from storage (i.e. <tt>O_DIRECT|O_SYNC</tt>). Align all i/o to 4Kb boundaries for this to work. <tt>disable_safety_barriers</tt> can be used here.
102 2, //!< Cache reads and writes of metadata but avoid caching data (<tt>O_DIRECT</tt>), thus i/o here does not affect other cached data for other handles. Align all i/o to 4Kb boundaries for this to work.
103 reads =
104 3, //!< Cache reads only. Writes of data and metadata do not complete until reaching storage (<tt>O_SYNC</tt>). <tt>disable_safety_barriers</tt> can be used here.
106 5, //!< Cache reads and writes of metadata, but writes of data do not complete until reaching storage (<tt>O_DSYNC</tt>). <tt>disable_safety_barriers</tt> can be used here.
107 all =
108 6, //!< Cache reads and writes of data and metadata so they complete immediately, sending writes to storage at some point when the kernel decides (this is the default file system caching on a system).
110 7, //!< Cache reads and writes of data and metadata so they complete immediately, but issue safety barriers at certain points. See documentation for <tt>disable_safety_barriers</tt>.
111 temporary =
112 8 //!< Cache reads and writes of data and metadata so they complete immediately, only sending any updates to storage on last handle close in the system or if memory becomes tight as this file is expected to be temporary (Windows and FreeBSD only).
113 // NOTE: IF UPDATING THIS UPDATE THE std::ostream PRINTER BELOW!!!
114 };
@ none
No ability to read or write anything, but can synchronise (SYNCHRONIZE or 0)
@ reads
Cache reads only. Writes of data and metadata do not complete until reaching storage (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...

◆ creation

enum class llfio_v2_xxx::handle::creation : unsigned char
stronginherited

On opening, do we also create a new file or truncate an existing one?

Enumerator
open_existing 

Filesystem entry must already exist.

only_if_not_exist 

Filesystem entry must NOT exist, and is atomically created by the success of this operation.

if_needed 

If filesystem entry exists that is used, else one is created.

truncate_existing 

Filesystem entry must already exist. It is atomically truncated on open, leaving creation date and unique identifier unmodified.

always_new 

If filesystem entry exists, it is atomically replaced with a new inode, else a new entry is created.

87 {
88 open_existing = 0, //!< Filesystem entry must already exist
89 only_if_not_exist, //!< Filesystem entry must NOT exist, and is atomically created by the success of this operation
90 if_needed, //!< If filesystem entry exists that is used, else one is created
91 truncate_existing, //!< Filesystem entry must already exist. It is atomically truncated on open, leaving creation date and unique identifier unmodified.
92 always_new //!< If filesystem entry exists, it is atomically replaced with a new inode, else a new entry is created.
93 // NOTE: IF UPDATING THIS UPDATE THE std::ostream PRINTER BELOW!!!
94 };
@ if_needed
If filesystem entry exists that is used, else one is created.
@ open_existing
Filesystem entry must already exist.
@ truncate_existing
Filesystem entry must already exist. It is atomically truncated on open, leaving creation date and un...
@ only_if_not_exist
Filesystem entry must NOT exist, and is atomically created by the success of this operation.
@ always_new
If filesystem entry exists, it is atomically replaced with a new inode, else a new entry is created.

◆ mode

enum class llfio_v2_xxx::handle::mode : unsigned char
stronginherited

The behaviour of the handle: does it read, read and write, or atomic append?

Enumerator
none 

No ability to read or write anything, but can synchronise (SYNCHRONIZE or 0)

attr_read 

Ability to read attributes (FILE_READ_ATTRIBUTES|SYNCHRONIZE or O_RDONLY)

attr_write 

Ability to read and write attributes (FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|SYNCHRONIZE or O_RDONLY)

read 

Ability to read (READ_CONTROL|FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA|SYNCHRONISE or O_RDONLY)

write 

Ability to read and write (READ_CONTROL|FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|FILE_APPEND_DATA|SYNCHRONISE or O_RDWR)

append 

All mainstream OSs and CIFS guarantee this is atomic with respect to all other appenders (FILE_APPEND_DATA|SYNCHRONISE or O_APPEND)

74 {
75 unchanged = 0,
76 none = 2, //!< No ability to read or write anything, but can synchronise (SYNCHRONIZE or 0)
77 attr_read = 4, //!< Ability to read attributes (FILE_READ_ATTRIBUTES|SYNCHRONIZE or O_RDONLY)
78 attr_write = 5, //!< Ability to read and write attributes (FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|SYNCHRONIZE or O_RDONLY)
79 read = 6, //!< Ability to read (READ_CONTROL|FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA|SYNCHRONISE or O_RDONLY)
80 write =
81 7, //!< Ability to read and write (READ_CONTROL|FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|FILE_APPEND_DATA|SYNCHRONISE or O_RDWR)
82 append = 9 //!< All mainstream OSs and CIFS guarantee this is atomic with respect to all other appenders (FILE_APPEND_DATA|SYNCHRONISE or O_APPEND)
83 // NOTE: IF UPDATING THIS UPDATE THE std::ostream PRINTER BELOW!!!
84 };
@ append
All mainstream OSs and CIFS guarantee this is atomic with respect to all other appenders (FILE_APPEND...
@ attr_write
Ability to read and write attributes (FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|SYNCHRONIZE or O_RDO...
@ attr_read
Ability to read attributes (FILE_READ_ATTRIBUTES|SYNCHRONIZE or O_RDONLY)
@ read
Ability to read (READ_CONTROL|FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA|SYNCHRONISE or O_RDONL...
@ write
Ability to read and write (READ_CONTROL|FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_WRITE_D...

Constructor & Destructor Documentation

◆ process_handle() [1/4]

constexpr llfio_v2_xxx::process_handle::process_handle ( )
inlineconstexpr

Default constructor.

74{} // NOLINT

◆ process_handle() [2/4]

constexpr llfio_v2_xxx::process_handle::process_handle ( native_handle_type  h,
flag  flags = flag::none 
)
inlineexplicitconstexprnoexcept

Construct a handle from a supplied native handle.

77 : handle(std::move(h))
78 , _flags(flags)
79 {
80 }
flag flags() const noexcept
The flags this handle was opened with.
Definition handle.hpp:423
constexpr handle()
Default constructor.
Definition handle.hpp:229

◆ process_handle() [3/4]

constexpr llfio_v2_xxx::process_handle::process_handle ( handle &&  o,
flag  flags = flag::none 
)
inlineexplicitconstexprnoexcept

Explicit conversion from handle permitted.

83 : handle(std::move(o))
84 , _flags(flags)
85 {
86 }

◆ ~process_handle()

virtual llfio_v2_xxx::process_handle::~process_handle ( )
inlineoverridevirtual
88 {
89 (void) close_pipes();
90 if(_v)
91 {
92 (void) process_handle::close();
93 _v = {};
94 }
95 }
virtual result< void > close() noexcept override
Immediately close this handle, possibly closing the pipes, possibly blocking until a child process ex...
result< void > close_pipes() noexcept
Close or release all the pipes, depending on flag::release_pipes_on_close
Definition process_handle.hpp:148

◆ process_handle() [4/4]

constexpr llfio_v2_xxx::process_handle::process_handle ( process_handle &&  o)
inlineconstexprnoexcept

Move the handle.

102 : handle(std::move(o))
103 , _flags(o._flags)
104 , _in_pipe(std::move(o._in_pipe))
105 , _out_pipe(std::move(o._out_pipe))
106 , _error_pipe(std::move(o._error_pipe))
107 {
108 }

Member Function Documentation

◆ 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.

416{ 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.

420{ 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.

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

◆ clone()

result< process_handle > llfio_v2_xxx::process_handle::clone ( ) const
noexcept

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

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

◆ close()

virtual result< void > llfio_v2_xxx::process_handle::close ( )
overridevirtualnoexcept

Immediately close this handle, possibly closing the pipes, possibly blocking until a child process exits.

Reimplemented from llfio_v2_xxx::handle.

◆ close_pipes()

result< void > llfio_v2_xxx::process_handle::close_pipes ( )
inlinenoexcept

Close or release all the pipes, depending on flag::release_pipes_on_close

149 {
150 if(!(_.flags & flag::release_pipes_on_close))
151 {
152 // Close the other's side's write pipes first, as closing its
153 // read pipe may cause it to immediately exit
154 if(_in_pipe.is_valid())
155 {
156 OUTCOME_TRY(_in_pipe.close());
157 }
158 if(_error_pipe.is_valid())
159 {
160 OUTCOME_TRY(_error_pipe.close());
161 }
162 if(_out_pipe.is_valid())
163 {
164 OUTCOME_TRY(_out_pipe.close());
165 }
166 }
167 else
168 {
169 _in_pipe.release();
170 _error_pipe.release();
171 _out_pipe.release();
172 }
173 return success();
174 }
virtual native_handle_type release() noexcept
Release the native handle type managed by this handle.
Definition handle.hpp:322
bool is_valid() const noexcept
True if the handle is valid (and usually open)
Definition handle.hpp:329
virtual result< void > close() noexcept override
Immediately close the native handle type managed by this handle.
Definition pipe_handle.hpp:272

◆ current()

static const process_handle & llfio_v2_xxx::process_handle::current ( )
staticnoexcept

Return a process handle referring to the current process.

◆ current_path()

virtual result< path_type > llfio_v2_xxx::process_handle::current_path ( ) const
overridevirtualnoexcept

Returns the current path of the binary the process is executing.

Note
If the current path cannot be retrieved on this platform (i.e. invariant to concurrent filesystem modification), an empty path is returned. This includes the current process.

Reimplemented from llfio_v2_xxx::handle.

◆ environment()

std::unique_ptr< span< path_view_component >, _byte_array_deleter > llfio_v2_xxx::process_handle::environment ( ) const
noexcept

Retrieves the current environment of the process.

Note
If the current environment cannot be retrieved on this platform, a null pointer is returned.

◆ error_pipe() [1/2]

const pipe_handle & llfio_v2_xxx::process_handle::error_pipe ( ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

140{ return _error_pipe; }

◆ error_pipe() [2/2]

pipe_handle & llfio_v2_xxx::process_handle::error_pipe ( )
inlinenoexcept

A pipe with which one can read what another process writes to stderr, or by which this process can write to stderr.

138{ return _error_pipe; }

◆ flags()

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

The flags this handle was opened with.

423{ return _.flags; }

◆ in_pipe() [1/2]

const pipe_handle & llfio_v2_xxx::process_handle::in_pipe ( ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

134{ return _in_pipe; }

◆ in_pipe() [2/2]

pipe_handle & llfio_v2_xxx::process_handle::in_pipe ( )
inlinenoexcept

A pipe with which one can read what another process writes to stdout, or by which this process can read from stdin. Therefore always read-only.

132{ return _in_pipe; }

◆ is_allocation()

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

True if a memory allocation.

377{ return _v.is_allocation(); }

◆ is_append_only()

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

True if the handle is append only.

336{ return _v.is_append_only(); }

◆ is_directory()

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

True if a directory.

363{ return _v.is_directory(); }

◆ is_http_socket()

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

True if a HTTP socket.

383{ return _v.is_http_socket(); }

◆ is_kernel_handle()

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

True if native_handle() is a valid kernel handle.

358{ return _v.is_kernel_handle(); }

◆ is_multiplexable()

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

True if multiplexable.

350{ 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.

371{ return _v.is_multiplexer(); }

◆ is_nonblocking()

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

True if nonblocking.

352{ return _v.is_nonblocking(); }

◆ is_path()

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

True if a path or a directory.

379{ return _v.is_path(); }

◆ is_pipe()

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

True if a pipe.

367{ return _v.is_pipe(); }

◆ is_process()

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

True if a process.

373{ return _v.is_process(); }

◆ is_readable()

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

True if the handle is readable.

332{ return _v.is_readable(); }

◆ is_regular()

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

True if a regular file or device.

361{ return _v.is_regular(); }

◆ is_section()

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

True if a memory section.

375{ return _v.is_section(); }

◆ is_seekable()

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

True if seekable.

354{ return _v.is_seekable(); }

◆ is_socket()

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

True if a socket.

369{ return _v.is_socket(); }

◆ is_symlink()

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

True if a symlink.

365{ return _v.is_symlink(); }

◆ is_tls_socket()

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

True if a TLS socket.

381{ return _v.is_tls_socket(); }

◆ is_valid()

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

True if the handle is valid (and usually open)

329{ return _v.is_valid(); }

◆ is_writable()

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

True if the handle is writable.

334{ return _v.is_writable(); }

◆ kernel_caching()

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

Kernel cache strategy used by this handle.

387 {
388 const bool safety_barriers = !!(_v.behaviour & native_handle_type::disposition::safety_barriers);
389 const bool cache_metadata = !!(_v.behaviour & native_handle_type::disposition::cache_metadata);
390 const bool cache_reads = !!(_v.behaviour & native_handle_type::disposition::cache_reads);
391 const bool cache_writes = !!(_v.behaviour & native_handle_type::disposition::cache_writes);
392 const bool cache_temporary = !!(_v.behaviour & native_handle_type::disposition::cache_temporary);
393 if(cache_temporary)
394 {
395 return caching::temporary;
396 }
397 if(cache_metadata && cache_reads && cache_writes)
398 {
400 }
401 if(cache_metadata && cache_reads)
402 {
404 }
405 if(cache_reads)
406 {
407 return caching::reads;
408 }
409 if(cache_metadata)
410 {
412 }
413 return caching::none;
414 }
@ none
No caching whatsoever, all reads and writes come from storage (i.e. O_DIRECT|O_SYNC)....

◆ launch_process() [1/2]

static result< process_handle > llfio_v2_xxx::process_handle::launch_process ( path_view  path,
span< path_view_component args,
flag  flags = flag::wait_on_close 
)
inlinestaticnoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

232{ return launch_process(path, args, *current().environment(), flags); }
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 const process_handle & current() noexcept
std::unique_ptr< span< path_view_component >, _byte_array_deleter > environment() const noexcept
result< path_handle > path(const path_handle &base, path_handle::path_view_type path) noexcept
Definition path_handle.hpp:171

◆ launch_process() [2/2]

static result< process_handle > llfio_v2_xxx::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 
)
staticnoexcept

Create a new process launching the binary at path.

Parameters
pathThe absolute path to the binary to launch.
argsAn array of arguments to pass to the process.
envAn array of environment variables to set for the process, which defaults to the current process' environment.
flagsAny 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.

Errors returnable
Any of the values POSIX posix_spawn() or CreateProcess() can return.

◆ native_handle()

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

The native handle used by this handle.

425{ return _v; }

◆ operator=()

process_handle & llfio_v2_xxx::process_handle::operator= ( process_handle &&  o)
inlinenoexcept

Move assignment of handle.

111 {
112 if(this == &o)
113 {
114 return *this;
115 }
116 this->~process_handle();
117 new(this) process_handle(std::move(o));
118 return *this;
119 }
constexpr process_handle()
Default constructor.
Definition process_handle.hpp:74

◆ out_pipe() [1/2]

const pipe_handle & llfio_v2_xxx::process_handle::out_pipe ( ) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

146{ return _out_pipe; }

◆ out_pipe() [2/2]

pipe_handle & llfio_v2_xxx::process_handle::out_pipe ( )
inlinenoexcept

A pipe with which one can write what another process reads from stdin, or by which this process can write to stdout. Therefore always write-only.

144{ return _out_pipe; }

◆ 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

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

◆ 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.

323 {
324 native_handle_type ret(std::move(_v));
325 return ret;
326 }

◆ requires_aligned_io()

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

True if requires aligned i/o.

356{ return _v.requires_aligned_io(); }

◆ set_append_only()

virtual result< void > llfio_v2_xxx::process_handle::set_append_only ( bool  enable)
inlineoverridevirtualnoexcept

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
Whatever POSIX fcntl() returns. On Windows nothing is changed on the handle.
Memory Allocations
No memory allocation.

Reimplemented from llfio_v2_xxx::handle.

195{ return errc::operation_not_supported; }

◆ swap() [1/2]

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

Swap with another instance.

263 {
264 handle temp(std::move(*this));
265 *this = std::move(o);
266 o = std::move(temp);
267 }

◆ swap() [2/2]

void llfio_v2_xxx::process_handle::swap ( process_handle o)
inlinenoexcept

Swap with another instance.

123 {
124 process_handle temp(std::move(*this));
125 *this = std::move(o);
126 o = std::move(temp);
127 }

◆ try_wait()

template<class... Args>
bool llfio_v2_xxx::process_handle::try_wait ( Args &&...  args)
inlinenoexcept

◆ try_wait_for()

template<class... Args, class Rep , class Period >
bool llfio_v2_xxx::process_handle::try_wait_for ( Args &&...  args,
const std::chrono::duration< Rep, Period > &  duration 
)
inlinenoexcept

◆ try_wait_until()

template<class... Args, class Clock , class Duration >
bool llfio_v2_xxx::process_handle::try_wait_until ( Args &&...  args,
const std::chrono::time_point< Clock, Duration > &  timeout 
)
inlinenoexcept

◆ wait()

result< intptr_t > llfio_v2_xxx::process_handle::wait ( deadline  d = {}) const
noexcept

Waits until a process exits, returning its exit code.

Member Data Documentation

◆ _flags

flag llfio_v2_xxx::process_handle::_flags {flag::none}
protected
64{flag::none};

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