jaulib v1.4.0-2-g788cf73
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-2025 Gothel Software e.K.
4 * Copyright (c) 2021 ZAFENA AB
5 *
6 * SPDX-License-Identifier: MIT
7 *
8 * This Source Code Form is subject to the terms of the MIT License
9 * If a copy of the MIT was not distributed with this file,
10 * you can obtain one at https://opensource.org/license/mit/.
11 */
12
13#ifndef JAU_IO_IO_UTIL_HPP_
14#define JAU_IO_IO_UTIL_HPP_
15
16#include <string>
17#include <cstdint>
18#include <thread>
19#include <vector>
20
21#include <jau/basic_types.hpp>
23#include <jau/ringbuffer.hpp>
24#include <jau/functional.hpp>
25
26namespace jau::io {
27 /** @defgroup IOUtils IO Utilities
28 * Input and Output (IO) types and functionality.
29 *
30 * @{
31 */
32
33 template<typename T> using secure_vector = std::vector<T, jau::callocator_sec<T>>;
34
35 typedef std::basic_string<char, std::char_traits<char>, jau::callocator_sec<char>> secure_string;
36
38
39 extern const size_t BEST_URLSTREAM_RINGBUFFER_SIZE;
40
41 /**
42 * I/O direction, read or write
43 */
44 enum class io_dir_t : int8_t {
45 /** Read Operation */
46 READ = 0,
47
48 /** Write Operation */
50 };
51
52 /**
53 * I/O operation result value
54 */
55 enum class io_result_t : int8_t {
56 /** Operation failed. */
57 FAILED = -1,
58
59 /** Operation still in progress. */
60 NONE = 0,
61
62 /** Operation succeeded. */
64 };
66
67 inline std::string toString(io_result_t v) noexcept {
68 switch(v) {
69 case io_result_t::SUCCESS: return "SUCCESS";
70 case io_result_t::NONE: return "NONE";
71 default: return "FAILED";
72 }
73 }
74 inline std::ostream& operator<<(std::ostream& os, io_result_t v) { return os << toString(v); }
75
76 /**
77 * Stream consumer function
78 * - `bool consumer(secure_vector<uint8_t>& data, bool is_final)`
79 *
80 * Returns true to signal continuation, false to end streaming.
81 */
82 typedef jau::function<bool(secure_vector<uint8_t>& /* data */, bool /* is_final */)> StreamConsumerFunc;
83
84 /**
85 * Synchronous byte input stream reader from given file path using the given StreamConsumerFunc consumer_fn.
86 *
87 * To abort streaming, user may return `false` from the given `consumer_func`.
88 *
89 * It is guaranteed that consumer_fn() is called with `is_final=true` once at the end,
90 * even if `input_file` stream has zero size.
91 *
92 * @param input_file input file name path, `-` denotes std::stdin.
93 * @param buffer secure std::vector buffer, passed down to consumer_fn
94 * @param consumer_fn StreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
95 * @return total bytes read or 0 if error
96 */
97 uint64_t read_file(const std::string& input_file,
99 const StreamConsumerFunc& consumer_fn) noexcept;
100
101 class ByteStream; // fwd
102
103 /**
104 * Synchronous byte input stream reader using the given StreamConsumerFunc consumer_fn.
105 *
106 * To abort streaming, user may return `false` from the given `consumer_func`.
107 *
108 * It is guaranteed that consumer_fn() is called with `is_final=true` once at the end,
109 * even input stream has zero size.
110 *
111 * @param in the input byte stream to read from
112 * @param buffer secure std::vector buffer, passed down to consumer_fn
113 * @param consumer_fn StreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
114 * @return total bytes read or 0 if error
115 */
116 uint64_t read_stream(ByteStream& in,
118 const StreamConsumerFunc& consumer_fn) noexcept;
119
120 /**
121 * Synchronous double-buffered byte input stream reader using the given StreamConsumerFunc consumer_fn.
122 *
123 * To abort streaming, user may return `false` from the given `consumer_func`.
124 *
125 * It is guaranteed that consumer_fn() is called with `is_final=true` once at the end,
126 * even if input stream has zero size.
127 *
128 * Implementation reads one buffer ahead in respect to consumer_fn(). <br/>
129 * If reading zero bytes on the next buffer,
130 * it propagates the end-of-file (EOF) to the previous buffer which will be send via consumer_fn() next.<br/>
131 *
132 * This way, the consumer_fn() will always receive its `is_final` flag on the last sent bytes (size > 0)
133 * even if the content-size is unknown (pipe). <br/>
134 * Hence it allows e.g. decryption to work where the final data chunck must be processed as such.
135 *
136 * @param in the input byte stream to read from
137 * @param buffer1 secure std::vector buffer, passed down to consumer_fn
138 * @param buffer2 secure std::vector buffer, passed down to consumer_fn
139 * @param consumer_fn StreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
140 * @return total bytes read or 0 if error
141 */
142 uint64_t read_stream(ByteStream& in,
144 const StreamConsumerFunc& consumer_fn) noexcept;
145
146 /**
147 * Synchronous URL stream reader using the given StreamConsumerFunc consumer_fn.
148 *
149 * To abort streaming, user may return `false` from the given `consumer_func`.
150 *
151 * Standard implementation uses [curl](https://curl.se/),
152 * hence all [*libcurl* network protocols](https://curl.se/docs/url-syntax.html) are supported,
153 * see jau::io::uri::supported_protocols().
154 *
155 * If the uri-sheme doesn't match a supported protocol, see jau::io::uri::protocol_supported(),
156 * function returns immediately with zero bytes.
157 *
158 * Environment variables:
159 * - `jau_io_net_ssl_verifypeer=[true|false]` to enable or disable SSL peer verification. Defaults to `true`.
160 * - `jau_io_net_verbose=[true|false]` to enable or disable verbose on stderr stream communication. Defaults to `false`.
161 *
162 * @param url the URL to open a connection to and stream bytes from
163 * @param buffer secure std::vector buffer, passed down to consumer_fn
164 * @param consumer_fn StreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
165 * @return total bytes read or 0 if transmission error or protocol of given url is not supported
166 */
167 uint64_t read_url_stream(const std::string& url,
169 const StreamConsumerFunc& consumer_fn) noexcept;
170
171 /**
172 * Synchronized URL header response completion
173 * as used by asynchronous read_url_stream().
174 *
175 * @see url_header_sync::completed()
176 */
178 private:
179 std::mutex m_sync;
180 std::condition_variable m_cv;
181 jau::relaxed_atomic_bool m_completed;
182 jau::relaxed_atomic_int32 m_response_code;
183
184 public:
185 url_header_resp() noexcept // NOLINT(modernize-use-equals-default)
186 : m_completed(false)
187 { }
188
189 /**
190 * Returns whether URL header is completed.
191 *
192 * Completion is reached in any of the following cases
193 * - Final (http) CRLF message received
194 * - Any http header error response received
195 * - First data package received
196 * - End of operation
197 */
198 bool completed() const noexcept { return m_completed; }
199
200 int32_t response_code() const noexcept { return m_response_code; }
201
202 /**
203 * Notify completion, see completed()
204 */
205 void notify_complete(const int32_t response_code=200) noexcept;
206
207 /**
208 * Wait until completed() has been reached.
209 * @param timeout maximum duration in fractions of seconds to wait, where fractions_i64::zero waits infinitely
210 * @return true if completed within timeout, otherwise false
211 */
212 bool wait_until_completion(const jau::fraction_i64& timeout) noexcept;
213 };
214
215 namespace http {
216 struct PostRequest {
217 std::unordered_map<std::string, std::string> header;
218 std::string body;
219 };
220 using PostRequestPtr = std::unique_ptr<PostRequest>;
221 }
222
223 using net_tk_handle = void*;
224
225 /// creates a reusable handle, free with free_net_tk_handle() after use.
227 /// frees a handle after use created by create_net_tk_handle()
228 void free_net_tk_handle(net_tk_handle handle) noexcept;
229
230 /** Synchronous stream response */
239
242
243 /** Stream failed and is aborted, i.e. io_result_t::FAILED == result */
244 constexpr_atomic bool failed() const noexcept { return io_result_t::FAILED == result; }
245 /** Stream processing in progress, i.e. io_result_t::NONE == result */
246 constexpr_atomic bool processing() const noexcept { return io_result_t::NONE == result; }
247 /** Stream completed successfully, i.e. io_result_t::SUCCESS == result */
248 constexpr_atomic bool success() const noexcept { return io_result_t::SUCCESS == result; }
249
250 /// used network tookit handle, if owned by caller
252 /// synchronized URL header response completion
254 /// indicating whether content_length is known from server
256 /// content_length tracking the content_length
258 /// tracking the total_read
259 uint64_t total_read;
260 /// tracking io_result_t. If set to other than io_result_t::NONE while streaming, streaming is aborted. See failed(), processing() and success()
262 /// piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
263 std::vector<uint8_t> result_data;
264 /// piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
265 std::string result_text;
266 };
267 using SyncStreamResponseRef = std::shared_ptr<SyncStreamResponse>;
268
269 /**
270 * Synchronous stream consumer function
271 * - `bool consumer(AsyncStreamResponse& resp, const uint8_t* data , size_t len, bool is_final)`
272 *
273 * Returns true to signal continuation, false to end streaming.
274 */
275 typedef jau::function<bool(SyncStreamResponse& /* resp */, const uint8_t* /* data */, size_t /* len */, bool /* is_final */)> SyncStreamConsumerFunc;
276
277 /**
278 * Synchronous URL stream reader using the given SyncStreamConsumerFunc consumer_fn.
279 *
280 * Function returns after completion.
281 *
282 * To abort streaming, (1) user may return `false` from the given `consumer_func`.
283 * Asynchronous URL read content using the given byte jau::ringbuffer, allowing parallel reading.
284 *
285 * To abort streaming, (2) user may set given reference `results` to a value other than async_io_result_t::NONE.
286 *
287 * Standard implementation uses [curl](https://curl.se/),
288 * hence all [*libcurl* network protocols](https://curl.se/docs/url-syntax.html) are supported,
289 * see jau::io::uri::supported_protocols().
290 *
291 * If the uri-sheme doesn't match a supported protocol, see jau::io::uri::protocol_supported(),
292 * SyncStreamResponse::failed() returns true.
293 *
294 * Environment variables:
295 * - `jau_io_net_ssl_verifypeer=[true|false]` to enable or disable SSL peer verification. Defaults to `true`.
296 * - `jau_io_net_verbose=[true|false]` to enable or disable verbose on stderr stream communication. Defaults to `false`.
297 *
298 * @param handle optional reused user-pooled net toolkit handle, see create_net_tk_handle(). Pass nullptr to use an own local handle.
299 * @param url the URL to open a connection to and stream bytes from
300 * @param httpPostReq optional HTTP POST request data, maybe nullptr
301 * @param buffer optional jau::ringbuffer<uint8_t>, if not nullptr will be synchronously filled with received data
302 * @param consumer_fn SyncStreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
303 * @return new SyncStreamResponse reference. If protocol of given url is not supported, SyncStreamResponse::failed() returns true.
304 */
305 SyncStreamResponseRef read_url_stream_sync(net_tk_handle handle, const std::string& url,
306 http::PostRequestPtr httpPostReq, ByteRingbuffer *buffer,
307 const SyncStreamConsumerFunc& consumer_fn) noexcept;
308
309 /** Asynchronous stream response */
318
321
322 /** Stream failed and is aborted, i.e. io_result_t::FAILED == result */
323 constexpr_atomic bool failed() const noexcept { return io_result_t::FAILED == result; }
324 /** Stream processing in progress, i.e. io_result_t::NONE == result */
325 constexpr_atomic bool processing() const noexcept { return io_result_t::NONE == result; }
326 /** Stream completed successfully, i.e. io_result_t::SUCCESS == result */
327 constexpr_atomic bool success() const noexcept { return io_result_t::SUCCESS == result; }
328
329 /// used network tookit handle, if owned by caller
331 /// background reading thread unique-pointer
332 std::thread thread;
333 /// synchronized URL header response completion
335 /// indicating whether content_length is known from server
337 /// content_length tracking the content_length
339 /// tracking the total_read
341 /// tracking io_result_t. If set to other than io_result_t::NONE while streaming, streaming is aborted. See failed(), processing() and success()
343 /// piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
344 std::vector<uint8_t> result_data;
345 /// piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
346 std::string result_text;
347 };
348 using AsyncStreamResponseRef = std::shared_ptr<AsyncStreamResponse>;
349
350 /**
351 * Asynchronous stream consumer function
352 * - `bool consumer(AsyncStreamResponse& resp, const uint8_t* data , size_t len, bool is_final)`
353 *
354 * Returns true to signal continuation, false to end streaming.
355 */
356 typedef jau::function<bool(AsyncStreamResponse& /* resp */, const uint8_t* /* data */, size_t /* len */, bool /* is_final */)> AsyncStreamConsumerFunc;
357
358 /**
359 * Asynchronous URL stream reader using the given AsyncStreamConsumerFunc consumer_fn.
360 *
361 * Function returns immediately.
362 *
363 * To abort streaming, (1) user may return `false` from the given `consumer_func`.
364 * Asynchronous URL read content using the given byte jau::ringbuffer, allowing parallel reading.
365 *
366 * To abort streaming, (2) user may set given reference `results` to a value other than async_io_result_t::NONE.
367 *
368 * Standard implementation uses [curl](https://curl.se/),
369 * hence all [*libcurl* network protocols](https://curl.se/docs/url-syntax.html) are supported,
370 * see jau::io::uri::supported_protocols().
371 *
372 * If the uri-sheme doesn't match a supported protocol, see jau::io::uri::protocol_supported(),
373 * AsyncStreamResponse::failed() returns true.
374 *
375 * Environment variables:
376 * - `jau_io_net_ssl_verifypeer=[true|false]` to enable or disable SSL peer verification. Defaults to `true`.
377 * - `jau_io_net_verbose=[true|false]` to enable or disable verbose on stderr stream communication. Defaults to `false`.
378 *
379 * @param handle optional reused user-pooled net toolkit handle, see create_net_tk_handle(). Pass nullptr to use an own local handle.
380 * @param url the URL to open a connection to and stream bytes from
381 * @param httpPostReq optional HTTP POST request data, maybe nullptr
382 * @param buffer optional jau::ringbuffer<uint8_t>, if not nullptr will be asynchronously filled with received data
383 * @param consumer_fn AsyncStreamConsumerFunc consumer for each received heap of bytes, returning true to continue stream of false to abort.
384 * @return new AsyncStreamResponse reference. If protocol of given url is not supported, AsyncStreamResponse::failed() returns true.
385 */
386 AsyncStreamResponseRef read_url_stream_async(net_tk_handle handle, const std::string& url,
387 http::PostRequestPtr httpPostReq, ByteRingbuffer *buffer,
388 const AsyncStreamConsumerFunc& consumer_fn) noexcept;
389
390 void print_stats(const std::string& prefix, const uint64_t& out_bytes_total, const jau::fraction_i64& td) noexcept;
391
392 /**@}*/
393
394 /**
395 * Limited URI toolkit to query handled protocols by the IO implementation.
396 *
397 * The URI scheme functionality exposed here is limited and only provided to decide whether the used implementation
398 * is able to handle the protocol. This is not a replacement for a proper URI class.
399 */
400 namespace uri_tk {
401 /** \addtogroup IOUtils
402 *
403 * @{
404 */
405
406 /**
407 * Returns a list of supported protocol supported by [*libcurl* network protocols](https://curl.se/docs/url-syntax.html),
408 * queried at runtime.
409 * @see protocol_supported()
410 */
411 std::vector<std::string_view> supported_protocols() noexcept;
412
413 /**
414 * Returns the valid uri-scheme from given uri,
415 * which is empty if no valid scheme is included.
416 *
417 * The given uri must include at least a colon after the uri-scheme part.
418 *
419 * @param uri an uri
420 * @return valid uri-scheme, empty if non found
421 */
422 std::string_view get_scheme(const std::string_view& uri) noexcept;
423
424 /**
425 * 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.
426 *
427 * The uri-scheme is retrieved via get_scheme() passing given uri, hence must include at least a colon after the uri-scheme part.
428 *
429 * The *libcurl* supported protocols is queried at runtime, see supported_protocols().
430 *
431 * @param uri an uri to test
432 * @return true if the uri-scheme of given uri is supported, otherwise false.
433 * @see supported_protocols()
434 * @see get_scheme()
435 */
436 bool protocol_supported(const std::string_view& uri) noexcept;
437
438 /**
439 * Returns true if the uri-scheme of given uri matches the local `file` protocol, i.e. starts with `file://`.
440 * @param uri an uri to test
441 */
442 bool is_local_file_protocol(const std::string_view& uri) noexcept;
443
444 /**
445 * Returns true if the uri-scheme of given uri matches the `http` or `https` protocol, i.e. starts with `http:` or `https:`.
446 * @param uri an uri to test
447 */
448 bool is_httpx_protocol(const std::string_view& uri) noexcept;
449
450 /**@}*/
451 }
452
453} // namespace jau::io
454
455#endif /* JAU_IO_IO_UTIL_HPP_ */
Class template jau::function is a general-purpose static-polymorphic function wrapper.
Byte stream interface.
Synchronized URL header response completion as used by asynchronous read_url_stream().
Definition io_util.hpp:177
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:198
int32_t response_code() const noexcept
Definition io_util.hpp:200
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:65
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:205
io_dir_t
I/O direction, read or write.
Definition io_util.hpp:44
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_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:312
void * net_tk_handle
Definition io_util.hpp:223
jau::function< bool(secure_vector< uint8_t > &, bool)> StreamConsumerFunc
Stream consumer function.
Definition io_util.hpp:82
uint64_t read_stream(ByteStream &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:60
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:209
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:183
io_result_t
I/O operation result value.
Definition io_util.hpp:55
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:160
jau::function< bool(AsyncStreamResponse &, const uint8_t *, size_t, bool)> AsyncStreamConsumerFunc
Asynchronous stream consumer function.
Definition io_util.hpp:356
std::string toString(io_result_t v) noexcept
Definition io_util.hpp:67
std::basic_string< char, std::char_traits< char >, jau::callocator_sec< char > > secure_string
Definition io_util.hpp:35
std::shared_ptr< SyncStreamResponse > SyncStreamResponseRef
Definition io_util.hpp:267
std::shared_ptr< AsyncStreamResponse > AsyncStreamResponseRef
Definition io_util.hpp:348
jau::function< bool(SyncStreamResponse &, const uint8_t *, size_t, bool)> SyncStreamConsumerFunc
Synchronous stream consumer function.
Definition io_util.hpp:275
jau::ringbuffer< uint8_t, size_t > ByteRingbuffer
Definition io_util.hpp:37
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:33
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:47
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:195
@ READ
Read Operation.
Definition io_util.hpp:46
@ WRITE
Write Operation.
Definition io_util.hpp:49
@ NONE
Operation still in progress.
Definition io_util.hpp:60
@ FAILED
Operation failed.
Definition io_util.hpp:57
@ SUCCESS
Operation succeeded.
Definition io_util.hpp:63
@ timeout
Input or output operation failed due to timeout.
std::unique_ptr< PostRequest > PostRequestPtr
Definition io_util.hpp:220
Limited URI toolkit to query handled protocols by the IO implementation.
Definition io_util.hpp:400
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:310
constexpr_atomic bool failed() const noexcept
Stream failed and is aborted, i.e.
Definition io_util.hpp:323
constexpr_atomic bool processing() const noexcept
Stream processing in progress, i.e.
Definition io_util.hpp:325
std::string result_text
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
Definition io_util.hpp:346
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:342
std::thread thread
background reading thread unique-pointer
Definition io_util.hpp:332
relaxed_atomic_bool has_content_length
indicating whether content_length is known from server
Definition io_util.hpp:336
relaxed_atomic_uint64 total_read
tracking the total_read
Definition io_util.hpp:340
AsyncStreamResponse(net_tk_handle handle_)
Definition io_util.hpp:311
net_tk_handle handle
used network tookit handle, if owned by caller
Definition io_util.hpp:330
std::vector< uint8_t > result_data
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
Definition io_util.hpp:344
relaxed_atomic_uint64 content_length
content_length tracking the content_length
Definition io_util.hpp:338
url_header_resp header_resp
synchronized URL header response completion
Definition io_util.hpp:334
constexpr_atomic bool success() const noexcept
Stream completed successfully, i.e.
Definition io_util.hpp:327
Synchronous stream response.
Definition io_util.hpp:231
constexpr_atomic bool processing() const noexcept
Stream processing in progress, i.e.
Definition io_util.hpp:246
uint64_t total_read
tracking the total_read
Definition io_util.hpp:259
uint64_t content_length
content_length tracking the content_length
Definition io_util.hpp:257
url_header_resp header_resp
synchronized URL header response completion
Definition io_util.hpp:253
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:261
constexpr_atomic bool failed() const noexcept
Stream failed and is aborted, i.e.
Definition io_util.hpp:244
bool has_content_length
indicating whether content_length is known from server
Definition io_util.hpp:255
constexpr_atomic bool success() const noexcept
Stream completed successfully, i.e.
Definition io_util.hpp:248
std::string result_text
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
Definition io_util.hpp:265
std::vector< uint8_t > result_data
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
Definition io_util.hpp:263
SyncStreamResponse(net_tk_handle handle_)
Definition io_util.hpp:232
net_tk_handle handle
used network tookit handle, if owned by caller
Definition io_util.hpp:251
std::unordered_map< std::string, std::string > header
Definition io_util.hpp:217
std::atomic<T> type with predefined fixed std::memory_order, not allowing changing the memory model o...