diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2020-04-13 11:59:54 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2020-04-13 11:59:54 +0300 |
commit | 45defa9dbf3d3562c37efe48ab98bca55648afba (patch) | |
tree | 861f61f6883f7173bf107f482ff8bef3b1f12f69 /example | |
parent | 48d74e82e05e1756467441de4e916996c1a9b4be (diff) |
Tests now all pass on resumable i/o branch merge.
Diffstat (limited to 'example')
-rw-r--r-- | example/use_cases.cpp | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/example/use_cases.cpp b/example/use_cases.cpp index ac93b06b..3fb5cc1e 100644 --- a/example/use_cases.cpp +++ b/example/use_cases.cpp @@ -65,92 +65,6 @@ void read_entire_file1() //! [file_entire_file1] } -void read_entire_file2() -{ - //! [file_entire_file2] - namespace llfio = LLFIO_V2_NAMESPACE; - - // Create an i/o service to complete the async file i/o - llfio::io_service service; - - // Open the file for read - llfio::async_file_handle fh = llfio::async_file( // - service, // The i/o service to complete i/o to - {}, // path_handle to base directory - "foo" // path_view to path fragment relative to base directory - // default mode is read only - // default creation is open existing - // default caching is all - // default flags is none - ).value(); // If failed, throw a filesystem_error exception - - // Get the valid extents of the file. - const std::vector< - llfio::file_handle::extent_pair - > valid_extents = fh.extents().value(); - - // Schedule asynchronous reads for every valid extent - std::vector<std::pair<std::vector<llfio::byte>, llfio::async_file_handle::io_state_ptr>> buffers(valid_extents.size()); - for (size_t n = 0; n < valid_extents.size(); n++) - { - // Set up the scatter buffer - buffers[n].first.resize(valid_extents[n].length); - for(;;) - { - llfio::async_file_handle::buffer_type scatter_req{ buffers[n].first.data(), buffers[n].first.size() }; // buffer to fill - auto ret = llfio::async_read( // - fh, // handle to read from - { { &scatter_req, 1 }, valid_extents[n].offset }, // The scatter request buffers + offset - []( // The completion handler - llfio::async_file_handle *, // The parent handle - llfio::async_file_handle::io_result<llfio::async_file_handle::buffers_type> && // Result of the i/o - ) { /* do nothing */ } - // default deadline is infinite - ); - // Was the operation successful? - if (ret) - { - // Retain the handle to the outstanding i/o - buffers[n].second = std::move(ret).value(); - break; - } - if (ret.error() == llfio::errc::resource_unavailable_try_again) - { - // Many async file i/o implementations have limited total system concurrency - std::this_thread::yield(); - continue; - } - // Otherwise, throw a filesystem_error exception - ret.value(); - } - } - - // Pump i/o completion until no work remains - while (service.run().value()) - { - // run() returns per completion handler dispatched if work remains - // It blocks until some i/o completes (there is a polling and deadline based overload) - // If no work remains, it returns false - } - - // Gather the completions of all i/o scheduled for success and errors - for (auto &i : buffers) - { - // Did the read succeed? - if (i.second->result.read) - { - // Then adjust the buffer size to that actually read - i.first.resize(i.second->result.read.value().size()); - } - else - { - // Throw the cause of failure as an exception - i.second->result.read.value(); - } - } - //! [file_entire_file2] -} - void scatter_write() { /* WARNING: This example cannot possibly work because files opened with caching::only_metadata |