summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qabstractsocket.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2016-03-22 07:24:57 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2016-03-22 07:28:42 +0100
commita02863234d76abb6c9f289026ae4ea3145924f30 (patch)
treeaef6381d0000a78ba69ac80eb03739b1c8ca5fc3 /src/network/socket/qabstractsocket.cpp
parente77b13621f0057374d83a2b884f03dd2e5b7b88c (diff)
parente4d79e1fdeb6b26ba0b12b578daacf7cd672b960 (diff)
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts: configure mkspecs/common/wince/qplatformdefs.h src/plugins/platforms/directfb/qdirectfbbackingstore.cpp src/plugins/platforms/xcb/qxcbbackingstore.cpp Change-Id: Ied4d31264a9afca9514b51a7eb1494c28712793c
Diffstat (limited to 'src/network/socket/qabstractsocket.cpp')
-rw-r--r--src/network/socket/qabstractsocket.cpp77
1 files changed, 56 insertions, 21 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index 0969d84180..3ce2d63a39 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -562,7 +562,6 @@ QAbstractSocketPrivate::QAbstractSocketPrivate()
socketEngine(0),
cachedSocketDescriptor(-1),
readBufferMaxSize(0),
- writeBuffer(QABSTRACTSOCKET_BUFFERSIZE),
isBuffered(false),
connectTimer(0),
disconnectTimer(0),
@@ -572,6 +571,7 @@ QAbstractSocketPrivate::QAbstractSocketPrivate()
socketError(QAbstractSocket::UnknownSocketError),
preferredNetworkLayerProtocol(QAbstractSocket::UnknownNetworkLayerProtocol)
{
+ writeBufferChunkSize = QABSTRACTSOCKET_BUFFERSIZE;
}
/*! \internal
@@ -852,15 +852,16 @@ bool QAbstractSocketPrivate::writeToSocket()
written);
#endif
- // Remove what we wrote so far.
- writeBuffer.free(written);
if (written > 0) {
+ // Remove what we wrote so far.
+ writeBuffer.free(written);
// Don't emit bytesWritten() recursively.
if (!emittedBytesWritten) {
QScopedValueRollback<bool> r(emittedBytesWritten);
emittedBytesWritten = true;
emit q->bytesWritten(written);
}
+ emit q->channelBytesWritten(0, written);
}
if (writeBuffer.isEmpty() && socketEngine && !socketEngine->bytesToWrite())
@@ -1286,6 +1287,7 @@ void QAbstractSocketPrivate::emitReadyRead()
emittedReadyRead = true;
emit q->readyRead();
}
+ emit q->channelReadyRead(0);
}
/*! \internal
@@ -1298,6 +1300,18 @@ void QAbstractSocketPrivate::fetchConnectionParameters()
peerName = hostName;
if (socketEngine) {
+ if (q->isReadable()) {
+ const int inboundStreamCount = socketEngine->inboundStreamCount();
+ setReadChannelCount(qMax(1, inboundStreamCount));
+ if (inboundStreamCount == 0)
+ readChannelCount = 0;
+ }
+ if (q->isWritable()) {
+ const int outboundStreamCount = socketEngine->outboundStreamCount();
+ setWriteChannelCount(qMax(1, outboundStreamCount));
+ if (outboundStreamCount == 0)
+ writeChannelCount = 0;
+ }
socketEngine->setReadNotificationEnabled(true);
socketEngine->setWriteNotificationEnabled(true);
localPort = socketEngine->localPort();
@@ -1620,8 +1634,8 @@ void QAbstractSocket::connectToHost(const QString &hostName, quint16 port,
d->preferredNetworkLayerProtocol = protocol;
d->hostName = hostName;
d->port = port;
- d->buffer.clear();
- d->writeBuffer.clear();
+ d->setReadChannelCount(0);
+ d->setWriteChannelCount(0);
d->abortCalled = false;
d->pendingClose = false;
if (d->state != BoundState) {
@@ -1654,6 +1668,8 @@ void QAbstractSocket::connectToHost(const QString &hostName, quint16 port,
openMode |= QAbstractSocket::Unbuffered; // QUdpSocket
QIODevice::open(openMode);
+ d->readChannelCount = d->writeChannelCount = 0;
+
d->state = HostLookupState;
emit stateChanged(d->state);
@@ -1716,11 +1732,11 @@ void QAbstractSocket::connectToHost(const QHostAddress &address, quint16 port,
*/
qint64 QAbstractSocket::bytesToWrite() const
{
- Q_D(const QAbstractSocket);
+ const qint64 pendingBytes = QIODevice::bytesToWrite();
#if defined(QABSTRACTSOCKET_DEBUG)
- qDebug("QAbstractSocket::bytesToWrite() == %lld", d->writeBuffer.size());
+ qDebug("QAbstractSocket::bytesToWrite() == %lld", pendingBytes);
#endif
- return d->writeBuffer.size();
+ return pendingBytes;
}
/*!
@@ -1859,8 +1875,8 @@ bool QAbstractSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState
Q_D(QAbstractSocket);
d->resetSocketLayer();
- d->writeBuffer.clear();
- d->buffer.clear();
+ d->setReadChannelCount(0);
+ d->setWriteChannelCount(0);
d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this);
if (!d->socketEngine) {
d->setError(UnsupportedSocketOperationError, tr("Operation on socket is not supported"));
@@ -1881,6 +1897,23 @@ bool QAbstractSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState
QIODevice::open(openMode);
+ if (socketState == ConnectedState) {
+ if (isReadable()) {
+ const int inboundStreamCount = d->socketEngine->inboundStreamCount();
+ d->setReadChannelCount(qMax(1, inboundStreamCount));
+ if (inboundStreamCount == 0)
+ d->readChannelCount = 0;
+ }
+ if (isWritable()) {
+ const int outboundStreamCount = d->socketEngine->outboundStreamCount();
+ d->setWriteChannelCount(qMax(1, outboundStreamCount));
+ if (outboundStreamCount == 0)
+ d->writeChannelCount = 0;
+ }
+ } else {
+ d->readChannelCount = d->writeChannelCount = 0;
+ }
+
if (d->state != socketState) {
d->state = socketState;
emit stateChanged(d->state);
@@ -2138,8 +2171,10 @@ bool QAbstractSocket::waitForReadyRead(int msecs)
return false;
}
- Q_ASSERT(d->socketEngine);
do {
+ if (state() != ConnectedState)
+ return false;
+
bool readyToRead = false;
bool readyToWrite = false;
if (!d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(),
@@ -2161,9 +2196,6 @@ bool QAbstractSocket::waitForReadyRead(int msecs)
if (readyToWrite)
d->canWriteNotification();
-
- if (state() != ConnectedState)
- return false;
} while (msecs == -1 || qt_subtract_from_timeout(msecs, stopWatch.elapsed()) > 0);
return false;
}
@@ -2212,8 +2244,10 @@ bool QAbstractSocket::waitForBytesWritten(int msecs)
forever {
bool readyToRead = false;
bool readyToWrite = false;
- if (!d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite, true, !d->writeBuffer.isEmpty(),
- qt_subtract_from_timeout(msecs, stopWatch.elapsed()))) {
+ if (!d->socketEngine->waitForReadOrWrite(&readyToRead, &readyToWrite,
+ !d->readBufferMaxSize || d->buffer.size() < d->readBufferMaxSize,
+ !d->writeBuffer.isEmpty(),
+ qt_subtract_from_timeout(msecs, stopWatch.elapsed()))) {
#if defined (QABSTRACTSOCKET_DEBUG)
qDebug("QAbstractSocket::waitForBytesWritten(%i) failed (%i, %s)",
msecs, d->socketEngine->error(), d->socketEngine->errorString().toLatin1().constData());
@@ -2228,8 +2262,7 @@ bool QAbstractSocket::waitForBytesWritten(int msecs)
#if defined (QABSTRACTSOCKET_DEBUG)
qDebug("QAbstractSocket::waitForBytesWritten calls canReadNotification");
#endif
- if(!d->canReadNotification())
- return false;
+ d->canReadNotification();
}
@@ -2328,7 +2361,7 @@ void QAbstractSocket::abort()
#if defined (QABSTRACTSOCKET_DEBUG)
qDebug("QAbstractSocket::abort()");
#endif
- d->writeBuffer.clear();
+ d->setWriteChannelCount(0);
if (d->state == UnconnectedState)
return;
#ifndef QT_NO_SSL
@@ -2472,8 +2505,10 @@ qint64 QAbstractSocket::writeData(const char *data, qint64 size)
qt_prettyDebug(data, qMin((int)size, 32), size).data(),
size, written);
#endif
- if (written >= 0)
+ if (written >= 0) {
emit bytesWritten(written);
+ emit channelBytesWritten(0, written);
+ }
return written;
}
@@ -2724,7 +2759,7 @@ void QAbstractSocket::disconnectFromHost()
d->peerPort = 0;
d->localAddress.clear();
d->peerAddress.clear();
- d->writeBuffer.clear();
+ d->setWriteChannelCount(0);
#if defined(QABSTRACTSOCKET_DEBUG)
qDebug("QAbstractSocket::disconnectFromHost() disconnected!");