aboutsummaryrefslogtreecommitdiffstats
path: root/src/io_util.cpp
Commit message (Collapse)AuthorAgeFilesLines
* cleanup: includes, space, missing inline (ODR), drop cast, drop return statementSven Göthel2024-09-141-1/+0
|
* cleanup C++20: Review bugprone-casting-through-void; Fix includes; Use ↵Sven Göthel2024-05-191-1/+1
| | | | type-traits _v and _t; Use std::string::starts_with(); Use std::numbers::pi_v
* jau::ringbuffer: Add 'End of Stream' (EOS) concept and utilize it for ↵v1.1.1Sven Gothel2023-01-021-12/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | jau::io::ByteInStream_[URL|Feed]'s available() and read() operation. jau::ringbuffer: Add 'End of Stream' (EOS) concept to unblock all read-operations from this point onwards and unblocking a potentially currently blocked reader thread. The EOS concept is required to allow blocking operations from a consumer (reader) w/o knowledge of the content-size, having the producer (writer) signaling EOS at the end and unblocking all read-operations. Fuerther, after unblocking a potentially blocker reader-thread, the failure criteria is now being checked as for the `timeout` case. This allows a read-thread being unblocked (interrupted) after writing the last chunk and hence picking up this last written data. +++ Utilize ringbuffer EOS concept for jau::io::ByteInStream_[URL|Feed]'s available() and read() operation, i.e. both methods utilize blocking operations. After the producer (URL: Our Curl consume callback; Feed: Manual set_eof()) marks EOS on the ringbuffer, all blocking read-operations are permanently unblocked and a current read-thread also interrupted. +++ Passed test_bytestream01 and test_iostream01 while causing full CPU load via `stress --cpu $(getconf _NPROCESSORS_ONLN)`.
* jau::io::read_stream/URL: Adopt to end_of_data() -> !good(); ↵Sven Gothel2023-01-011-10/+19
| | | | jau::io::consume_data_curl2 consider putBlocking result and call header_sync.notify_complete() after content_length setting
* clang-tidy: Add 'performance-' fixesSven Gothel2022-11-271-4/+4
| | | | | | | - Drop 'std::move' for trivially copyable things - Use 'const T&' if not moved into and used as R value only - Notable: Can also hold a default value! - Use non-const local vars, if used as return or move value
* clang-tidy: jau::io::read_url_stream() noexcept: Drop potential ↵Sven Gothel2022-11-261-4/+0
| | | | buffer.recapacity() as it may throw and is not described in API
* clang-tidy (C++ lint): Enable for vscode, optional @ commandline (see ↵Sven Gothel2022-11-261-1/+1
| | | | scripts/build.sh), simple lint fixes.
* ClangTidy: Misc fixes: Use override, conversion, nullptr, c-includes, ↵Sven Gothel2022-11-211-8/+8
| | | | default implementation (ctor, dtor, ..), ..
* async read_url_stream(): Add `url_header_sync` object to notify user whether ↵Sven Gothel2022-08-301-16/+67
| | | | | | | | | | | | | header is complete (or an error occured, i.e. past header streaming stage) `url_header_sync` allows user to wait until the url streamed header is completed, either - Final (http) CRLF message received - Any http header error response received - First data package received - End of operation This way content_size can be awaited and acted accordingly at read, e.g. a blocking read w/ content_size.
* io_util.cpp: Enhance error messages, minor whitespace editSven Gothel2022-08-281-25/+25
|
* io_util/byte_stream: Decouple from Botan, add iostate and new Byte*Stream* ↵Sven Gothel2022-08-051-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | super iostate_func class for std::basic_ios's iostate functionality The burden of having a compile time header dependency to ByteInStream is too high and may cause 'confusion' if linking unit w/ different settings - to say the very least! In case Botan::DataSource is required, user shall wrap ByteInStream into such desired types. +++ Don't include any iostream header. std::basic_ios's iostate functionality allows us to reuse the std spec for our streaming classes, enforcing a well specified iostate to be defined either by just setting the iostate at read() for non-async sources like file or by dynamical evaluation via rdstate() override for async sources. Use shorter method names, eg check_available() -> available() and iostream affine names, eg bytes_read() -> tellg(). Use 'void*' buffer types for read() and peak(), similar to POSIX, removing the burden for a nonsense cast. Drop ByteInStream_istream.
* jau::io::read_stream(): Guarantee consumer_fn() is called with ↵Sven Gothel2022-08-021-3/+3
| | | | `is_final=true` once at the end, even if input stream has zero size
* ByteInStream_File: Remove obsolete `use_binary` arg, byte streams are always ↵Sven Gothel2022-07-311-1/+1
| | | | binary; Java: Add dirfd and fd ctor variants
* Add jau::io::read_stream() with double-buffered reading to ensure last ↵Sven Gothel2022-07-311-2/+72
| | | | | | | consumer_fn() call gets is_final set if next buffer has eof() w/ zero bytes. This behavior is required for certain operations, i.e. where we cannot have a zero-sized consumer_fn() call as is_final=true. Example: cipherpack using Botan API, where AEAD::finish() requires the last Tag bytes to be delivered.
* jau::io::read_stream(): Issue final consumer_fn() call w/ zero size if no ↵Sven Gothel2022-07-291-0/+2
| | | | bytes are available, ensuring user notification
* Java: Move 'org.jau.nio' content -> 'org.jau.io' and 'org.jau.nio.Uri' -> ↵Sven Gothel2022-07-071-10/+10
| | | | ''org.jau.nio.UriTk'; C++: 'jau::io::uri' -> 'jau::io::uri_tk'
* Use libcurl optional, enable via cmake option `-DUSE_LIBCURL=ON` and remove ↵Sven Gothel2022-06-181-3/+27
| | | | dependencies w/o using it
* Clean up io_util.hpp and byte_stream.hpp: Have the former be more self ↵Sven Gothel2022-06-051-0/+1
| | | | contained and include the low level declarations.
* Bump v0.13.0: jau::io changes for robust and simplified ByteInStream usage ↵v0.13.0Sven Gothel2022-06-041-7/+69
| | | | | | | | | | | | | | | | | | sourced as file or via remote URL * `string_util.hpp`: Add `jau::to_string()` support for `std::string` and `std::string_view` as well as for `std::vector<T>` lists * Add namespace `jau::io::uri`, limited URI scheme functionality to query whether implementation may handle the protocol. - Query *libcurl* supported protocols at runtime - Test for local file protocol - Test whether protocol in given uri is supported by *libcurl* * `jau::io::read_url_stream()`, sync and async, return immediately if protocol in given url is not supportet - async variant returns `std::unique_ptr<std::thread>`, where a nullptr is used for no support * `jau::io::ByteInStream_File` recognizes the local file protocol and cuts off `file://` is used. - Fix: Recognition of a non-existing path, unaccessbile path or non-file case properly * `jau::io::ByteInStream_URL` recognizes a non supported protocol via async `jau::io::read_url_stream()`. * Added convenient `jau::io::std::unique_ptr<ByteInStream> to_ByteInStream()` - Returning either a `jau::io::ByteInStream_File`, `jau::io::ByteInStream_URL` or nullptr if `path_or_url` is not supported * Make Java class `org.jau.ney.Uri` standalone, drop dependencies for easier reusage.
* io::read_url_stream(): Fix using std::string -> char * in ERR_PRINTSven Gothel2022-05-301-4/+4
|
* io::read_url_stream: Fix content_length (-1 == unknown), add consume_header ↵Sven Gothel2022-05-291-23/+188
| | | | | | | | | | | | | | | | | | | | | | w/ response_code for errors >= 400 and buffer.interruptReader() - curl replies -1 for unknown content_length - also consume the curl header to detect response_code errors >= 400 (404 not found) - in case of an error, we need to interrupt the ringbuffer-reader thread -> buffer.interruptReader(), otherwise the thread would be blocked until timeout and renders application to not be responsive. - interruptReader() has been added for the synchronous- and asynchronous read_url_stream() functions - interruptReader() has been exposed as ByteInStream_Feed::interruptReader() and added to ByteInStream_Feed::set_eof(). - the above is tested via test_iostream01 for synchronous- and asynchronous read_url_stream() functions using a non-existing URL entity - the above is tested via test_bytestream01 for ByteInStream_URL using a non-existing URL entity and for and ByteInStream_Feed having the feeder thread prematurely end transmission.
* ByteInStream: Add content_size methods and replace exp_size, mark/implement ↵Sven Gothel2022-05-291-74/+53
| | | | all methods noexcept, see Botan related notes; Add test_bytestream01 unit tests.
* io::read*(): Document API and have 'em all noexcept while catching potential ↵Sven Gothel2022-05-291-14/+26
| | | | exception on consumer_fn call
* Add IOUtils Module/Group; Rename Byte{->In}Stream interface and implementationsSven Gothel2022-05-281-11/+11
|
* Integrating byte_stream.* and io_util.* incl. unit test from Elevator ↵Sven Gothel2022-05-281-0/+419
project for better encapsulation, test and generic use Fixed: ByteStream_File::check_available(): 'm_bytes_consumed - m_content_size >= n', missed subtracting m_content_size (duh) test_iostream01 uses the fragile std::system() call to start/stop mini_httpd as the http server for testing streaming with curl.