OSDN Git Service

remove unused socket exception notification
authorIvailo Monev <xakepa10@gmail.com>
Tue, 27 Dec 2022 19:41:19 +0000 (21:41 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 27 Dec 2022 19:41:19 +0000 (21:41 +0200)
doubles as performance optimization for sockets (QTcpServer and QUdpSocket)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/network/socket/qabstractsocket_p.h
src/network/socket/qabstractsocketengine.cpp
src/network/socket/qabstractsocketengine_p.h
src/network/socket/qtcpserver.cpp

index d4b4c2c..d45ffd3 100644 (file)
@@ -55,7 +55,6 @@ public:
     // from QAbstractSocketEngineReceiver
     inline void readNotification() { canReadNotification(); }
     inline void writeNotification() { canWriteNotification(); }
-    inline void exceptionNotification() {}
     void connectionNotification();
 
     bool canReadNotification();
index 754d6c2..32fed9c 100644 (file)
@@ -126,30 +126,6 @@ bool QWriteNotifier::event(QEvent *e)
     return QSocketNotifier::event(e);
 }
 
-class QExceptionNotifier : public QSocketNotifier
-{
-public:
-    QExceptionNotifier(int fd, QAbstractSocketEngine *parent)
-        : QSocketNotifier(fd, QSocketNotifier::Exception, parent) { engine = parent; }
-
-protected:
-    bool event(QEvent *);
-
-    QAbstractSocketEngine *engine;
-};
-
-bool QExceptionNotifier::event(QEvent *e)
-{
-    if (e->type() == QEvent::SockAct) {
-        if (engine->state() == QAbstractSocket::ConnectingState)
-            engine->connectionNotification();
-        else
-            engine->exceptionNotification();
-        return true;
-    }
-    return QSocketNotifier::event(e);
-}
-
 /*! \internal
     Constructs the private class and initializes all data members.
 */
@@ -157,7 +133,6 @@ QAbstractSocketEnginePrivate::QAbstractSocketEnginePrivate()
     : socketDescriptor(-1)
     , readNotifier(0)
     , writeNotifier(0)
-    , exceptNotifier(0)
     , socketError(QAbstractSocket::UnknownSocketError)
     , hasSetSocketError(false)
     , socketErrorString(QLatin1String(QT_TRANSLATE_NOOP(QSocketLayer, "Unknown error")))
@@ -236,12 +211,6 @@ void QAbstractSocketEngine::writeNotification()
         receiver->writeNotification();
 }
 
-void QAbstractSocketEngine::exceptionNotification()
-{
-    if (QAbstractSocketEngineReceiver *receiver = d_func()->receiver)
-        receiver->exceptionNotification();
-}
-
 /*!
     If there's a connection activity on the socket, process it. Then
     notify our parent if there really was activity.
@@ -903,8 +872,6 @@ void QAbstractSocketEngine::close()
         d->readNotifier->setEnabled(false);
     if (d->writeNotifier)
         d->writeNotifier->setEnabled(false);
-    if (d->exceptNotifier)
-        d->exceptNotifier->setEnabled(false);
 
     if(d->socketDescriptor != -1) {
         d->nativeClose();
@@ -924,10 +891,6 @@ void QAbstractSocketEngine::close()
         delete d->writeNotifier;
         d->writeNotifier = 0;
     }
-    if (d->exceptNotifier) {
-        delete d->exceptNotifier;
-        d->exceptNotifier = 0;
-    }
 }
 
 /*!
@@ -1077,23 +1040,6 @@ void QAbstractSocketEngine::setWriteNotificationEnabled(bool enable)
     }
 }
 
-bool QAbstractSocketEngine::isExceptionNotificationEnabled() const
-{
-    Q_D(const QAbstractSocketEngine);
-    return d->exceptNotifier && d->exceptNotifier->isEnabled();
-}
-
-void QAbstractSocketEngine::setExceptionNotificationEnabled(bool enable)
-{
-    Q_D(QAbstractSocketEngine);
-    if (d->exceptNotifier) {
-        d->exceptNotifier->setEnabled(enable);
-    } else if (enable && d->threadData->eventDispatcher) {
-        d->exceptNotifier = new QExceptionNotifier(d->socketDescriptor, this);
-        d->exceptNotifier->setEnabled(true);
-    }
-}
-
 QT_END_NAMESPACE
 
 #include "moc_qabstractsocketengine_p.h"
index 9959ccc..83cee73 100644 (file)
@@ -47,11 +47,10 @@ class QSocketNotifier;
 
 class QAbstractSocketEngineReceiver {
 public:
-    virtual ~QAbstractSocketEngineReceiver(){}
-    virtual void readNotification()= 0;
-    virtual void writeNotification()= 0;
-    virtual void exceptionNotification()= 0;
-    virtual void connectionNotification()= 0;
+    virtual ~QAbstractSocketEngineReceiver() {}
+    virtual void readNotification() = 0;
+    virtual void writeNotification() = 0;
+    virtual void connectionNotification() = 0;
 };
 
 class Q_AUTOTEST_EXPORT QAbstractSocketEngine : public QObject
@@ -136,13 +135,10 @@ public:
     void setReadNotificationEnabled(bool enable);
     bool isWriteNotificationEnabled() const;
     void setWriteNotificationEnabled(bool enable);
-    bool isExceptionNotificationEnabled() const;
-    void setExceptionNotificationEnabled(bool enable);
 
 public Q_SLOTS:
     void readNotification();
     void writeNotification();
-    void exceptionNotification();
     void connectionNotification();
 
 public:
@@ -239,7 +235,7 @@ public:
     bool fetchConnectionParameters();
 
     int socketDescriptor;
-    QSocketNotifier *readNotifier, *writeNotifier, *exceptNotifier;
+    QSocketNotifier *readNotifier, *writeNotifier;
     QAbstractSocket::SocketError socketError;
     bool hasSetSocketError;
     QString socketErrorString;
index 4d365b4..f19dad5 100644 (file)
@@ -109,7 +109,6 @@ public:
     // from QAbstractSocketEngineReceiver
     void readNotification();
     inline void writeNotification() {}
-    inline void exceptionNotification() {}
     inline void connectionNotification() {}
 };
 
@@ -372,8 +371,9 @@ QHostAddress QTcpServer::serverAddress() const
 bool QTcpServer::waitForNewConnection(int msec, bool *timedOut)
 {
     Q_D(QTcpServer);
-    if (!isListening())
+    if (!isListening()) {
         return false;
+    }
 
     if (!d->socketEngine->waitForRead(msec, timedOut)) {
         return false;