26#ifndef JAU_IO_UTIL_HPP_
27#define JAU_IO_UTIL_HPP_
46 template<
typename T>
using secure_vector = std::vector<T, jau::callocator_sec<T>>;
84 default:
return "FAILED";
113 uint64_t
read_file(
const std::string& input_file,
196 std::condition_variable m_cv;
233 std::unordered_map<std::string, std::string>
header;
438 std::string_view
get_scheme(
const std::string_view& uri)
noexcept;
Class template jau::function is a general-purpose static-polymorphic function wrapper.
Abstract byte input stream object.
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.
jau::ordered_atomic< io_result_t, std::memory_order_relaxed > relaxed_atomic_io_result_t
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.
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.
io_dir_t
I/O direction, read or write.
net_tk_handle create_net_tk_handle() noexcept
creates a reusable handle, free with free_net_tk_handle() after use.
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.
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.
jau::function< bool(secure_vector< uint8_t > &, bool)> StreamConsumerFunc
Stream consumer function.
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....
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.
io_result_t
I/O operation result value.
std::vector< std::string_view > supported_protocols() noexcept
Returns a list of supported protocol supported by libcurl network protocols, queried at runtime.
jau::function< bool(AsyncStreamResponse &, const uint8_t *, size_t, bool)> AsyncStreamConsumerFunc
Asynchronous stream consumer function.
std::string toString(io_result_t v) noexcept
std::basic_string< char, std::char_traits< char >, jau::callocator_sec< char > > secure_string
std::shared_ptr< SyncStreamResponse > SyncStreamResponseRef
std::shared_ptr< AsyncStreamResponse > AsyncStreamResponseRef
jau::function< bool(SyncStreamResponse &, const uint8_t *, size_t, bool)> SyncStreamConsumerFunc
Synchronous stream consumer function.
jau::ringbuffer< uint8_t, size_t > ByteRingbuffer
void free_net_tk_handle(net_tk_handle handle) noexcept
frees a handle after use created by create_net_tk_handle()
const size_t BEST_URLSTREAM_RINGBUFFER_SIZE
std::vector< T, jau::callocator_sec< T > > secure_vector
void print_stats(const std::string &prefix, const uint64_t &out_bytes_total, const jau::fraction_i64 &td) noexcept
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...
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...
@ timeout
Input or output operation failed due to timeout.
@ NONE
Operation still in progress.
@ FAILED
Operation failed.
@ SUCCESS
Operation succeeded.
std::unique_ptr< PostRequest > PostRequestPtr
Limited URI toolkit to query handled protocols by the IO implementation.
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.
A simple secure allocator for integral types using POSIX C functions: ::malloc() and ::free().
Asynchronous stream response.
constexpr_atomic bool failed() const noexcept
Stream failed and is aborted, i.e.
constexpr_atomic bool processing() const noexcept
Stream processing in progress, i.e.
std::string result_text
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
relaxed_atomic_io_result_t result
tracking io_result_t. If set to other than io_result_t::NONE while streaming, streaming is aborted....
std::thread thread
background reading thread unique-pointer
relaxed_atomic_bool has_content_length
indicating whether content_length is known from server
relaxed_atomic_uint64 total_read
tracking the total_read
AsyncStreamResponse(net_tk_handle handle_)
net_tk_handle handle
used network tookit handle, if owned by caller
std::vector< uint8_t > result_data
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
relaxed_atomic_uint64 content_length
content_length tracking the content_length
url_header_resp header_resp
synchronized URL header response completion
constexpr_atomic bool success() const noexcept
Stream completed successfully, i.e.
Synchronous stream response.
constexpr_atomic bool processing() const noexcept
Stream processing in progress, i.e.
uint64_t total_read
tracking the total_read
uint64_t content_length
content_length tracking the content_length
url_header_resp header_resp
synchronized URL header response completion
relaxed_atomic_io_result_t result
tracking io_result_t. If set to other than io_result_t::NONE while streaming, streaming is aborted....
constexpr_atomic bool failed() const noexcept
Stream failed and is aborted, i.e.
bool has_content_length
indicating whether content_length is known from server
constexpr_atomic bool success() const noexcept
Stream completed successfully, i.e.
std::string result_text
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
std::vector< uint8_t > result_data
piggy-bag result data compiled by user, e.g. via AsyncStreamConsumerFunc
SyncStreamResponse(net_tk_handle handle_)
net_tk_handle handle
used network tookit handle, if owned by caller
std::unordered_map< std::string, std::string > header
std::atomic<T> type with predefined fixed std::memory_order, not allowing changing the memory model o...