Skip to content

Commit

Permalink
QAbstractSocket: remove redundant handling of recursive calls
Browse files Browse the repository at this point in the history
Recursion is alredy prevented by the emittedReadyRead member.
Disabling the read notifications also occurs when:

  - a new chunk of data has arrived on an unbuffered socket;
  - the buffer size limit has been reached on a buffered socket;
  - pauseSocketNotifiers() has been called

Subsequent calls to read() or resumeSocketNotifiers() should re-enable
the notifications independently from possible nesting.

Change-Id: I4587265b8d3ed137516e08fbe92dce2f5eab508c
Reviewed-by: Oswald Buddenhagen <[email protected]>
Reviewed-by: Markus Goetz (Woboq GmbH) <[email protected]>
  • Loading branch information
Alex Trotsenko committed Jan 15, 2016
1 parent e666ce1 commit 9826563
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
25 changes: 2 additions & 23 deletions src/network/socket/qabstractsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,7 @@ static bool isProxyError(QAbstractSocket::SocketError error)
Constructs a QAbstractSocketPrivate. Initializes all members.
*/
QAbstractSocketPrivate::QAbstractSocketPrivate()
: readSocketNotifierCalled(false),
readSocketNotifierState(false),
readSocketNotifierStateSet(false),
emittedReadyRead(false),
: emittedReadyRead(false),
emittedBytesWritten(false),
abortCalled(false),
pendingClose(false),
Expand Down Expand Up @@ -684,17 +681,6 @@ bool QAbstractSocketPrivate::canReadNotification()
qDebug("QAbstractSocketPrivate::canReadNotification()");
#endif

// Prevent recursive calls
if (readSocketNotifierCalled) {
if (!readSocketNotifierStateSet) {
readSocketNotifierStateSet = true;
readSocketNotifierState = socketEngine->isReadNotificationEnabled();
socketEngine->setReadNotificationEnabled(false);
}
}
QScopedValueRollback<bool> rsncrollback(readSocketNotifierCalled);
readSocketNotifierCalled = true;

if (!isBuffered)
socketEngine->setReadNotificationEnabled(false);

Expand Down Expand Up @@ -744,13 +730,6 @@ bool QAbstractSocketPrivate::canReadNotification()
if (socketEngine && isBuffered)
socketEngine->setReadNotificationEnabled(readBufferMaxSize == 0 || readBufferMaxSize > q->bytesAvailable());

// reset the read socket notifier state if we reentered inside the
// readyRead() connected slot.
if (readSocketNotifierStateSet && socketEngine &&
readSocketNotifierState != socketEngine->isReadNotificationEnabled()) {
socketEngine->setReadNotificationEnabled(readSocketNotifierState);
readSocketNotifierStateSet = false;
}
return true;
}

Expand Down Expand Up @@ -2819,7 +2798,7 @@ void QAbstractSocket::setReadBufferSize(qint64 size)
if (d->readBufferMaxSize == size)
return;
d->readBufferMaxSize = size;
if (!d->readSocketNotifierCalled && d->socketEngine) {
if (!d->emittedReadyRead && d->socketEngine) {
// ensure that the read notification is enabled if we've now got
// room in the read buffer
// but only if we're not inside canReadNotification -- that will take care on its own
Expand Down
4 changes: 0 additions & 4 deletions src/network/socket/qabstractsocket_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ class QAbstractSocketPrivate : public QIODevicePrivate, public QAbstractSocketEn
void _q_abortConnectionAttempt();
void _q_forceDisconnect();

bool readSocketNotifierCalled;
bool readSocketNotifierState;
bool readSocketNotifierStateSet;

bool emittedReadyRead;
bool emittedBytesWritten;

Expand Down

0 comments on commit 9826563

Please sign in to comment.