E-MailRelay

Public Member Functions | Friends | List of all members
GNet::Task Class Reference

A class for running an exectuable in a separate process with an asychronous completion callback. More...

`#include <gtask.h>`

## Public Member Functions
| Task (TaskCallback &, ExceptionSink es, const std::string &exec_error_format=std::string(), const G::Identity &=G::Identity::invalid())
| Constructor for an object that can be start()ed or run(). More...
| ~Task ()
| Destructor. More...
void | start (const G::ExecutableCommand &commandline)
| Starts the task by spawning a new process with the given command-line and also starting a thread to wait for it. More...
void | start (const G::ExecutableCommand &commandline, const G::Environment &env, G::NewProcess::Fd fd_stdin=G::NewProcess::Fd::devnull(), G::NewProcess::Fd fd_stdout=G::NewProcess::Fd::pipe(), G::NewProcess::Fd fd_stderr=G::NewProcess::Fd::devnull(), const G::Path &cd=G::Path())
| Overload with more control over the execution environment. More...
void | stop ()
| Attempts to kill the spawned process. More...
std::pair< int, std::string > | run (const G::ExecutableCommand &commandline, const G::Environment &env, G::NewProcess::Fd fd_stdin=G::NewProcess::Fd::devnull(), G::NewProcess::Fd fd_stdout=G::NewProcess::Fd::pipe(), G::NewProcess::Fd fd_stderr=G::NewProcess::Fd::devnull(), const G::Path &cd=G::Path())
| Runs the task synchronously and returns the exit code and pipe output. More...
| Task (const Task &)=delete
| Task (Task &&)=delete
void | operator= (const Task &)=delete
void | operator= (Task &&)=delete

## Friends
class | GNet::TaskImp

## Detailed Description

A class for running an exectuable in a separate process with an asychronous completion callback.

Definition at line 44 of file gtask.h.

## Constructor & Destructor Documentation

## ◆ Task()

GNet::Task::Task | ( | TaskCallback & | callback,
|  | ExceptionSink | es,
|  | const std::string & | exec_error_format = `std::string()`,
|  | const G::Identity & | id = `G::Identity::invalid()`
| ) |  |

Constructor for an object that can be start()ed or run().

The two trailing parameters are passed to the G::NewProcess class.

Definition at line 229 of file gtask.cpp.

## ◆ ~Task()

GNet::Task::~Task | ( |  | ) |

Destructor.

Kills the spawned process and waits for it to terminate, where necessary.

Definition at line 239 of file gtask.cpp.

## Member Function Documentation

## ◆ run()

std::pair< int, std::string > GNet::Task::run | ( | const G::ExecutableCommand & | commandline,
|  | const G::Environment & | env,
|  | G::NewProcess::Fd | fd_stdin = `G::NewProcess::Fd::devnull()`,
|  | G::NewProcess::Fd | fd_stdout = `G::NewProcess::Fd::pipe()`,
|  | G::NewProcess::Fd | fd_stderr = `G::NewProcess::Fd::devnull()`,
|  | const G::Path & | cd = `G::Path()`
| ) |  |

Runs the task synchronously and returns the exit code and pipe output.

Throws if killed. The callback interface is not used.

Definition at line 259 of file gtask.cpp.

## ◆ start() [1/2]

void GNet::Task::start | ( | const G::ExecutableCommand & | commandline | ) |

Starts the task by spawning a new process with the given command-line and also starting a thread to wait for it.

The wait thread signals completion of the child process via the event loop and the TaskCallback interface. Standard output goes to the pipe and standard error is discarded. Throws Busy if still busy from a prior call to start().

Definition at line 273 of file gtask.cpp.

## ◆ start() [2/2]

void GNet::Task::start | ( | const G::ExecutableCommand & | commandline,
|  | const G::Environment & | env,
|  | G::NewProcess::Fd | fd_stdin = `G::NewProcess::Fd::devnull()`,
|  | G::NewProcess::Fd | fd_stdout = `G::NewProcess::Fd::pipe()`,
|  | G::NewProcess::Fd | fd_stderr = `G::NewProcess::Fd::devnull()`,
|  | const G::Path & | cd = `G::Path()`
| ) |  |

Overload with more control over the execution environment.

See also G::NewProcess.

Definition at line 282 of file gtask.cpp.

## ◆ stop()

void GNet::Task::stop | ( |  | ) |

Attempts to kill the spawned process.

No task-done callback will be triggered.

Definition at line 250 of file gtask.cpp.

## Friends And Related Function Documentation

## ◆ GNet::TaskImp

friend class GNet::TaskImp
| friend

Definition at line 96 of file gtask.h.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/gtask.h
- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/gtask.cpp