Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnetworkreplywasmimpl_p.h
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QNETWORKREPLYWASMIMPL_H
6#define QNETWORKREPLYWASMIMPL_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qnetworkreply.h"
22
23#include <QtCore/qfile.h>
24
25#include <private/qtnetworkglobal_p.h>
26#include <private/qabstractfileengine_p.h>
27
28#include <emscripten.h>
29#include <emscripten/fetch.h>
30
31#include <memory>
32#include <mutex>
33
34QT_BEGIN_NAMESPACE
35
36class QIODevice;
37
40{
42public:
45 virtual void abort() override;
46
47 // reimplemented from QNetworkReply
48 virtual void close() override;
49 virtual qint64 bytesAvailable() const override;
50 virtual bool isSequential () const override;
51 qint64 size() const override;
52
53 virtual qint64 readData(char *data, qint64 maxlen) override;
54
55 void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request,
56 QIODevice *outgoingData);
57
59
63
64private:
65 QByteArray methodName() const;
66};
67
69
70/*!
71 The FetchContext class ensures the requestData object remains valid
72 while a fetch operation is pending. Since Emscripten fetch is asynchronous,
73 requestData must persist until one of the final callbacks is invoked.
74 Additionally, there's a potential race condition between the thread
75 scheduling the fetch operation and the one executing it. Since fetch must
76 occur on the main thread due to browser limitations,
77 a mutex safeguards the FetchContext to ensure atomic state transitions.
78*/
90
92{
93public:
96
98 void doSendRequest();
99 static void setReplyAttributes(quintptr data, int statusCode, const QString &statusReason);
100
101 void emitReplyError(QNetworkReply::NetworkError errorCode, const QString &);
102 void emitDataReadProgress(qint64 done, qint64 total);
103 void dataReceived(const QByteArray &buffer);
104 void headersReceived(const QByteArray &buffer);
105
106 void setStatusCode(int status, const QByteArray &statusText);
107
108 void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request,
109 QIODevice *outgoingData);
110
114
117
120
126
127 QIODevice *outgoingData;
129
130 static void downloadProgress(emscripten_fetch_t *fetch);
131 static void downloadFailed(emscripten_fetch_t *fetch);
132 static void downloadSucceeded(emscripten_fetch_t *fetch);
133 static void stateChange(emscripten_fetch_t *fetch);
134
135 static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const QUrl &url);
136
139 void setReplyFinished();
140 void setCanceled();
141
142 Q_DECLARE_PUBLIC(QNetworkReplyWasmImpl)
143};
144
145QT_END_NAMESPACE
146
147#endif // QNETWORKREPLYWASMIMPL_H
std::shared_ptr< QRingBuffer > outgoingDataBuffer
static void setReplyAttributes(quintptr data, int statusCode, const QString &statusReason)
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
static void downloadFailed(emscripten_fetch_t *fetch)
static void downloadSucceeded(emscripten_fetch_t *fetch)
void emitReplyError(QNetworkReply::NetworkError errorCode, const QString &)
void setStatusCode(int status, const QByteArray &statusText)
std::shared_ptr< QAtomicInt > pendingDownloadData
std::shared_ptr< QAtomicInt > pendingDownloadProgress
void headersReceived(const QByteArray &buffer)
static void stateChange(emscripten_fetch_t *fetch)
QNetworkAccessManagerPrivate * managerPrivate
void emitDataReadProgress(qint64 done, qint64 total)
static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const QUrl &url)
static void downloadProgress(emscripten_fetch_t *fetch)
void dataReceived(const QByteArray &buffer)
qint64 size() const override
For open random-access devices, this function returns the size of the device.
virtual qint64 bytesAvailable() const override
Returns the number of bytes that are available for reading.
virtual qint64 readData(char *data, qint64 maxlen) override
virtual void abort() override
Aborts the operation immediately and closes any network connections still open.
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
virtual bool isSequential() const override
\reimp
virtual void close() override
Closes this device for reading.
Combined button and popup list for selecting options.
constexpr int getArraySize(int factor)
static int parseHeaderName(const QByteArray &headerName)
The FetchContext class ensures the requestData object remains valid while a fetch operation is pendin...
FetchContext(QNetworkReplyWasmImplPrivate *networkReply)
QNetworkReplyWasmImplPrivate * reply