qtbase/tests/auto
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
..
bic/data Add binary compatibility file for 6.9.0 2025-04-09 14:57:42 +03:00
cmake CMake: add QT_NAMESPACE property to Qt::Core 2025-09-04 02:01:22 +00:00
concurrent QtConcurrent: fix support for callables with deduced return type 2025-01-06 10:48:34 +01:00
corelib Add QRandomAccessAsyncFile and QIOOperation 2025-09-15 13:22:47 +02:00
dbus QDBusIntegrator: Set QDBusContext when processing properties 2025-07-28 18:50:51 +02:00
gui Wayland: skip tst_QWindow::modalWindowEnterEventOnHide_QTBUG35109() 2025-09-08 14:00:14 +02:00
guiapplauncher
network tst_QUdpSocket: test UDP broadcasting using a dual-socket IPv6 2025-09-02 11:44:10 -07:00
opengl
other wasm: a11y - Implement ParentChanged callback 2025-09-08 16:50:11 +02:00
printsupport Unblacklist tst_qPrinter::testPrintPreviewDialog on Ubuntu Wayland 2025-06-10 18:41:35 +02:00
shared QTextOption: Add flag for showing default ignorable characters 2024-10-10 18:36:58 +03:00
sql SQL/ODBC: fix reading REAL values 2025-07-31 03:12:38 +02:00
testlib QCOMPARE: print the payload of NaNs 2025-08-08 20:39:20 +00:00
tools uic/Python: Handle surrogates correctly 2025-09-08 14:00:15 +02:00
wasm wasm: Fix stacking order problem for transient parent windows 2025-05-26 13:27:17 +02:00
wayland tests: buffer overflow warning in wayland reconnect test 2025-08-20 11:47:55 +08:00
widgets Android: blacklist tst_QGridLayout::spacingsAndMargins 2025-09-10 21:56:40 +00:00
xml QDom: Fix setAttributeNode() to properly replace existing attributes 2025-03-18 11:49:56 +01:00
CMakeLists.txt wasm: enable previously disabled tests on WebAssembly 2025-05-19 16:03:29 +00:00
network-settings.h