diff options
Diffstat (limited to 'src/network/socket')
-rw-r--r-- | src/network/socket/qabstractsocket.cpp | 34 | ||||
-rw-r--r-- | src/network/socket/qabstractsocket.h | 2 | ||||
-rw-r--r-- | src/network/socket/qabstractsocket_p.h | 3 | ||||
-rw-r--r-- | src/network/socket/qabstractsocketengine_p.h | 2 | ||||
-rw-r--r-- | src/network/socket/qhttpsocketengine.cpp | 8 | ||||
-rw-r--r-- | src/network/socket/qhttpsocketengine_p.h | 2 | ||||
-rw-r--r-- | src/network/socket/qlocalserver.cpp | 6 | ||||
-rw-r--r-- | src/network/socket/qlocalsocket_win.cpp | 4 | ||||
-rw-r--r-- | src/network/socket/qnativesocketengine.cpp | 8 | ||||
-rw-r--r-- | src/network/socket/qnativesocketengine_p.h | 2 | ||||
-rw-r--r-- | src/network/socket/qnativesocketengine_win.cpp | 26 | ||||
-rw-r--r-- | src/network/socket/qnativesocketengine_winrt_p.h | 2 | ||||
-rw-r--r-- | src/network/socket/qsocks5socketengine.cpp | 10 | ||||
-rw-r--r-- | src/network/socket/qsocks5socketengine_p.h | 2 | ||||
-rw-r--r-- | src/network/socket/qtcpserver.cpp | 4 |
15 files changed, 70 insertions, 45 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index e86793cb21..9c8f29e18a 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -914,7 +914,7 @@ void QAbstractSocketPrivate::resolveProxy(const QString &hostname, quint16 port) proxies << proxy; } else { // try the application settings instead - QNetworkProxyQuery query(hostname, port, QString(), + QNetworkProxyQuery query(hostname, port, protocolTag, socketType == QAbstractSocket::TcpSocket ? QNetworkProxyQuery::TcpSocket : socketType == QAbstractSocket::SctpSocket ? @@ -2959,6 +2959,38 @@ QNetworkProxy QAbstractSocket::proxy() const Q_D(const QAbstractSocket); return d->proxy; } + +/*! + \since 5.13 + + Returns the protocol tag for this socket. + If the protocol tag is set then this is passed to QNetworkProxyQuery + when this is created internally to indicate the protocol tag to be + used. + + \sa setProtocolTag(), QNetworkProxyQuery +*/ + +QString QAbstractSocket::protocolTag() const +{ + Q_D(const QAbstractSocket); + return d->protocolTag; +} + +/*! + \since 5.13 + + Sets the protocol tag for this socket to \a tag. + + \sa protocolTag() +*/ + +void QAbstractSocket::setProtocolTag(const QString &tag) +{ + Q_D(QAbstractSocket); + d->protocolTag = tag; +} + #endif // QT_NO_NETWORKPROXY #ifndef QT_NO_DEBUG_STREAM diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h index 6d5e57ac52..de09195eeb 100644 --- a/src/network/socket/qabstractsocket.h +++ b/src/network/socket/qabstractsocket.h @@ -197,6 +197,8 @@ public: #ifndef QT_NO_NETWORKPROXY void setProxy(const QNetworkProxy &networkProxy); QNetworkProxy proxy() const; + QString protocolTag() const; + void setProtocolTag(const QString &tag); #endif Q_SIGNALS: diff --git a/src/network/socket/qabstractsocket_p.h b/src/network/socket/qabstractsocket_p.h index 066a35ff85..5aa69d747e 100644 --- a/src/network/socket/qabstractsocket_p.h +++ b/src/network/socket/qabstractsocket_p.h @@ -83,7 +83,7 @@ public: #ifndef QT_NO_NETWORKPROXY inline void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) override { Q_Q(QAbstractSocket); - q->proxyAuthenticationRequired(proxy, authenticator); + emit q->proxyAuthenticationRequired(proxy, authenticator); } #endif @@ -124,6 +124,7 @@ public: #ifndef QT_NO_NETWORKPROXY QNetworkProxy proxy; QNetworkProxy proxyInUse; + QString protocolTag; void resolveProxy(const QString &hostName, quint16 port); #else inline void resolveProxy(const QString &, quint16) { } diff --git a/src/network/socket/qabstractsocketengine_p.h b/src/network/socket/qabstractsocketengine_p.h index b15dd73c96..8eebb06a4d 100644 --- a/src/network/socket/qabstractsocketengine_p.h +++ b/src/network/socket/qabstractsocketengine_p.h @@ -215,7 +215,7 @@ protected: private: Q_DECLARE_PRIVATE(QAbstractSocketEngine) - Q_DISABLE_COPY(QAbstractSocketEngine) + Q_DISABLE_COPY_MOVE(QAbstractSocketEngine) }; class QAbstractSocketEnginePrivate : public QObjectPrivate diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp index 4cfc8e3555..bfde3870c4 100644 --- a/src/network/socket/qhttpsocketengine.cpp +++ b/src/network/socket/qhttpsocketengine.cpp @@ -649,7 +649,7 @@ void QHttpSocketEngine::slotSocketReadNotification() } if (priv->phase == QAuthenticatorPrivate::Done) - emit proxyAuthenticationRequired(d->proxy, &d->authenticator); + proxyAuthenticationRequired(d->proxy, &d->authenticator); // priv->phase will get reset to QAuthenticatorPrivate::Start if the authenticator got modified in the signal above. if (priv->phase == QAuthenticatorPrivate::Done) { setError(QAbstractSocket::ProxyAuthenticationRequiredError, tr("Authentication required")); @@ -771,7 +771,7 @@ void QHttpSocketEngine::emitPendingReadNotification() Q_D(QHttpSocketEngine); d->readNotificationPending = false; if (d->readNotificationEnabled) - emit readNotification(); + readNotification(); } void QHttpSocketEngine::emitPendingWriteNotification() @@ -779,14 +779,14 @@ void QHttpSocketEngine::emitPendingWriteNotification() Q_D(QHttpSocketEngine); d->writeNotificationPending = false; if (d->writeNotificationEnabled) - emit writeNotification(); + writeNotification(); } void QHttpSocketEngine::emitPendingConnectionNotification() { Q_D(QHttpSocketEngine); d->connectionNotificationPending = false; - emit connectionNotification(); + connectionNotification(); } void QHttpSocketEngine::emitReadNotification() diff --git a/src/network/socket/qhttpsocketengine_p.h b/src/network/socket/qhttpsocketengine_p.h index cb7798694a..bbcc09eee9 100644 --- a/src/network/socket/qhttpsocketengine_p.h +++ b/src/network/socket/qhttpsocketengine_p.h @@ -160,7 +160,7 @@ private: bool readHttpHeader(); Q_DECLARE_PRIVATE(QHttpSocketEngine) - Q_DISABLE_COPY(QHttpSocketEngine) + Q_DISABLE_COPY_MOVE(QHttpSocketEngine) }; diff --git a/src/network/socket/qlocalserver.cpp b/src/network/socket/qlocalserver.cpp index a9789b7d04..3e36a7b229 100644 --- a/src/network/socket/qlocalserver.cpp +++ b/src/network/socket/qlocalserver.cpp @@ -408,7 +408,7 @@ int QLocalServer::maxPendingConnections() const still a good idea to delete the object explicitly when you are done with it, to avoid wasting memory. - 0 is returned if this function is called when there are no pending + \nullptr is returned if this function is called when there are no pending connections. \sa hasPendingConnections(), newConnection(), incomingConnection() @@ -506,8 +506,8 @@ void QLocalServer::setMaxPendingConnections(int numConnections) /*! Waits for at most \a msec milliseconds or until an incoming connection is available. Returns \c true if a connection is available; otherwise - returns \c false. If the operation timed out and \a timedOut is not 0, - *timedOut will be set to true. + returns \c false. If the operation timed out and \a timedOut is not + \nullptr, *timedOut will be set to true. This is a blocking function call. Its use is ill-advised in a single-threaded GUI application, since the whole application will stop diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index d6ee76043f..4decbd5ded 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -87,9 +87,9 @@ void QLocalSocketPrivate::_q_winError(ulong windowsError, const QString &functio } if (currentState != state) { - q->emit stateChanged(state); + emit q->stateChanged(state); if (state == QLocalSocket::UnconnectedState && currentState != QLocalSocket::ConnectingState) - q->emit disconnected(); + emit q->disconnected(); } emit q->error(error); } diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp index 8947a7ee8a..5126a5330f 100644 --- a/src/network/socket/qnativesocketengine.cpp +++ b/src/network/socket/qnativesocketengine.cpp @@ -999,8 +999,8 @@ void QNativeSocketEngine::close() /*! Waits for \a msecs milliseconds or until the socket is ready for - reading. If \a timedOut is not 0 and \a msecs milliseconds have - passed, the value of \a timedOut is set to true. + reading. If \a timedOut is not \nullptr and \a msecs milliseconds + have passed, the value of \a timedOut is set to true. Returns \c true if data is available for reading; otherwise returns false. @@ -1039,8 +1039,8 @@ bool QNativeSocketEngine::waitForRead(int msecs, bool *timedOut) /*! Waits for \a msecs milliseconds or until the socket is ready for - writing. If \a timedOut is not 0 and \a msecs milliseconds have - passed, the value of \a timedOut is set to true. + writing. If \a timedOut is not \nullptr and \a msecs milliseconds + have passed, the value of \a timedOut is set to true. Returns \c true if data is available for writing; otherwise returns false. diff --git a/src/network/socket/qnativesocketengine_p.h b/src/network/socket/qnativesocketengine_p.h index aa61b74823..2292566265 100644 --- a/src/network/socket/qnativesocketengine_p.h +++ b/src/network/socket/qnativesocketengine_p.h @@ -196,7 +196,7 @@ public Q_SLOTS: private: Q_DECLARE_PRIVATE(QNativeSocketEngine) - Q_DISABLE_COPY(QNativeSocketEngine) + Q_DISABLE_COPY_MOVE(QNativeSocketEngine) }; class QSocketNotifier; diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index 897f9e24bb..9edabd7822 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -1141,22 +1141,17 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const qint64 ret = -1; int recvResult = 0; DWORD flags; - DWORD bufferCount = 5; - WSABUF * buf = 0; + // We start at 1500 bytes (the MTU for Ethernet V2), which should catch + // almost all uses (effective MTU for UDP under IPv4 is 1468), except + // for localhost datagrams and those reassembled by the IP layer. + char udpMessagePeekBuffer[1500]; + std::vector<WSABUF> buf; for (;;) { - // We start at 1500 bytes (the MTU for Ethernet V2), which should catch - // almost all uses (effective MTU for UDP under IPv4 is 1468), except - // for localhost datagrams and those reassembled by the IP layer. - char udpMessagePeekBuffer[1500]; - - buf = new WSABUF[bufferCount]; - for (DWORD i=0; i<bufferCount; i++) { - buf[i].buf = udpMessagePeekBuffer; - buf[i].len = sizeof(udpMessagePeekBuffer); - } + buf.resize(buf.size() + 5, {sizeof(udpMessagePeekBuffer), udpMessagePeekBuffer}); + flags = MSG_PEEK; DWORD bytesRead = 0; - recvResult = ::WSARecv(socketDescriptor, buf, bufferCount, &bytesRead, &flags, 0,0); + recvResult = ::WSARecv(socketDescriptor, buf.data(), DWORD(buf.size()), &bytesRead, &flags, nullptr, nullptr); int err = WSAGetLastError(); if (recvResult != SOCKET_ERROR) { ret = qint64(bytesRead); @@ -1164,8 +1159,6 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const } else { switch (err) { case WSAEMSGSIZE: - bufferCount += 5; - delete[] buf; continue; case WSAECONNRESET: case WSAENETRESET: @@ -1180,9 +1173,6 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const } } - if (buf) - delete[] buf; - #if defined (QNATIVESOCKETENGINE_DEBUG) qDebug("QNativeSocketEnginePrivate::nativePendingDatagramSize() == %lli", ret); #endif diff --git a/src/network/socket/qnativesocketengine_winrt_p.h b/src/network/socket/qnativesocketengine_winrt_p.h index 6688bfe35c..e1fe58bb97 100644 --- a/src/network/socket/qnativesocketengine_winrt_p.h +++ b/src/network/socket/qnativesocketengine_winrt_p.h @@ -188,7 +188,7 @@ private slots: private: Q_DECLARE_PRIVATE(QNativeSocketEngine) - Q_DISABLE_COPY(QNativeSocketEngine) + Q_DISABLE_COPY_MOVE(QNativeSocketEngine) }; class QNativeSocketEnginePrivate : public QAbstractSocketEnginePrivate diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp index e7e4d64c32..18b3ce9db2 100644 --- a/src/network/socket/qsocks5socketengine.cpp +++ b/src/network/socket/qsocks5socketengine.cpp @@ -372,7 +372,7 @@ QSocks5BindData *QSocks5BindStore::retrieve(qintptr socketDescriptor) store.erase(it); if (bindData) { if (bindData->controlSocket->thread() != QThread::currentThread()) { - qWarning("Can not access socks5 bind data from different thread"); + qWarning("Cannot access socks5 bind data from different thread"); return 0; } } else { @@ -706,7 +706,7 @@ void QSocks5SocketEnginePrivate::reauthenticate() // we require authentication QAuthenticator auth; - emit q->proxyAuthenticationRequired(proxyInfo, &auth); + q->proxyAuthenticationRequired(proxyInfo, &auth); if (!auth.user().isEmpty() || !auth.password().isEmpty()) { // we have new credentials, let's try again @@ -915,7 +915,7 @@ void QSocks5SocketEnginePrivate::_q_emitPendingReadNotification() if (readNotificationEnabled) { QSOCKS5_D_DEBUG << "emitting readNotification"; QPointer<QSocks5SocketEngine> qq = q; - emit q->readNotification(); + q->readNotification(); if (!qq) return; // check if there needs to be a new zero read notification @@ -944,7 +944,7 @@ void QSocks5SocketEnginePrivate::_q_emitPendingWriteNotification() Q_Q(QSocks5SocketEngine); if (writeNotificationEnabled) { QSOCKS5_D_DEBUG << "emitting writeNotification"; - emit q->writeNotification(); + q->writeNotification(); } } @@ -964,7 +964,7 @@ void QSocks5SocketEnginePrivate::_q_emitPendingConnectionNotification() connectionNotificationPending = false; Q_Q(QSocks5SocketEngine); QSOCKS5_D_DEBUG << "emitting connectionNotification"; - emit q->connectionNotification(); + q->connectionNotification(); } void QSocks5SocketEnginePrivate::emitConnectionNotification() diff --git a/src/network/socket/qsocks5socketengine_p.h b/src/network/socket/qsocks5socketengine_p.h index 1942eff4ca..ef9d771753 100644 --- a/src/network/socket/qsocks5socketengine_p.h +++ b/src/network/socket/qsocks5socketengine_p.h @@ -127,7 +127,7 @@ public: private: Q_DECLARE_PRIVATE(QSocks5SocketEngine) - Q_DISABLE_COPY(QSocks5SocketEngine) + Q_DISABLE_COPY_MOVE(QSocks5SocketEngine) Q_PRIVATE_SLOT(d_func(), void _q_controlSocketConnected()) Q_PRIVATE_SLOT(d_func(), void _q_controlSocketReadNotification()) Q_PRIVATE_SLOT(d_func(), void _q_controlSocketError(QAbstractSocket::SocketError)) diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp index eddf789921..98e58192a2 100644 --- a/src/network/socket/qtcpserver.cpp +++ b/src/network/socket/qtcpserver.cpp @@ -493,7 +493,7 @@ QHostAddress QTcpServer::serverAddress() const Waits for at most \a msec milliseconds or until an incoming connection is available. Returns \c true if a connection is available; otherwise returns \c false. If the operation timed out - and \a timedOut is not 0, *\a timedOut will be set to true. + and \a timedOut is not \nullptr, *\a timedOut will be set to true. This is a blocking function call. Its use is disadvised in a single-threaded GUI application, since the whole application will @@ -548,7 +548,7 @@ bool QTcpServer::hasPendingConnections() const destroyed. It is still a good idea to delete the object explicitly when you are done with it, to avoid wasting memory. - 0 is returned if this function is called when there are no pending + \nullptr is returned if this function is called when there are no pending connections. \note The returned QTcpSocket object cannot be used from another |