LLFIO  v2.00 late beta
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

using path_type = handle::path_type
 
using extent_type = handle::extent_type
 
using size_type = handle::size_type
 
enum  mode : unsigned char {
  unchanged = 0, mode::none = 2, mode::attr_read = 4, mode::attr_write = 5,
  mode::read = 6, mode::write = 7, mode::append = 9
}
 The behaviour of the handle: does it read, read and write, or atomic append? More...
 
enum  creation : unsigned char {
  creation::open_existing = 0, creation::only_if_not_exist, creation::if_needed, creation::truncate_existing,
  creation::always_new
}
 On opening, do we also create a new file or truncate an existing one? More...
 
enum  caching : unsigned char {
  unchanged = 0, caching::none = 1, caching::only_metadata = 2, caching::reads = 3,
  caching::reads_and_metadata = 5, caching::all = 6, caching::safety_barriers = 7, caching::temporary = 8
}
 What i/o on the handle may complete immediately due to kernel caching. More...
 

Public Member Functions

 QUICKCPPLIB_BITFIELD_BEGIN (flag)
 The behaviour of theprocess handle. More...
 
 QUICKCPPLIB_BITFIELD_END (flag)
 
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_typecurrent_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. More...
 
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
 
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_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.
 
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.
 

Static Protected Member Functions

static constexpr void _set_caching (native_handle_type &nativeh, caching caching) noexcept
 

Protected Attributes

flag _flags {flag::none}
 
pipe_handle _in_pipe
 
pipe_handle _out_pipe
 
pipe_handle _error_pipe
 
native_handle_type _v
 

Detailed Description

A handle to this, or another, process.

Member Enumeration Documentation

◆ caching

enum 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).

88  : unsigned char // bit 0 set means safety barriers enabled
89  {
90  unchanged = 0,
91  none = 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.
92  only_metadata = 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.
93  reads = 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.
94  reads_and_metadata = 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.
95  all = 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).
96  safety_barriers = 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>.
97  temporary = 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).
98  // NOTE: IF UPDATING THIS UPDATE THE std::ostream PRINTER BELOW!!!
99  };

◆ creation

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

78  : unsigned char
79  {
80  open_existing = 0, //!< Filesystem entry must already exist
81  only_if_not_exist, //!< Filesystem entry must NOT exist, and is atomically created by the success of this operation
82  if_needed, //!< If filesystem entry exists that is used, else one is created
83  truncate_existing, //!< Filesystem entry must already exist. It is atomically truncated on open, leaving creation date and unique identifier unmodified.
84  always_new //!< If filesystem entry exists, it is atomically replaced with a new inode, else a new entry is created.
85  // NOTE: IF UPDATING THIS UPDATE THE std::ostream PRINTER BELOW!!!
86  };

◆ mode

enum 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)

66  : unsigned char // bit 0 set means writable
67  {
68  unchanged = 0,
69  none = 2, //!< No ability to read or write anything, but can synchronise (SYNCHRONIZE or 0)
70  attr_read = 4, //!< Ability to read attributes (FILE_READ_ATTRIBUTES|SYNCHRONIZE or O_RDONLY)
71  attr_write = 5, //!< Ability to read and write attributes (FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|SYNCHRONIZE or O_RDONLY)
72  read = 6, //!< Ability to read (READ_CONTROL|FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA|SYNCHRONISE or O_RDONLY)
73  write = 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)
74  append = 9 //!< All mainstream OSs and CIFS guarantee this is atomic with respect to all other appenders (FILE_APPEND_DATA|SYNCHRONISE or O_APPEND)
75  // NOTE: IF UPDATING THIS UPDATE THE std::ostream PRINTER BELOW!!!
76  };

Member Function Documentation

◆ clone()

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

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

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

◆ current()

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

Return a process handle referring to the current process.

◆ current_path()

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

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
inlinenoexcept

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()

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; }

◆ in_pipe()

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; }

◆ launch_process()

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 
)
inlinestaticnoexcept

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\n Any of the values POSIX posix_spawn() or CreateProcess() can return.

◆ out_pipe()

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()

llfio_v2_xxx::process_handle::QUICKCPPLIB_BITFIELD_BEGIN ( flag  )
inline

The behaviour of theprocess handle.

< No flags

< Do not redirect the stdin for a launched process

< Do not redirect the stdout for a launched process

< Do not redirect the stderr for a launched process

< Wait for the process to exit in .close()

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

< 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);

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

Reimplemented from llfio_v2_xxx::handle.

195 { return errc::operation_not_supported; }

◆ wait()

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

Waits until a process exits, returning its exit code.


The documentation for this class was generated from the following file:
llfio_v2_xxx::write
io_handle::io_result< io_handle::const_buffers_type > write(io_handle &self, io_handle::io_request< io_handle::const_buffers_type > reqs, deadline d=deadline()) noexcept
Write data to the open handle.
Definition: io_handle.hpp:596
llfio_v2_xxx::read
file_handle::io_result< file_handle::size_type > read(file_handle &self, file_handle::extent_type offset, std::initializer_list< file_handle::buffer_type > lst, deadline d=deadline()) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: file_handle.hpp:479