43 #include "QtCore/qdatastream.h" 44 #include <QCoreApplication> 45 #include "private/qnoncontiguousbytedevice_p.h" 49 #ifdef QT_BUILD_INTERNAL 52 ReadBufferSize = 16384,
53 WriteBufferSize = ReadBufferSize
73 return new QNetworkAccessDebugPipeBackend;
77 QNetworkAccessDebugPipeBackend::QNetworkAccessDebugPipeBackend()
78 : bareProtocol(false), hasUploadFinished(false), hasDownloadFinished(false),
79 hasEverythingFinished(false), bytesDownloaded(0), bytesUploaded(0)
83 QNetworkAccessDebugPipeBackend::~QNetworkAccessDebugPipeBackend()
86 socket.disconnect(
this);
91 socket.connectToHost(
url().host(),
url().port(12345));
92 socket.setReadBufferSize(ReadBufferSize);
111 void QNetworkAccessDebugPipeBackend::socketReadyRead()
113 pushFromSocketToDownstream();
116 void QNetworkAccessDebugPipeBackend::downstreamReadyWrite()
118 pushFromSocketToDownstream();
121 void QNetworkAccessDebugPipeBackend::socketBytesWritten(
qint64)
123 pushFromUpstreamToSocket();
126 void QNetworkAccessDebugPipeBackend::uploadReadyReadSlot()
128 pushFromUpstreamToSocket();
131 void QNetworkAccessDebugPipeBackend::pushFromSocketToDownstream()
140 if (hasDownloadFinished)
143 buffer.
resize(ReadBufferSize);
144 qint64 haveRead = socket.read(buffer.
data(), ReadBufferSize);
146 if (haveRead == -1) {
147 hasDownloadFinished =
true;
152 }
else if (haveRead == 0) {
157 bytesDownloaded += haveRead;
167 void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket()
171 if (hasUploadFinished)
175 if (socket.bytesToWrite() >= WriteBufferSize)
180 if (haveRead == -1) {
182 hasUploadFinished =
true;
186 }
else if (haveRead == 0 || readPointer == 0) {
191 haveWritten = socket.write(readPointer, haveRead);
193 if (haveWritten < 0) {
202 bytesUploaded += haveWritten;
213 void QNetworkAccessDebugPipeBackend::possiblyFinish()
215 if (hasEverythingFinished)
217 hasEverythingFinished =
true;
230 void QNetworkAccessDebugPipeBackend::closeDownstreamChannel()
232 qWarning(
"QNetworkAccessDebugPipeBackend::closeDownstreamChannel() %d",
operation());;
238 void QNetworkAccessDebugPipeBackend::socketError()
240 qWarning(
"QNetworkAccessDebugPipeBackend::socketError() %d",socket.error());
242 switch (socket.error()) {
255 error(code, QNetworkAccessDebugPipeBackend::tr(
"Socket error on %1: %2")
262 void QNetworkAccessDebugPipeBackend::socketDisconnected()
264 pushFromSocketToDownstream();
266 if (socket.bytesToWrite() == 0) {
270 QString msg = QNetworkAccessDebugPipeBackend::tr(
"Remote host closed the connection prematurely on %1")
277 void QNetworkAccessDebugPipeBackend::socketConnected()
The QVariant class acts like a union for the most common Qt data types.
#define QT_END_NAMESPACE
This macro expands to.
char * data()
Returns a pointer to the data stored in the byte array.
The QByteArray class provides an array of bytes.
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
NetworkError
Indicates all possible error conditions found during the processing of the request.
Operation
Indicates the operation this reply is processing.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void append(QByteDataBuffer &other)
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
QUrl url() const
Returns the URL this network request is referring to.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
virtual const char * readPointer(qint64 maximumLength, qint64 &len)=0
Return a byte pointer for at most maximumLength bytes of that device.
static QString toString(Register *reg, int type, bool *ok=0)
QNonContiguousByteDevice * createUploadByteDevice()
#define QT_BEGIN_NAMESPACE
This macro expands to.
static QIntfbScreen * connected
void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
SocketError
This enum describes the socket errors that can occur.
Q_CORE_EXPORT void qWarning(const char *,...)
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
QNetworkAccessManager::Operation operation() const
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
QSharedPointer< QNonContiguousByteDevice > uploadByteDevice
QString scheme() const
Returns the scheme of the URL.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
void error(QNetworkReply::NetworkError code, const QString &errorString)
virtual bool advanceReadPointer(qint64 amount)=0
The old readPointer is invalid after this call.
void resize(int size)
Sets the size of the byte array to size bytes.
QString queryItemValue(const QString &key) const
Returns the first query string value whose key is equal to key from the URL.
void writeDownstreamData(QByteDataBuffer &list)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
void clear()
Clears the contents of the byte array and makes it empty.
int open(const char *, int,...)
#define forever
This macro is provided for convenience for writing infinite loops.