diff options
author | Joerg Bornemann <joerg.bornemann@nokia.com> | 2011-12-13 12:09:45 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-15 19:17:04 +0100 |
commit | 3ccd6264296a3d5b1652964c758cbd1063c8c8f2 (patch) | |
tree | 6d5b8f07fc56ca49cf56e55fb0f382b0fe37b3f5 /src/network/socket/qlocalsocket_win.cpp | |
parent | abccefa4a8fffda13d3873b8e0c60259d75a75e9 (diff) |
QLocalSocket/Win: make emitReadyRead timer persistent
This saves us from creating a single shot timer every time we emit
readyRead and eliminates the parallel pendingReadyRead flag.
Done-with: ossi
Change-Id: I1de7f07b83b583b9d60dd8862d6a9f7865b5b891
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Diffstat (limited to 'src/network/socket/qlocalsocket_win.cpp')
-rw-r--r-- | src/network/socket/qlocalsocket_win.cpp | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index 5d64479106..cb4d50d658 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -50,6 +50,9 @@ QT_BEGIN_NAMESPACE void QLocalSocketPrivate::init() { Q_Q(QLocalSocket); + emitReadyReadTimer = new QTimer(q); + emitReadyReadTimer->setSingleShot(true); + QObject::connect(emitReadyReadTimer, SIGNAL(timeout()), q, SIGNAL(readyRead())); memset(&overlapped, 0, sizeof(overlapped)); overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); dataReadNotifier = new QWinEventNotifier(overlapped.hEvent, q); @@ -108,7 +111,7 @@ QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(), actualReadBufferSize(0), error(QLocalSocket::UnknownSocketError), readSequenceStarted(false), - pendingReadyRead(false), + emitReadyReadTimer(0), pipeClosed(false), state(QLocalSocket::UnconnectedState) { @@ -236,13 +239,10 @@ qint64 QLocalSocket::readData(char *data, qint64 maxSize) void QLocalSocketPrivate::checkReadyRead() { if (actualReadBufferSize > 0) { - if (!pendingReadyRead) { - Q_Q(QLocalSocket); - QTimer::singleShot(0, q, SLOT(_q_emitReadyRead())); - pendingReadyRead = true; - } + if (!emitReadyReadTimer->isActive()) + emitReadyReadTimer->start(); } else { - pendingReadyRead = false; + emitReadyReadTimer->stop(); } } @@ -516,19 +516,10 @@ void QLocalSocketPrivate::_q_notified() return; } startAsyncRead(); - pendingReadyRead = false; + emitReadyReadTimer->stop(); emit q->readyRead(); } -void QLocalSocketPrivate::_q_emitReadyRead() -{ - if (pendingReadyRead) { - Q_Q(QLocalSocket); - pendingReadyRead = false; - emit q->readyRead(); - } -} - quintptr QLocalSocket::socketDescriptor() const { Q_D(const QLocalSocket); |