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

Holds the parameters and future results of a waitpid() system call, as performed by the wait() method. 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.
 
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
 Non-throwing overload. More...
 
std::string output () const
 Returns the first bit of child-process output. More...
 
 NewProcessWaitable (const NewProcessWaitable &)=delete
 
 NewProcessWaitable (NewProcessWaitable &&)=delete
 
void operator= (const NewProcessWaitable &)=delete
 
void operator= (NewProcessWaitable &&)=delete
 

Detailed Description

Holds the parameters and future results of a waitpid() system call, as performed by the wait() method.

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 177 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 388 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 393 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.

Member Function Documentation

◆ assign()

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

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

Definition at line 401 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 484 of file gnewprocess_unix.cpp.

◆ get() [2/2]

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

Non-throwing overload.

Definition at line 518 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 533 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 428 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() ;
<
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 414 of file gnewprocess_unix.cpp.


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