Qt Base (Core, Gui, Widgets, Network, ...)
Go to file
Ivan Solovev 65b7217ae7 Add QRandomAccessAsyncFile and QIOOperation
For now, as a private API.

The QRandomAccessAsyncFile class is supposed to handle async read
and write operations. Note that some operations (e.g. open() and
size()) are synchronous, because the tests showed that they
normally would not block even if the file is not actually downloaded
(e.g. stored on a MS OneDrive).

The implementation for async calls is inspired by QNetworkAccessManager
and QNetworkReply. The request for an async read or write returns a
pointer to a QIOOperation object. That object will emit a finished()
signal when the operation is complete, and an errorOccurred() signal,
if there was any error. The user has to connect to these signals to
handle the results. The typical usecase would be:

  QRandomAccessAsyncFile file;
  file.open(path, mode);
  auto op = file.read(offset, maxSize);
  connect(op, &QIOOperation::finished, &file, [op] {
    if (op->error() != QIOOperation::Error::None)
      // handle error
    // handle the data
    op->deleteLater();
  });

Similarly to QNetworkReply, the user has to call deleteLater() in the
callback that is connected to the signal.

The API provides two types of methods:
* owning methods that take ownership of the provided data-to-write or
  read into a buffer that is allocated internally. These are
  QRAAF::read() and QRAAF::write(). They exist for simplicity and user
  convenience.
* non-owning methods that rely on the user to keep the provided buffers
  alive as long as the operation in not completed. These are
  QRAAF::readInto() and QRAAF::writeFrom(). They have overloads taking
  span-of-spans, which should allow to implement vectored IO.

QIOOperation should become a public class at some point.
This means that its APIs should be easy to use, and also extensible.
It should not be limited to only Read and Write.

The hierarchy of IO operations is represented by QIOOperation and its
derived classes. The base class can be used when the user is not
interested in the data of the operation, or if the operation should
only report success of failure.
The derived classes implement data() methods with various return
types. The classes that represent Read and Write operations also
additionally provide offset() and numBytesProcessed() methods.

The patch also introduces QtPrivate::QIOOperationDataStorage that
holds a std::variant of all possible values that the operation can
contain. If needed, this variant can be extended to hold a QVariant
in order to store an arbitrary value.

This patch also provides the fallback QThreadpool-based implementation
that simply executes the requests on the dedicated threadpool using
QFuture. For simplicity, this implementation uses QFSFileEngine to
provide all operations.

The implementations for various backends should be added in follow-up
patches.

Task-number: QTBUG-136763
Change-Id: I8f34f9e78d91aa35756352de7fbe6544b58de23e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-09-15 13:22:47 +02:00
.github/workflows
LICENSES Merge Wayland client from qtwayland repository into qtbase 2025-05-13 01:50:43 +02:00
bin CMake: Don't hard-code "libexec" in qt-configure-module 2024-08-16 12:36:35 +02:00
cmake cmake: Don't create framework header directories unless we have headers 2025-09-12 15:13:38 +02:00
coin Coin: Add update repo instructions 2025-09-03 23:23:58 +00:00
config.tests CMake: Remove superfluous precompile_header feature and config test 2025-03-07 12:02:47 +01:00
dist Remove year from Qt Copyright in REUSE.toml 2025-07-09 15:16:21 +02:00
doc Doc: Add squish testing info to example template 2025-08-29 14:58:27 +02:00
examples Doc: Document the specific headers for the Qt Concurrent module 2025-09-09 15:35:39 +03:00
lib
libexec qt-android-runner.py: support launching any activity name 2025-08-22 22:11:29 +03:00
mkspecs qmake: Make ccache feature available on windows hosts 2025-08-15 15:19:50 +02:00
qmake Fail builds on Apple platforms with invalid Info.plist 2025-07-04 15:02:22 +02:00
src Add QRandomAccessAsyncFile and QIOOperation 2025-09-15 13:22:47 +02:00
tests Add QRandomAccessAsyncFile and QIOOperation 2025-09-15 13:22:47 +02:00
util util/unicode: split and trim in readUnicodeFile() to save repetition 2025-09-09 12:35:39 +00:00
.cmake.conf Bump tested and supported macOS and iOS versions to 26 2025-09-08 16:29:14 +00:00
.gitattributes
.gitignore Fix .gitignore to ignore any build dir under the repo or its subdirs 2025-07-22 19:12:39 +00:00
.gitreview Add .gitreview file 2025-03-24 23:19:04 +01:00
.tag
CMakeLists.txt CMake: Don't unconditionally enable the ASM language 2025-05-02 18:13:14 +02:00
REUSE.toml REUSE: Add annotations for QDoc generated metadata files 2025-09-08 21:01:57 +02:00
config_help.txt Make doc-snippets a "build part", ie -nomake/make doc-snippets 2025-07-30 16:01:51 +02:00
configure
configure.bat configure.bat: Use call when calling the helper cmake scripts 2025-01-30 22:18:36 +01:00
configure.cmake CMake: x86intrin - prevent re-configure failure with UBs 2025-09-08 04:05:34 +00:00
dependencies.yaml
licenseRule.json CMake: support reduced relocations for namespaced Qt 2025-08-14 05:52:37 +08:00
qt_cmdline.cmake Make doc-snippets a "build part", ie -nomake/make doc-snippets 2025-07-30 16:01:51 +02:00