jaulib v1.3.8
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
io_util.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021-2023 Gothel Software e.K.
4 * Copyright (c) 2021 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#ifndef JAU_IO_UTIL_HPP_
27#define JAU_IO_UTIL_HPP_
28
29#include <string>
30#include <cstdint>
31#include <thread>
32#include <vector>
33
34#include <jau/basic_types.hpp>
36#include <jau/ringbuffer.hpp>
37#include <jau/functional.hpp>
38
39namespace jau::io {
40 /** @defgroup IOUtils IO Utilities
41 * Input and Output (IO) types and functionality.
42 *
43 * @{
44 */
45
46 template<typename T> using secure_vector = std::vector<T, jau::callocator_sec<T>>;
47
48 typedef std::basic_string<char, std::char_traits<char>, jau::callocator_sec<char>> secure_string;
49
51
52 extern const size_t BEST_URLSTREAM_RINGBUFFER_SIZE;
53
54 /**
55 * I/O direction, read or write
56 */
57 enum class io_dir_t : int8_t {
58 /** Read Operation */
59 READ = 0,
60
61 /** Write Operation */
63 };
64
65 /**
66 * I/O operation result value
67 */
68 enum class io_result_t : int8_t {
69 /** Operation failed. */
70 FAILED = -1,
71
72 /** Operation still in progress. */
73 NONE = 0,
74
75 /** Operation succeeded. */
77 };
79
80 inline std::string toString(io_result_t v) noexcept {
81 switch(v) {
82 case io_result_t::SUCCESS: return "SUCCESS";
83 case io_result_t::NONE: return "NONE";
84 default: return "FAILED";
85 }
86 }
87 inline std::ostream& operator<<(std::ostream& os, io_result_t v) {
88 os << toString(v);
89 return os;
90 }
91
92 /**
93 * Stream consumer function
94 * - `bool consumer(secure_vector<uint8_t>& data, bool is_final)`
95 *
96 * Returns true to signal continuation, false to end streaming.
97 */
98 typedef jau::function<bool(secure_vector<uint8_t>& /* data */, bool /* is_final */)> StreamConsumerFunc;
99
100 /**
101 * Synchronous byte input stream reader from given file path using the given StreamConsumerFunc consumer_fn.
102 *
103 * To abort streaming, user may return `false` from the given `consumer_func`.
104 *
105 * It is guaranteed that consumer_fn() is called with `is_final=true` once at the end,
106 * even if `input_file` stream has zero size.
107 *
108 * @param input_file input file name path, `-` denotes std::stdin.
109 * @param buffer secure std::vector buffer, passed down to consumer_fn
110 * @param consumer_fn StreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
111 * @return total bytes read or 0 if error
112 */
113 uint64_t read_file(const std::string& input_file,
115 const StreamConsumerFunc& consumer_fn) noexcept;
116
117 class ByteInStream; // fwd
118
119 /**
120 * Synchronous byte input stream reader using the given StreamConsumerFunc consumer_fn.
121 *
122 * To abort streaming, user may return `false` from the given `consumer_func`.
123 *
124 * It is guaranteed that consumer_fn() is called with `is_final=true` once at the end,
125 * even input stream has zero size.
126 *
127 * @param in the input byte stream to read from
128 * @param buffer secure std::vector buffer, passed down to consumer_fn
129 * @param consumer_fn StreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
130 * @return total bytes read or 0 if error
131 */
132 uint64_t read_stream(ByteInStream& in,
134 const StreamConsumerFunc& consumer_fn) noexcept;
135
136 /**
137 * Synchronous double-buffered byte input stream reader using the given StreamConsumerFunc consumer_fn.
138 *
139 * To abort streaming, user may return `false` from the given `consumer_func`.
140 *
141 * It is guaranteed that consumer_fn() is called with `is_final=true` once at the end,
142 * even if input stream has zero size.
143 *
144 * Implementation reads one buffer ahead in respect to consumer_fn(). <br/>
145 * If reading zero bytes on the next buffer,
146 * it propagates the end-of-file (EOF) to the previous buffer which will be send via consumer_fn() next.<br/>
147 *
148 * This way, the consumer_fn() will always receive its `is_final` flag on the last sent bytes (size > 0)
149 * even if the content-size is unknown (pipe). <br/>
150 * Hence it allows e.g. decryption to work where the final data chunck must be processed as such.
151 *
152 * @param in the input byte stream to read from
153 * @param buffer1 secure std::vector buffer, passed down to consumer_fn
154 * @param buffer2 secure std::vector buffer, passed down to consumer_fn
155 * @param consumer_fn StreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
156 * @return total bytes read or 0 if error
157 */
158 uint64_t read_stream(ByteInStream& in,
160 const StreamConsumerFunc& consumer_fn) noexcept;
161
162 /**
163 * Synchronous URL stream reader using the given StreamConsumerFunc consumer_fn.
164 *
165 * To abort streaming, user may return `false` from the given `consumer_func`.
166 *
167 * Standard implementation uses [curl](https://curl.se/),
168 * hence all [*libcurl* network protocols](https://curl.se/docs/url-syntax.html) are supported,
169 * see jau::io::uri::supported_protocols().
170 *
171 * If the uri-sheme doesn't match a supported protocol, see jau::io::uri::protocol_supported(),
172 * function returns immediately with zero bytes.
173 *
174 * Environment variables:
175 * - `jau_io_net_ssl_verifypeer=[true|false]` to enable or disable SSL peer verification. Defaults to `true`.
176 * - `jau_io_net_verbose=[true|false]` to enable or disable verbose on stderr stream communication. Defaults to `false`.
177 *
178 * @param url the URL to open a connection to and stream bytes from
179 * @param buffer secure std::vector buffer, passed down to consumer_fn
180 * @param consumer_fn StreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
181 * @return total bytes read or 0 if transmission error or protocol of given url is not supported
182 */
183 uint64_t read_url_stream(const std::string& url,
185 const StreamConsumerFunc& consumer_fn) noexcept;
186
187 /**
188 * Synchronized URL header response completion
189 * as used by asynchronous read_url_stream().
190 *
191 * @see url_header_sync::completed()
192 */
194 private:
195 std::mutex m_sync;
196 std::condition_variable m_cv;
197 jau::relaxed_atomic_bool m_completed;
198 jau::relaxed_atomic_int32 m_response_code;
199
200 public:
202 : m_completed(false)
203 { }
204
205 /**
206 * Returns whether URL header is completed.
207 *
208 * Completion is reached in any of the following cases
209 * - Final (http) CRLF message received
210 * - Any http header error response received
211 * - First data package received
212 * - End of operation
213 */
214 bool completed() const noexcept { return m_completed; }
215
216 int32_t response_code() const noexcept { return m_response_code; }
217
218 /**
219 * Notify completion, see completed()
220 */
221 void notify_complete(const int32_t response_code=200) noexcept;
222
223 /**
224 * Wait until completed() has been reached.
225 * @param timeout maximum duration in fractions of seconds to wait, where fractions_i64::zero waits infinitely
226 * @return true if completed within timeout, otherwise false
227 */
228 bool wait_until_completion(const jau::fraction_i64& timeout) noexcept;
229 };
230
231 namespace http {
232 struct PostRequest {
233 std::unordered_map<std::string, std::string> header;
234 std::string body;
235 };
236 using PostRequestPtr = std::unique_ptr<PostRequest>;
237 }
238
239 using net_tk_handle = void*;
240
241 /// creates a reusable handle, free with free_net_tk_handle() after use.
243 /// frees a handle after use created by create_net_tk_handle()
244 void free_net_tk_handle(net_tk_handle handle) noexcept;
245
246 /** Synchronous stream response */
255
258
259 /** Stream failed and is aborted, i.e. io_result_t::FAILED == result */
260 constexpr_atomic bool failed() const noexcept { return io_result_t::FAILED == result; }
261 /** Stream processing in progress, i.e. io_result_t::NONE == result */
262 constexpr_atomic bool processing() const noexcept { return io_result_t::NONE == result; }
263 /** Stream completed successfully, i.e. io_result_t::SUCCESS == result */
264 constexpr_atomic bool success() const noexcept { return io_result_t::SUCCESS == result; }
265
266 /// used network tookit handle, if owned by caller
268 /// synchronized URL header response completion
270 /// indicating whether content_length is known from server
272 /// content_length tracking the content_length
274 /// tracking the total_read
275 uint64_t total_read;
276 /// tracking io_result_t. If set to other than io_result_t::NONE while streaming, streaming is aborted. See failed(), processing() and success()
278 /// piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
279 std::vector<uint8_t> result_data;
280 /// piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
281 std::string result_text;
282 };
283 using SyncStreamResponseRef = std::shared_ptr<SyncStreamResponse>;
284
285 /**
286 * Synchronous stream consumer function
287 * - `bool consumer(AsyncStreamResponse& resp, const uint8_t* data , size_t len, bool is_final)`
288 *
289 * Returns true to signal continuation, false to end streaming.
290 */
291 typedef jau::function<bool(SyncStreamResponse& /* resp */, const uint8_t* /* data */, size_t /* len */, bool /* is_final */)> SyncStreamConsumerFunc;
292
293 /**
294 * Synchronous URL stream reader using the given SyncStreamConsumerFunc consumer_fn.
295 *
296 * Function returns after completion.
297 *
298 * To abort streaming, (1) user may return `false` from the given `consumer_func`.
299 * Asynchronous URL read content using the given byte jau::ringbuffer, allowing parallel reading.
300 *
301 * To abort streaming, (2) user may set given reference `results` to a value other than async_io_result_t::NONE.
302 *
303 * Standard implementation uses [curl](https://curl.se/),
304 * hence all [*libcurl* network protocols](https://curl.se/docs/url-syntax.html) are supported,
305 * see jau::io::uri::supported_protocols().
306 *
307 * If the uri-sheme doesn't match a supported protocol, see jau::io::uri::protocol_supported(),
308 * SyncStreamResponse::failed() returns true.
309 *
310 * Environment variables:
311 * - `jau_io_net_ssl_verifypeer=[true|false]` to enable or disable SSL peer verification. Defaults to `true`.
312 * - `jau_io_net_verbose=[true|false]` to enable or disable verbose on stderr stream communication. Defaults to `false`.
313 *
314 * @param handle optional reused user-pooled net toolkit handle, see create_net_tk_handle(). Pass nullptr to use an own local handle.
315 * @param url the URL to open a connection to and stream bytes from
316 * @param httpPostReq optional HTTP POST request data, maybe nullptr
317 * @param buffer optional jau::ringbuffer<uint8_t>, if not nullptr will be synchronously filled with received data
318 * @param consumer_fn SyncStreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
319 * @return new SyncStreamResponse reference. If protocol of given url is not supported, SyncStreamResponse::failed() returns true.
320 */
321 SyncStreamResponseRef read_url_stream_sync(net_tk_handle handle, const std::string& url,
322 http::PostRequestPtr httpPostReq, ByteRingbuffer *buffer,
323 const SyncStreamConsumerFunc& consumer_fn) noexcept;
324
325 /** Asynchronous stream response */
334
337
338 /** Stream failed and is aborted, i.e. io_result_t::FAILED == result */
339 constexpr_atomic bool failed() const noexcept { return io_result_t::FAILED == result; }
340 /** Stream processing in progress, i.e. io_result_t::NONE == result */
341 constexpr_atomic bool processing() const noexcept { return io_result_t::NONE == result; }
342 /** Stream completed successfully, i.e. io_result_t::SUCCESS == result */
343 constexpr_atomic bool success() const noexcept { return io_result_t::SUCCESS == result; }
344
345 /// used network tookit handle, if owned by caller
347 /// background reading thread unique-pointer
348 std::thread thread;
349 /// synchronized URL header response completion
351 /// indicating whether content_length is known from server
353 /// content_length tracking the content_length
355 /// tracking the total_read
357 /// tracking io_result_t. If set to other than io_result_t::NONE while streaming, streaming is aborted. See failed(), processing() and success()
359 /// piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
360 std::vector<uint8_t> result_data;
361 /// piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
362 std::string result_text;
363 };
364 using AsyncStreamResponseRef = std::shared_ptr<AsyncStreamResponse>;
365
366 /**
367 * Asynchronous stream consumer function
368 * - `bool consumer(AsyncStreamResponse& resp, const uint8_t* data , size_t len, bool is_final)`
369 *
370 * Returns true to signal continuation, false to end streaming.
371 */
372 typedef jau::function<bool(AsyncStreamResponse& /* resp */, const uint8_t* /* data */, size_t /* len */, bool /* is_final */)> AsyncStreamConsumerFunc;
373
374 /**
375 * Asynchronous URL stream reader using the given AsyncStreamConsumerFunc consumer_fn.
376 *
377 * Function returns immediately.
378 *
379 * To abort streaming, (1) user may return `false` from the given `consumer_func`.
380 * Asynchronous URL read content using the given byte jau::ringbuffer, allowing parallel reading.
381 *
382 * To abort streaming, (2) user may set given reference `results` to a value other than async_io_result_t::NONE.
383 *
384 * Standard implementation uses [curl](https://curl.se/),
385 * hence all [*libcurl* network protocols](https://curl.se/docs/url-syntax.html) are supported,
386 * see jau::io::uri::supported_protocols().
387 *
388 * If the uri-sheme doesn't match a supported protocol, see jau::io::uri::protocol_supported(),
389 * AsyncStreamResponse::failed() returns true.
390 *
391 * Environment variables:
392 * - `jau_io_net_ssl_verifypeer=[true|false]` to enable or disable SSL peer verification. Defaults to `true`.
393 * - `jau_io_net_verbose=[true|false]` to enable or disable verbose on stderr stream communication. Defaults to `false`.
394 *
395 * @param handle optional reused user-pooled net toolkit handle, see create_net_tk_handle(). Pass nullptr to use an own local handle.
396 * @param url the URL to open a connection to and stream bytes from
397 * @param httpPostReq optional HTTP POST request data, maybe nullptr
398 * @param buffer optional jau::ringbuffer<uint8_t>, if not nullptr will be asynchronously filled with received data
399 * @param consumer_fn AsyncStreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
400 * @return new AsyncStreamResponse reference. If protocol of given url is not supported, AsyncStreamResponse::failed() returns true.
401 */
402 AsyncStreamResponseRef read_url_stream_async(net_tk_handle handle, const std::string& url,
403 http::PostRequestPtr httpPostReq, ByteRingbuffer *buffer,
404 const AsyncStreamConsumerFunc& consumer_fn) noexcept;
405
406 void print_stats(const std::string& prefix, const uint64_t& out_bytes_total, const jau::fraction_i64& td) noexcept;
407
408 /**@}*/
409
410 /**
411 * Limited URI toolkit to query handled protocols by the IO implementation.
412 *
413 * The URI scheme functionality exposed here is limited and only provided to decide whether the used implementation
414 * is able to handle the protocol. This is not a replacement for a proper URI class.
415 */
416 namespace uri_tk {
417 /** \addtogroup IOUtils
418 *
419 * @{
420 */
421
422 /**
423 * Returns a list of supported protocol supported by [*libcurl* network protocols](https://curl.se/docs/url-syntax.html),
424 * queried at runtime.
425 * @see protocol_supported()
426 */
427 std::vector<std::string_view> supported_protocols() noexcept;
428
429 /**
430 * Returns the valid uri-scheme from given uri,
431 * which is empty if no valid scheme is included.
432 *
433 * The given uri must include at least a colon after the uri-scheme part.
434 *
435 * @param uri an uri
436 * @return valid uri-scheme, empty if non found
437 */
438 std::string_view get_scheme(const std::string_view& uri) noexcept;
439
440 /**
441 * Returns true if the uri-scheme of given uri matches a supported by [*libcurl* network protocols](https://curl.se/docs/url-syntax.html) otherwise false.
442 *
443 * The uri-scheme is retrieved via get_scheme() passing given uri, hence must include at least a colon after the uri-scheme part.
444 *
445 * The *libcurl* supported protocols is queried at runtime, see supported_protocols().
446 *
447 * @param uri an uri to test
448 * @return true if the uri-scheme of given uri is supported, otherwise false.
449 * @see supported_protocols()
450 * @see get_scheme()
451 */
452 bool protocol_supported(const std::string_view& uri) noexcept;
453
454 /**
455 * Returns true if the uri-scheme of given uri matches the local `file` protocol, i.e. starts with `file://`.
456 * @param uri an uri to test
457 */
458 bool is_local_file_protocol(const std::string_view& uri) noexcept;
459
460 /**
461 * Returns true if the uri-scheme of given uri matches the `http` or `https` protocol, i.e. starts with `http:` or `https:`.
462 * @param uri an uri to test
463 */
464 bool is_httpx_protocol(const std::string_view& uri) noexcept;
465
466 /**@}*/
467 }
468
469} // namespace elevator::io
470
471#endif /* JAU_IO_UTIL_HPP_ */
Class template jau::function is a general-purpose static-polymorphic function wrapper.
Abstract byte input stream object.
Synchronized URL header response completion as used by asynchronous read_url_stream().
Definition io_util.hpp:193
bool wait_until_completion(const jau::fraction_i64 &timeout) noexcept
Wait until completed() has been reached.
Definition io_util.cpp:460
void notify_complete(const int32_t response_code=200) noexcept
Notify completion, see completed()
Definition io_util.cpp:451
bool completed() const noexcept
Returns whether URL header is completed.
Definition io_util.hpp:214
int32_t response_code() const noexcept
Definition io_util.hpp:216
Ring buffer implementation, a.k.a circular buffer, exposing lock-free get*(..) and put*(....
ordered_atomic< int32_t, std::memory_order_relaxed > relaxed_atomic_int32
Relaxed non-SC atomic integral scalar int32_t.
ordered_atomic< bool, std::memory_order_relaxed > relaxed_atomic_bool
Relaxed non-SC atomic integral scalar boolean.
ordered_atomic< uint64_t, std::memory_order_relaxed > relaxed_atomic_uint64
Relaxed non-SC atomic integral scalar uint64_t.
#define constexpr_atomic
Used when designed to declare a function constexpr, but prohibited by its specific implementation.
std::ostream & operator<<(std::ostream &os, const T v)
fraction< int64_t > fraction_i64
fraction using int64_t as integral type
AsyncStreamResponseRef read_url_stream_async(net_tk_handle handle, const std::string &url, http::PostRequestPtr httpPostReq, ByteRingbuffer *buffer, const AsyncStreamConsumerFunc &consumer_fn) noexcept
Asynchronous URL stream reader using the given AsyncStreamConsumerFunc consumer_fn.
Definition io_util.cpp:1119
jau::ordered_atomic< io_result_t, std::memory_order_relaxed > relaxed_atomic_io_result_t
Definition io_util.hpp:78
SyncStreamResponseRef read_url_stream_sync(net_tk_handle handle, const std::string &url, http::PostRequestPtr httpPostReq, ByteRingbuffer *buffer, const SyncStreamConsumerFunc &consumer_fn) noexcept
Synchronous URL stream reader using the given SyncStreamConsumerFunc consumer_fn.
Definition io_util.cpp:1093
bool is_local_file_protocol(const std::string_view &uri) noexcept
Returns true if the uri-scheme of given uri matches the local file protocol, i.e.
Definition io_util.cpp:206
io_dir_t
I/O direction, read or write.
Definition io_util.hpp:57
net_tk_handle create_net_tk_handle() noexcept
creates a reusable handle, free with free_net_tk_handle() after use.
Definition io_util.cpp:1072
uint64_t read_stream(ByteInStream &in, secure_vector< uint8_t > &buffer, const StreamConsumerFunc &consumer_fn) noexcept
Synchronous byte input stream reader using the given StreamConsumerFunc consumer_fn.
Definition io_util.cpp:61
uint64_t read_url_stream(const std::string &url, secure_vector< uint8_t > &buffer, const StreamConsumerFunc &consumer_fn) noexcept
Synchronous URL stream reader using the given StreamConsumerFunc consumer_fn.
Definition io_util.cpp:313
void * net_tk_handle
Definition io_util.hpp:239
jau::function< bool(secure_vector< uint8_t > &, bool)> StreamConsumerFunc
Stream consumer function.
Definition io_util.hpp:98
bool is_httpx_protocol(const std::string_view &uri) noexcept
Returns true if the uri-scheme of given uri matches the http or https protocol, i....
Definition io_util.cpp:210
std::string_view get_scheme(const std::string_view &uri) noexcept
Returns the valid uri-scheme from given uri, which is empty if no valid scheme is included.
Definition io_util.cpp:184
io_result_t
I/O operation result value.
Definition io_util.hpp:68
std::vector< std::string_view > supported_protocols() noexcept
Returns a list of supported protocol supported by libcurl network protocols, queried at runtime.
Definition io_util.cpp:161
jau::function< bool(AsyncStreamResponse &, const uint8_t *, size_t, bool)> AsyncStreamConsumerFunc
Asynchronous stream consumer function.
Definition io_util.hpp:372
std::string toString(io_result_t v) noexcept
Definition io_util.hpp:80
std::basic_string< char, std::char_traits< char >, jau::callocator_sec< char > > secure_string
Definition io_util.hpp:48
std::shared_ptr< SyncStreamResponse > SyncStreamResponseRef
Definition io_util.hpp:283
std::shared_ptr< AsyncStreamResponse > AsyncStreamResponseRef
Definition io_util.hpp:364
jau::function< bool(SyncStreamResponse &, const uint8_t *, size_t, bool)> SyncStreamConsumerFunc
Synchronous stream consumer function.
Definition io_util.hpp:291
jau::ringbuffer< uint8_t, size_t > ByteRingbuffer
Definition io_util.hpp:50
void free_net_tk_handle(net_tk_handle handle) noexcept
frees a handle after use created by create_net_tk_handle()
Definition io_util.cpp:1081
const size_t BEST_URLSTREAM_RINGBUFFER_SIZE
std::vector< T, jau::callocator_sec< T > > secure_vector
Definition io_util.hpp:46
void print_stats(const std::string &prefix, const uint64_t &out_bytes_total, const jau::fraction_i64 &td) noexcept
Definition io_util.cpp:1149
uint64_t read_file(const std::string &input_file, secure_vector< uint8_t > &buffer, const StreamConsumerFunc &consumer_fn) noexcept
Synchronous byte input stream reader from given file path using the given StreamConsumerFunc consumer...
Definition io_util.cpp:48
bool protocol_supported(const std::string_view &uri) noexcept
Returns true if the uri-scheme of given uri matches a supported by libcurl network protocols otherwis...
Definition io_util.cpp:196
@ timeout
Input or output operation failed due to timeout.
@ READ
Read Operation.
Definition io_util.hpp:59
@ WRITE
Write Operation.
Definition io_util.hpp:62
@ NONE
Operation still in progress.
Definition io_util.hpp:73
@ FAILED
Operation failed.
Definition io_util.hpp:70
@ SUCCESS
Operation succeeded.
Definition io_util.hpp:76
std::unique_ptr< PostRequest > PostRequestPtr
Definition io_util.hpp:236
Limited URI toolkit to query handled protocols by the IO implementation.
Definition io_util.hpp:416
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2024 Gothel Software e.K.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition backtrace.hpp:32
A simple secure allocator for integral types using POSIX C functions: ::malloc() and ::free().
Asynchronous stream response.
Definition io_util.hpp:326
constexpr_atomic bool failed() const noexcept
Stream failed and is aborted, i.e.
Definition io_util.hpp:339
constexpr_atomic bool processing() const noexcept
Stream processing in progress, i.e.
Definition io_util.hpp:341
std::string result_text
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
Definition io_util.hpp:362
relaxed_atomic_io_result_t result
tracking io_result_t. If set to other than io_result_t::NONE while streaming, streaming is aborted....
Definition io_util.hpp:358
std::thread thread
background reading thread unique-pointer
Definition io_util.hpp:348
relaxed_atomic_bool has_content_length
indicating whether content_length is known from server
Definition io_util.hpp:352
relaxed_atomic_uint64 total_read
tracking the total_read
Definition io_util.hpp:356
AsyncStreamResponse(net_tk_handle handle_)
Definition io_util.hpp:327
net_tk_handle handle
used network tookit handle, if owned by caller
Definition io_util.hpp:346
std::vector< uint8_t > result_data
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
Definition io_util.hpp:360
relaxed_atomic_uint64 content_length
content_length tracking the content_length
Definition io_util.hpp:354
url_header_resp header_resp
synchronized URL header response completion
Definition io_util.hpp:350
constexpr_atomic bool success() const noexcept
Stream completed successfully, i.e.
Definition io_util.hpp:343
Synchronous stream response.
Definition io_util.hpp:247
constexpr_atomic bool processing() const noexcept
Stream processing in progress, i.e.
Definition io_util.hpp:262
uint64_t total_read
tracking the total_read
Definition io_util.hpp:275
uint64_t content_length
content_length tracking the content_length
Definition io_util.hpp:273
url_header_resp header_resp
synchronized URL header response completion
Definition io_util.hpp:269
relaxed_atomic_io_result_t result
tracking io_result_t. If set to other than io_result_t::NONE while streaming, streaming is aborted....
Definition io_util.hpp:277
constexpr_atomic bool failed() const noexcept
Stream failed and is aborted, i.e.
Definition io_util.hpp:260
bool has_content_length
indicating whether content_length is known from server
Definition io_util.hpp:271
constexpr_atomic bool success() const noexcept
Stream completed successfully, i.e.
Definition io_util.hpp:264
std::string result_text
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
Definition io_util.hpp:281
std::vector< uint8_t > result_data
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
Definition io_util.hpp:279
SyncStreamResponse(net_tk_handle handle_)
Definition io_util.hpp:248
net_tk_handle handle
used network tookit handle, if owned by caller
Definition io_util.hpp:267
std::unordered_map< std::string, std::string > header
Definition io_util.hpp:233
std::atomic<T> type with predefined fixed std::memory_order, not allowing changing the memory model o...