E-MailRelay
Public Member Functions | List of all members
G::NewProcessWaitable Class Reference

Holds the parameters and future results of a waitpid() system call. More...

#include <gnewprocess.h>

Public Member Functions

 NewProcessWaitable ()
 Default constructor for an object where wait() does nothing and get() returns zero. More...
 
 NewProcessWaitable (pid_t pid, int fd=-1)
 Constructor taking a posix process-id and optional readable file descriptor. More...
 
 NewProcessWaitable (HANDLE hprocess, HANDLE hpipe, int)
 Constructor taking process and pipe handles. More...
 
void assign (pid_t pid, int fd)
 Reinitialises as if constructed with the given proces-id and file descriptor. More...
 
void assign (HANDLE hprocess, HANDLE hpipe, int)
 Reinitialises as if constructed with the given proces handle and pipe handle. More...
 
NewProcessWaitablewait ()
 Waits for the process identified by the constructor parameter to exit. More...
 
void waitp (std::promise< std::pair< int, std::string > >) noexcept
 Calls wait() and then sets the given promise with the get() and output() values or an exception: More...
 
int get () const
 Returns the result of the wait() as either the process exit code or as a thrown exception. More...
 
int get (std::nothrow_t, int exit_code_on_error=127) const noexcept
 Non-throwing overload. More...
 
std::string output () const
 Returns the first bit of child-process output. More...
 
 NewProcessWaitable (const NewProcessWaitable &)=delete
 
 NewProcessWaitable (NewProcessWaitable &&)=delete
 
NewProcessWaitableoperator= (const NewProcessWaitable &)=delete
 
NewProcessWaitableoperator= (NewProcessWaitable &&)=delete
 

Detailed Description

Holds the parameters and future results of a waitpid() system call.

The wait() method can be called from a worker thread and the results collected by the main thread using get() once the worker thread has signalled that it has finished. The signalling mechanism is outside the scope of this class (see std::promise, GNet::FutureEvent).

Definition at line 197 of file gnewprocess.h.

Constructor & Destructor Documentation

◆ NewProcessWaitable() [1/3]

G::NewProcessWaitable::NewProcessWaitable ( )

Default constructor for an object where wait() does nothing and get() returns zero.

Definition at line 381 of file gnewprocess_unix.cpp.

◆ NewProcessWaitable() [2/3]

G::NewProcessWaitable::NewProcessWaitable ( pid_t  pid,
int  fd = -1 
)
explicit

Constructor taking a posix process-id and optional readable file descriptor.

Only used by the unix implementation of G::NewProcess.

Definition at line 387 of file gnewprocess_unix.cpp.

◆ NewProcessWaitable() [3/3]

G::NewProcessWaitable::NewProcessWaitable ( HANDLE  hprocess,
HANDLE  hpipe,
int   
)

Constructor taking process and pipe handles.

Only used by the windows implementation of G::NewProcess.

Definition at line 595 of file gnewprocess_win32.cpp.

Member Function Documentation

◆ assign() [1/2]

void G::NewProcessWaitable::assign ( HANDLE  hprocess,
HANDLE  hpipe,
int   
)

Reinitialises as if constructed with the given proces handle and pipe handle.

Definition at line 607 of file gnewprocess_win32.cpp.

◆ assign() [2/2]

void G::NewProcessWaitable::assign ( pid_t  pid,
int  fd 
)

Reinitialises as if constructed with the given proces-id and file descriptor.

Definition at line 396 of file gnewprocess_unix.cpp.

◆ get() [1/2]

int G::NewProcessWaitable::get ( ) const

Returns the result of the wait() as either the process exit code or as a thrown exception.

Typically called by the main thread after the wait() worker thread has signalled its completion. Returns zero if there is no process to wait for.

Definition at line 481 of file gnewprocess_unix.cpp.

◆ get() [2/2]

int G::NewProcessWaitable::get ( std::nothrow_t  ,
int  exit_code_on_error = 127 
) const
noexcept

Non-throwing overload.

Definition at line 515 of file gnewprocess_unix.cpp.

◆ output()

std::string G::NewProcessWaitable::output ( ) const

Returns the first bit of child-process output.

Used after get().

Definition at line 530 of file gnewprocess_unix.cpp.

◆ wait()

G::NewProcessWaitable & G::NewProcessWaitable::wait ( )

Waits for the process identified by the constructor parameter to exit.

Returns *this. This method can be called from a separate worker thread.

Definition at line 425 of file gnewprocess_unix.cpp.

◆ waitp()

void G::NewProcessWaitable::waitp ( std::promise< std::pair< int, std::string > >  p)
noexcept

Calls wait() and then sets the given promise with the get() and output() values or an exception:

< std::promise<int,std::string> p ;
< std::future<int,std::string> f = p.get_future() ;
< std::thread t( std::bind(&NewProcessWaitable::waitp,waitable,_1) , std::move(p) ) ;
< f.wait() ;
< t.join() ;
< int e = f.get().first ;
<
void waitp(std::promise< std::pair< int, std::string > >) noexcept
Calls wait() and then sets the given promise with the get() and output() values or an exception:

Definition at line 410 of file gnewprocess_unix.cpp.


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