libfilezilla
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 
13 #include <vector>
14 
15 namespace fz {
16 class event_handler;
17 class impersonation_token;
18 class thread_pool;
19 
20 
26 {
28  read = 0x1,
29 
31  write = 0x2,
32 };
33 
35 struct process_event_type;
36 
37 class process;
38 
53 
60 class FZ_PUBLIC_SYMBOL process final
61 {
62 public:
64  process();
65 
70  process(thread_pool & pool, event_handler & handler);
71 
73  ~process();
74  process(process const&) = delete;
75  process& operator=(process const&) = delete;
76 
78  enum class io_redirection {
79  redirect,
80  none,
81  closeall
82  };
83 
97  bool spawn(native_string const& cmd, std::vector<native_string> const& args = std::vector<native_string>(), io_redirection redirect_mode = io_redirection::redirect);
98 
99  bool spawn(std::vector<native_string> const& command_with_args, io_redirection redirect_mode = io_redirection::redirect);
100 
101 #if FZ_WINDOWS || FZ_UNIX
102  bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, io_redirection redirect_mode = io_redirection::redirect);
104 #endif
105 
106 #ifndef FZ_WINDOWS
107 
113  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);
114 
115  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);
116 #endif
117 
123  void kill();
124 
137  bool stop(duration const& timeout = {});
138 
147  rwresult read(void* buffer, size_t len);
148 
156  rwresult write(void const* buffer, size_t len);
157 
158  inline rwresult write(std::string_view const& s) {
159  return write(s.data(), s.size());
160  }
161 
162 #if FZ_WINDOWS
163 
166  void* handle() const;
167 #endif
168 
169 private:
170  class impl;
171  impl* impl_;
172 };
173 
174 
183 bool FZ_PUBLIC_SYMBOL spawn_detached_process(std::vector<native_string> const& cmd_with_args);
184 
185 #if !FZ_WINDOWS
186 
195 class FZ_PUBLIC_SYMBOL forkblock final
196 {
197 public:
198  forkblock();
199  ~forkblock();
200 
201  forkblock(forkblock const&) = delete;
202  forkblock& operator=(forkblock const&) = delete;
203 };
204 #endif
205 
206 }
207 
208 #endif
Data has become available.
process_event_flag
The type of a process event.
Definition: process.hpp:25
bool spawn_detached_process(std::vector< native_string > const &cmd_with_args)
Starts a detached process.
simple_event< process_event_type, process *, process_event_flag > process_event
Definition: process.hpp:37
io_redirection
IO redirection modes.
Definition: process.hpp:78
Simple handler for asynchronous event processing.
Definition: event_handler.hpp:54
This is the recommended event class.
Definition: event.hpp:67
Impersonation tokens for a given user can be used to spawn processes running as that user...
Definition: impersonation.hpp:32
Assorted classes dealing with time.
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:33
The namespace used by libfilezilla.
Definition: apply.hpp:17
The duration class represents a time interval in milliseconds.
Definition: time.hpp:290
Declares event_base and simple_event<>
Sets some global macros and further includes string.hpp.
data can be written.
The process class manages an asynchronous process with redirected IO.
Definition: process.hpp:60
A dumb thread-pool for asynchronous tasks.
Definition: thread_pool.hpp:63