libfilezilla
Loading...
Searching...
No Matches
process.hpp
Go to the documentation of this file.
1#ifndef LIBFILEZILLA_PROCESS_HEADER
2#define LIBFILEZILLA_PROCESS_HEADER
3
4#include "libfilezilla.hpp"
5#include "fsresult.hpp"
6#include "event.hpp"
7#include "time.hpp"
8
12
13#include <vector>
14
15namespace fz {
16class event_handler;
18class thread_pool;
19
20
26{
28 read = 0x1,
29
31 write = 0x2,
32};
33
35struct process_event_type;
36
37class process;
38
53
60class FZ_PUBLIC_SYMBOL process final
61{
62public:
65
70 process(thread_pool & pool, event_handler & handler);
71
74 process(process const&) = delete;
75 process& operator=(process const&) = delete;
76
78 enum class io_redirection {
80 redirect,
81
83 none,
84
86 closeall,
87
89 redirect_except_stderr
90 };
91
105 bool spawn(native_string const& cmd, std::vector<native_string> const& args = std::vector<native_string>(), io_redirection redirect_mode = io_redirection::redirect);
106
107 bool spawn(std::vector<native_string> const& command_with_args, io_redirection redirect_mode = io_redirection::redirect);
108
109#if FZ_WINDOWS || FZ_UNIX
111 bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, io_redirection redirect_mode = io_redirection::redirect);
112#endif
113
114#ifndef FZ_WINDOWS
121 bool spawn(native_string const& cmd, std::vector<native_string> const& args, std::vector<int> const& extra_fds, io_redirection redirect_mode = io_redirection::redirect);
122
123 bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, std::vector<int> const& extra_fds, io_redirection redirect_mode = io_redirection::redirect);
124#endif
125
131 void kill();
132
145 bool stop(duration const& timeout = {});
146
153 rwresult read(void* buffer, size_t len);
154
160 rwresult write(void const* buffer, size_t len);
161
162 inline rwresult write(std::string_view const& s) {
163 return write(s.data(), s.size());
164 }
165
166#if FZ_WINDOWS
170 void* handle() const;
171#endif
172
173private:
174 class impl;
175 impl* impl_;
176};
177
178
187bool FZ_PUBLIC_SYMBOL spawn_detached_process(std::vector<native_string> const& cmd_with_args);
188
189#if !FZ_WINDOWS
199class FZ_PUBLIC_SYMBOL forkblock final
200{
201public:
202 forkblock();
203 ~forkblock();
204
205 forkblock(forkblock const&) = delete;
206 forkblock& operator=(forkblock const&) = delete;
207};
208#endif
209
210}
211
212#endif
The buffer class is a simple buffer where data can be appended at the end and consumed at the front....
Definition buffer.hpp:27
The duration class represents a time interval in milliseconds.
Definition time.hpp:291
Definition event_handler.hpp:61
Impersonation tokens for a given user can be used to spawn processes running as that user.
Definition impersonation.hpp:47
rwresult write(void const *buffer, size_t len)
Write data data process.
process(thread_pool &pool, event_handler &handler)
Creates instance with non-blocking event-based redirected communication.
void * handle() const
Returns the HANDLE of the process.
rwresult read(void *buffer, size_t len)
Read data from process.
bool spawn(native_string const &cmd, std::vector< native_string > const &args=std::vector< native_string >(), io_redirection redirect_mode=io_redirection::redirect)
Start the process.
process()
Creates instance for blocking I/O.
~process()
If process still running, calls process::kill().
bool stop(duration const &timeout={})
Stops the spawned process.
io_redirection
IO redirection modes.
Definition process.hpp:78
@ redirect
Redirect the child's stdin/out/err to pipes which will be interacted with through fz::process::read a...
Definition process.hpp:80
bool spawn(impersonation_token const &it, native_string const &cmd, std::vector< native_string > const &args, io_redirection redirect_mode=io_redirection::redirect)
Creates a process running under the user represented by the impersonation token.
Holds the result of read/write operations.
Definition fsresult.hpp:80
This is the recommended event class.
Definition event.hpp:68
A dumb thread-pool for asynchronous tasks.
Definition thread_pool.hpp:64
Declares event_base and simple_event<>.
result and rwresult wrappers for dealing with file system errors.
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition apply.hpp:17
simple_event< process_event_type, process *, process_event_flag > process_event
Definition process.hpp:52
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition string.hpp:69
bool spawn_detached_process(std::vector< native_string > const &cmd_with_args)
Starts a detached process.
process_event_flag
The type of a process event.
Definition process.hpp:26
@ read
Data has become available.
Definition process.hpp:28
@ write
data can be written.
Definition process.hpp:31
Assorted classes dealing with time.