From b6b276495b0d02e3bcfa62b793c83f5adcf178c7 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 18 Oct 2010 16:10:15 +0200 Subject: Sockets: Private function for pausing/resuming notifiers This will be used by QNAM to prevent event loop recursion while emitting signals that often spin an event loop, e.g. authenticationRequired() displaying a dialog for the user. Reviewed-by: Peter Hartmann Reviewed-by: Prasanth Task-Number: QTBUG-13234 --- src/network/socket/qabstractsocket.cpp | 30 ++++++++++++++++++++++++++++++ src/network/socket/qabstractsocket_p.h | 7 +++++++ src/network/ssl/qsslsocket.cpp | 14 ++++++++++++++ src/network/ssl/qsslsocket_p.h | 2 ++ 4 files changed, 53 insertions(+) diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 505db71..f03d102 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -1212,6 +1212,36 @@ void QAbstractSocketPrivate::fetchConnectionParameters() #endif } + +void QAbstractSocketPrivate::pauseSocketNotifiers(QAbstractSocket *socket) +{ + QAbstractSocketEngine *socketEngine = socket->d_func()->socketEngine; + if (!socketEngine) + return; + socket->d_func()->prePauseReadSocketNotifierState = socketEngine->isReadNotificationEnabled(); + socket->d_func()->prePauseWriteSocketNotifierState = socketEngine->isWriteNotificationEnabled(); + socket->d_func()->prePauseExceptionSocketNotifierState = socketEngine->isExceptionNotificationEnabled(); + socketEngine->setReadNotificationEnabled(false); + socketEngine->setWriteNotificationEnabled(false); + socketEngine->setExceptionNotificationEnabled(false); +} + +void QAbstractSocketPrivate::resumeSocketNotifiers(QAbstractSocket *socket) +{ + QAbstractSocketEngine *socketEngine = socket->d_func()->socketEngine; + if (!socketEngine) + return; + socketEngine->setReadNotificationEnabled(socket->d_func()->prePauseReadSocketNotifierState); + socketEngine->setWriteNotificationEnabled(socket->d_func()->prePauseWriteSocketNotifierState); + socketEngine->setExceptionNotificationEnabled(socket->d_func()->prePauseExceptionSocketNotifierState); +} + +QAbstractSocketEngine* QAbstractSocketPrivate::getSocketEngine(QAbstractSocket *socket) +{ + return socket->d_func()->socketEngine; +} + + /*! \internal Constructs a new abstract socket of type \a socketType. The \a diff --git a/src/network/socket/qabstractsocket_p.h b/src/network/socket/qabstractsocket_p.h index b51c301..7fba0fe 100644 --- a/src/network/socket/qabstractsocket_p.h +++ b/src/network/socket/qabstractsocket_p.h @@ -158,6 +158,13 @@ public: QAbstractSocket::SocketState state; QAbstractSocket::SocketError socketError; + + bool prePauseReadSocketNotifierState; + bool prePauseWriteSocketNotifierState; + bool prePauseExceptionSocketNotifierState; + static void pauseSocketNotifiers(QAbstractSocket*); + static void resumeSocketNotifiers(QAbstractSocket*); + static QAbstractSocketEngine* getSocketEngine(QAbstractSocket*); }; QT_END_NAMESPACE diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp index c9f421f..a752720 100644 --- a/src/network/ssl/qsslsocket.cpp +++ b/src/network/ssl/qsslsocket.cpp @@ -2035,6 +2035,20 @@ void QSslSocketPrivate::createPlainSocket(QIODevice::OpenMode openMode) q->setReadBufferSize(readBufferMaxSize); } +void QSslSocketPrivate::pauseSocketNotifiers(QSslSocket *socket) +{ + if (!socket->d_func()->plainSocket) + return; + QAbstractSocketPrivate::pauseSocketNotifiers(socket->d_func()->plainSocket); +} + +void QSslSocketPrivate::resumeSocketNotifiers(QSslSocket *socket) +{ + if (!socket->d_func()->plainSocket) + return; + QAbstractSocketPrivate::resumeSocketNotifiers(socket->d_func()->plainSocket); +} + /*! \internal */ diff --git a/src/network/ssl/qsslsocket_p.h b/src/network/ssl/qsslsocket_p.h index 72b3ef7..94f5f39 100644 --- a/src/network/ssl/qsslsocket_p.h +++ b/src/network/ssl/qsslsocket_p.h @@ -142,6 +142,8 @@ public: // The socket itself, including private slots. QTcpSocket *plainSocket; void createPlainSocket(QIODevice::OpenMode openMode); + static void pauseSocketNotifiers(QSslSocket*); + static void resumeSocketNotifiers(QSslSocket*); void _q_connectedSlot(); void _q_hostFoundSlot(); void _q_disconnectedSlot(); -- cgit v0.12