summaryrefslogtreecommitdiffstats
path: root/src/network/socket
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/socket')
-rw-r--r--src/network/socket/qabstractsocket.cpp77
-rw-r--r--src/network/socket/qabstractsocket.h7
-rw-r--r--src/network/socket/qabstractsocketengine.cpp6
-rw-r--r--src/network/socket/qhttpsocketengine.cpp31
-rw-r--r--src/network/socket/qlocalserver.cpp2
-rw-r--r--src/network/socket/qlocalserver_unix.cpp2
-rw-r--r--src/network/socket/qlocalsocket.cpp19
-rw-r--r--src/network/socket/qlocalsocket.h4
-rw-r--r--src/network/socket/qlocalsocket_p.h4
-rw-r--r--src/network/socket/qlocalsocket_tcp.cpp16
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp49
-rw-r--r--src/network/socket/qlocalsocket_win.cpp6
-rw-r--r--src/network/socket/qnativesocketengine.cpp18
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp6
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp15
-rw-r--r--src/network/socket/qsocks5socketengine.cpp54
-rw-r--r--src/network/socket/qtcpserver.cpp10
-rw-r--r--src/network/socket/qudpsocket.cpp2
18 files changed, 182 insertions, 146 deletions
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index b1ea9a4133..3d88c0337d 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -215,7 +215,7 @@
connections, you will have to register it with Q_DECLARE_METATYPE() and
qRegisterMetaType().
- \sa error(), errorString(), {Creating Custom Qt Types}
+ \sa socketError(), errorString(), {Creating Custom Qt Types}
*/
/*!
@@ -329,7 +329,7 @@
is non-blocking).
\value UnknownSocketError An unidentified error occurred.
- \sa QAbstractSocket::error()
+ \sa QAbstractSocket::socketError()
*/
/*!
@@ -464,7 +464,10 @@
#include "qabstractsocket_p.h"
#include "private/qhostinfo_p.h"
+#if QT_CONFIG(bearermanagement) // ### Qt6: Remove section
#include "private/qnetworksession_p.h"
+#endif
+#include "private/qnetworkconfiguration_p.h" // ### Qt6: Remove include
#include <qabstracteventdispatcher.h>
#include <qhostaddress.h>
@@ -564,12 +567,12 @@ QAbstractSocketPrivate::QAbstractSocketPrivate()
port(0),
localPort(0),
peerPort(0),
- socketEngine(0),
+ socketEngine(nullptr),
cachedSocketDescriptor(-1),
readBufferMaxSize(0),
isBuffered(false),
hasPendingData(false),
- connectTimer(0),
+ connectTimer(nullptr),
hostLookupId(-1),
socketType(QAbstractSocket::UnknownSocketType),
state(QAbstractSocket::UnconnectedState),
@@ -603,7 +606,7 @@ void QAbstractSocketPrivate::resetSocketLayer()
socketEngine->close();
socketEngine->disconnect();
delete socketEngine;
- socketEngine = 0;
+ socketEngine = nullptr;
cachedSocketDescriptor = -1;
}
if (connectTimer)
@@ -643,7 +646,7 @@ bool QAbstractSocketPrivate::initSocketLayer(QAbstractSocket::NetworkLayerProtoc
QAbstractSocket::tr("Operation on socket is not supported"));
return false;
}
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
//copy network session down to the socket engine (if it has been set)
socketEngine->setProperty("_q_networksession", q->property("_q_networksession"));
#endif
@@ -659,7 +662,7 @@ bool QAbstractSocketPrivate::initSocketLayer(QAbstractSocket::NetworkLayerProtoc
configureCreatedSocket();
- if (threadData->hasEventDispatcher())
+ if (threadData.loadRelaxed()->hasEventDispatcher())
socketEngine->setReceiver(this);
#if defined (QABSTRACTSOCKET_DEBUG)
@@ -1138,7 +1141,7 @@ void QAbstractSocketPrivate::_q_connectToNextAddress()
}
// Start the connect timer.
- if (threadData->hasEventDispatcher()) {
+ if (threadData.loadRelaxed()->hasEventDispatcher()) {
if (!connectTimer) {
connectTimer = new QTimer(q);
QObject::connect(connectTimer, SIGNAL(timeout()),
@@ -1146,7 +1149,7 @@ void QAbstractSocketPrivate::_q_connectToNextAddress()
Qt::DirectConnection);
}
int connectTimeout = QNetworkConfigurationPrivate::DefaultTimeout;
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
QSharedPointer<QNetworkSession> networkSession = qvariant_cast< QSharedPointer<QNetworkSession> >(q->property("_q_networksession"));
if (networkSession) {
QNetworkConfiguration networkConfiguration = networkSession->configuration();
@@ -1740,7 +1743,7 @@ void QAbstractSocket::connectToHost(const QString &hostName, quint16 port,
return;
#endif
} else {
- if (d->threadData->hasEventDispatcher()) {
+ if (d->threadData.loadRelaxed()->hasEventDispatcher()) {
// this internal API for QHostInfo either immediately gives us the desired
// QHostInfo from cache or later calls the _q_startConnecting slot.
bool immediateResultValid = false;
@@ -1941,7 +1944,7 @@ bool QAbstractSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState
d->setError(UnsupportedSocketOperationError, tr("Operation on socket is not supported"));
return false;
}
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
//copy network session down to the socket engine (if it has been set)
d->socketEngine->setProperty("_q_networksession", property("_q_networksession"));
#endif
@@ -1953,7 +1956,7 @@ bool QAbstractSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState
// Sync up with error string, which open() shall clear.
d->socketError = UnknownSocketError;
- if (d->threadData->hasEventDispatcher())
+ if (d->threadData.loadRelaxed()->hasEventDispatcher())
d->socketEngine->setReceiver(d);
QIODevice::open(openMode);
@@ -2094,7 +2097,7 @@ QVariant QAbstractSocket::socketOption(QAbstractSocket::SocketOption option)
Waits until the socket is connected, up to \a msecs
milliseconds. If the connection has been established, this
function returns \c true; otherwise it returns \c false. In the case
- where it returns \c false, you can call error() to determine
+ where it returns \c false, you can call socketError() to determine
the cause of the error.
The following example waits up to one second for a connection
@@ -2134,7 +2137,7 @@ bool QAbstractSocket::waitForConnected(int msecs)
QElapsedTimer stopWatch;
stopWatch.start();
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
QSharedPointer<QNetworkSession> networkSession = qvariant_cast< QSharedPointer<QNetworkSession> >(property("_q_networksession"));
#endif
@@ -2144,27 +2147,20 @@ bool QAbstractSocket::waitForConnected(int msecs)
#endif
QHostInfo::abortHostLookup(d->hostLookupId);
d->hostLookupId = -1;
-#ifndef QT_NO_BEARERMANAGEMENT
- if (networkSession) {
- d->_q_startConnecting(QHostInfoPrivate::fromName(d->hostName, networkSession));
- } else
-#endif
- {
- QHostAddress temp;
- if (temp.setAddress(d->hostName)) {
- QHostInfo info;
- info.setAddresses(QList<QHostAddress>() << temp);
- d->_q_startConnecting(info);
- } else {
- d->_q_startConnecting(QHostInfo::fromName(d->hostName));
- }
+ QHostAddress temp;
+ if (temp.setAddress(d->hostName)) {
+ QHostInfo info;
+ info.setAddresses(QList<QHostAddress>() << temp);
+ d->_q_startConnecting(info);
+ } else {
+ d->_q_startConnecting(QHostInfo::fromName(d->hostName));
}
}
if (state() == UnconnectedState)
return false; // connect not im progress anymore!
int connectTimeout = QNetworkConfigurationPrivate::DefaultTimeout;
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
if (networkSession) {
QNetworkConfiguration networkConfiguration = networkSession->configuration();
connectTimeout = networkConfiguration.connectTimeout();
@@ -2873,7 +2869,7 @@ void QAbstractSocket::setReadBufferSize(qint64 size)
/*!
Returns the state of the socket.
- \sa error()
+ \sa socketError()
*/
QAbstractSocket::SocketState QAbstractSocket::state() const
{
@@ -2900,16 +2896,35 @@ QAbstractSocket::SocketType QAbstractSocket::socketType() const
return d_func()->socketType;
}
+#if QT_DEPRECATED_SINCE(5, 15)
/*!
+ \deprecated
+
+ Use socketError() instead.
+
Returns the type of error that last occurred.
- \sa state(), errorString()
+ \sa state(), errorString(), socketError()
*/
QAbstractSocket::SocketError QAbstractSocket::error() const
{
+ return socketError();
+}
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+/*!
+ \since 5.15
+
+ Returns the type of error that last occurred.
+
+ \sa state(), errorString()
+*/
+QAbstractSocket::SocketError QAbstractSocket::socketError() const
+{
return d_func()->socketError;
}
+
/*!
Sets the type of error that last occurred to \a socketError.
diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h
index de09195eeb..cbc79ea684 100644
--- a/src/network/socket/qabstractsocket.h
+++ b/src/network/socket/qabstractsocket.h
@@ -180,7 +180,12 @@ public:
SocketType socketType() const;
SocketState state() const;
- SocketError error() const;
+
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_X("Use socketError()") SocketError error() const;
+#endif // QT_DEPRECATED_SINCE(5, 15)
+
+ SocketError socketError() const;
// from QIODevice
void close() override;
diff --git a/src/network/socket/qabstractsocketengine.cpp b/src/network/socket/qabstractsocketengine.cpp
index 3fffff6d5a..54c7452c66 100644
--- a/src/network/socket/qabstractsocketengine.cpp
+++ b/src/network/socket/qabstractsocketengine.cpp
@@ -85,7 +85,7 @@ QAbstractSocketEnginePrivate::QAbstractSocketEnginePrivate()
, peerPort(0)
, inboundStreamCount(0)
, outboundStreamCount(0)
- , receiver(0)
+ , receiver(nullptr)
{
}
@@ -104,7 +104,7 @@ QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(QAbstractSocket
#ifndef QT_NO_NETWORKPROXY
// proxy type must have been resolved by now
if (proxy.type() == QNetworkProxy::DefaultProxy)
- return 0;
+ return nullptr;
#endif
QMutexLocker locker(&socketHandlers()->mutex);
@@ -116,7 +116,7 @@ QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(QAbstractSocket
#ifndef QT_NO_NETWORKPROXY
// only NoProxy can have reached here
if (proxy.type() != QNetworkProxy::NoProxy)
- return 0;
+ return nullptr;
#endif
return new QNativeSocketEngine(parent);
diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp
index c67b273937..21f97be29a 100644
--- a/src/network/socket/qhttpsocketengine.cpp
+++ b/src/network/socket/qhttpsocketengine.cpp
@@ -72,7 +72,7 @@ bool QHttpSocketEngine::initialize(QAbstractSocket::SocketType type, QAbstractSo
setSocketType(type);
d->socket = new QTcpSocket(this);
d->reply = new QHttpNetworkReply(QUrl(), this);
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
d->socket->setProperty("_q_networkSession", property("_q_networkSession"));
#endif
@@ -216,7 +216,7 @@ void QHttpSocketEngine::close()
if (d->socket) {
d->socket->close();
delete d->socket;
- d->socket = 0;
+ d->socket = nullptr;
}
}
@@ -370,8 +370,8 @@ bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut)
if (!d->socket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))) {
if (d->socket->state() == QAbstractSocket::UnconnectedState)
return true;
- setError(d->socket->error(), d->socket->errorString());
- if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
+ setError(d->socket->socketError(), d->socket->errorString());
+ if (timedOut && d->socket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -385,8 +385,8 @@ bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut)
// Report any error that may occur.
if (d->state != Connected) {
- setError(d->socket->error(), d->socket->errorString());
- if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
+ setError(d->socket->socketError(), d->socket->errorString());
+ if (timedOut && d->socket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -401,7 +401,7 @@ bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut)
if (d->state == Connected) {
if (d->socket->bytesToWrite()) {
if (!d->socket->waitForBytesWritten(msecs)) {
- if (d->socket->error() == QAbstractSocket::SocketTimeoutError && timedOut)
+ if (d->socket->socketError() == QAbstractSocket::SocketTimeoutError && timedOut)
*timedOut = true;
return false;
}
@@ -421,8 +421,7 @@ bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut)
// Report any error that may occur.
if (d->state != Connected) {
-// setError(d->socket->error(), d->socket->errorString());
- if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
+ if (timedOut && d->socket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
}
@@ -586,7 +585,7 @@ void QHttpSocketEngine::slotSocketReadNotification()
}
int statusCode = d->reply->statusCode();
- QAuthenticatorPrivate *priv = 0;
+ QAuthenticatorPrivate *priv = nullptr;
if (statusCode == 200) {
d->state = Connected;
setLocalAddress(d->socket->localAddress());
@@ -829,8 +828,8 @@ QHttpSocketEnginePrivate::QHttpSocketEnginePrivate()
, credentialsSent(false)
, pendingResponseData(0)
{
- socket = 0;
- reply = 0;
+ socket = nullptr;
+ reply = nullptr;
state = QHttpSocketEngine::None;
}
@@ -843,15 +842,15 @@ QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(QAbstractSoc
QObject *parent)
{
if (socketType != QAbstractSocket::TcpSocket)
- return 0;
+ return nullptr;
// proxy type must have been resolved by now
if (proxy.type() != QNetworkProxy::HttpProxy)
- return 0;
+ return nullptr;
// we only accept active sockets
if (!qobject_cast<QAbstractSocket *>(parent))
- return 0;
+ return nullptr;
QHttpSocketEngine *engine = new QHttpSocketEngine(parent);
engine->setProxy(proxy);
@@ -860,7 +859,7 @@ QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(QAbstractSoc
QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(qintptr, QObject *)
{
- return 0;
+ return nullptr;
}
QT_END_NAMESPACE
diff --git a/src/network/socket/qlocalserver.cpp b/src/network/socket/qlocalserver.cpp
index 3e36a7b229..5ca2db70b9 100644
--- a/src/network/socket/qlocalserver.cpp
+++ b/src/network/socket/qlocalserver.cpp
@@ -417,7 +417,7 @@ QLocalSocket *QLocalServer::nextPendingConnection()
{
Q_D(QLocalServer);
if (d->pendingConnections.isEmpty())
- return 0;
+ return nullptr;
QLocalSocket *nextSocket = d->pendingConnections.dequeue();
#ifndef QT_LOCALSOCKET_TCP
if (d->pendingConnections.size() <= d->maxPendingConnections)
diff --git a/src/network/socket/qlocalserver_unix.cpp b/src/network/socket/qlocalserver_unix.cpp
index 9547ec5b88..88367d680d 100644
--- a/src/network/socket/qlocalserver_unix.cpp
+++ b/src/network/socket/qlocalserver_unix.cpp
@@ -243,7 +243,7 @@ void QLocalServerPrivate::closeServer()
if (socketNotifier) {
socketNotifier->setEnabled(false); // Otherwise, closed socket is checked before deleter runs
socketNotifier->deleteLater();
- socketNotifier = 0;
+ socketNotifier = nullptr;
}
if (-1 != listenSocket)
diff --git a/src/network/socket/qlocalsocket.cpp b/src/network/socket/qlocalsocket.cpp
index af7cdb76d2..38e47d6e26 100644
--- a/src/network/socket/qlocalsocket.cpp
+++ b/src/network/socket/qlocalsocket.cpp
@@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE
The socket is opened in the given \a openMode and first enters ConnectingState.
If a connection is established, QLocalSocket enters ConnectedState and emits connected().
- After calling this function, the socket can emit error() to signal that an error occurred.
+ After calling this function, the socket can emit errorOccurred() to signal that an error occurred.
\sa state(), serverName(), waitForConnected()
*/
@@ -87,7 +87,7 @@ QT_BEGIN_NAMESPACE
Note that unlike in most other QIODevice subclasses, open() may not open the device directly.
The function return false if the socket was already connected or if the server to connect
- to was not defined and true in any other case. The connected() or error() signals will be
+ to was not defined and true in any other case. The connected() or errorOccurred() signals will be
emitted once the device is actualy open (or the connection failed).
See connectToServer() for more details.
@@ -329,6 +329,14 @@ QT_BEGIN_NAMESPACE
/*!
\fn void QLocalSocket::error(QLocalSocket::LocalSocketError socketError)
+ \obsolete
+
+ Use errorOccurred() instead.
+*/
+
+/*!
+ \fn void QLocalSocket::errorOccurred(QLocalSocket::LocalSocketError socketError)
+ \since 5.15
This signal is emitted after an error occurred. The \a socketError
parameter describes the type of error that occurred.
@@ -362,6 +370,9 @@ QLocalSocket::QLocalSocket(QObject * parent)
{
Q_D(QLocalSocket);
d->init();
+
+ // Support the deprecated error() signal:
+ connect(this, &QLocalSocket::errorOccurred, this, QOverload<QLocalSocket::LocalSocketError>::of(&QLocalSocket::error));
}
/*!
@@ -372,7 +383,7 @@ QLocalSocket::~QLocalSocket()
QLocalSocket::close();
#if !defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)
Q_D(QLocalSocket);
- d->unixSocket.setParent(0);
+ d->unixSocket.setParent(nullptr);
#endif
}
@@ -389,7 +400,7 @@ bool QLocalSocket::open(OpenMode openMode)
The socket is opened in the given \a openMode and first enters ConnectingState.
If a connection is established, QLocalSocket enters ConnectedState and emits connected().
- After calling this function, the socket can emit error() to signal that an error occurred.
+ After calling this function, the socket can emit errorOccurred() to signal that an error occurred.
\sa state(), serverName(), waitForConnected()
*/
diff --git a/src/network/socket/qlocalsocket.h b/src/network/socket/qlocalsocket.h
index 1876a6ac0d..ae78c86b3c 100644
--- a/src/network/socket/qlocalsocket.h
+++ b/src/network/socket/qlocalsocket.h
@@ -117,7 +117,11 @@ public:
Q_SIGNALS:
void connected();
void disconnected();
+#if QT_DEPRECATED_SINCE(5,15)
+ QT_DEPRECATED_X("Use QLocalSocket::errorOccurred(QLocalSocket::LocalSocketError) instead")
void error(QLocalSocket::LocalSocketError socketError);
+#endif
+ void errorOccurred(QLocalSocket::LocalSocketError socketError);
void stateChanged(QLocalSocket::LocalSocketState socketState);
protected:
diff --git a/src/network/socket/qlocalsocket_p.h b/src/network/socket/qlocalsocket_p.h
index d93b53be0c..e3bcd92326 100644
--- a/src/network/socket/qlocalsocket_p.h
+++ b/src/network/socket/qlocalsocket_p.h
@@ -125,7 +125,7 @@ public:
bool ownsTcpSocket;
void setSocket(QLocalUnixSocket*);
QString generateErrorString(QLocalSocket::LocalSocketError, const QString &function) const;
- void errorOccurred(QLocalSocket::LocalSocketError, const QString &function);
+ void setErrorAndEmit(QLocalSocket::LocalSocketError, const QString &function);
void _q_stateChanged(QAbstractSocket::SocketState newState);
void _q_error(QAbstractSocket::SocketError newError);
#elif defined(Q_OS_WIN)
@@ -142,7 +142,7 @@ public:
qint64 skip(qint64 maxSize) override;
QLocalUnixSocket unixSocket;
QString generateErrorString(QLocalSocket::LocalSocketError, const QString &function) const;
- void errorOccurred(QLocalSocket::LocalSocketError, const QString &function);
+ void setErrorAndEmit(QLocalSocket::LocalSocketError, const QString &function);
void _q_stateChanged(QAbstractSocket::SocketState newState);
void _q_error(QAbstractSocket::SocketError newError);
void _q_connectToSocket();
diff --git a/src/network/socket/qlocalsocket_tcp.cpp b/src/network/socket/qlocalsocket_tcp.cpp
index 41e5b47627..e13bcfc0cb 100644
--- a/src/network/socket/qlocalsocket_tcp.cpp
+++ b/src/network/socket/qlocalsocket_tcp.cpp
@@ -95,7 +95,7 @@ void QLocalSocketPrivate::_q_error(QAbstractSocket::SocketError socketError)
QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
QString errorString = generateErrorString(error, function);
q->setErrorString(errorString);
- emit q->error(error);
+ emit q->errorOccurred(error);
}
void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
@@ -168,7 +168,7 @@ QString QLocalSocketPrivate::generateErrorString(QLocalSocket::LocalSocketError
return errorString;
}
-void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, const QString &function)
+void QLocalSocketPrivate::setErrorAndEmit(QLocalSocket::LocalSocketError error, const QString &function)
{
Q_Q(QLocalSocket);
switch (error) {
@@ -206,7 +206,7 @@ void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, co
QString errorString = generateErrorString(error, function);
q->setErrorString(errorString);
- emit q->error(error);
+ emit q->errorOccurred(error);
// errors cause a disconnect
tcpSocket->setSocketState(QAbstractSocket::UnconnectedState);
@@ -222,7 +222,7 @@ void QLocalSocket::connectToServer(OpenMode openMode)
Q_D(QLocalSocket);
if (state() == ConnectedState || state() == ConnectingState) {
setErrorString(tr("Trying to connect while connection is in progress"));
- emit error(QLocalSocket::OperationError);
+ emit errorOccurred(QLocalSocket::OperationError);
return;
}
@@ -231,8 +231,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
emit stateChanged(d->state);
if (d->serverName.isEmpty()) {
- d->errorOccurred(ServerNotFoundError,
- QLatin1String("QLocalSocket::connectToServer"));
+ d->setErrorAndEmit(ServerNotFoundError,
+ QLatin1String("QLocalSocket::connectToServer"));
return;
}
@@ -246,8 +246,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
bool ok;
const quint16 port = settings.value(d->fullServerName).toUInt(&ok);
if (!ok) {
- d->errorOccurred(ServerNotFoundError,
- QLatin1String("QLocalSocket::connectToServer"));
+ d->setErrorAndEmit(ServerNotFoundError,
+ QLatin1String("QLocalSocket::connectToServer"));
return;
}
QIODevice::open(openMode);
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index d1df26d9f1..e860b880d5 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -61,10 +61,9 @@
QT_BEGIN_NAMESPACE
QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
- delayConnect(0),
- connectTimer(0),
+ delayConnect(nullptr),
+ connectTimer(nullptr),
connectingSocket(-1),
- connectingOpenMode(0),
state(QLocalSocket::UnconnectedState)
{
}
@@ -100,7 +99,7 @@ void QLocalSocketPrivate::_q_error(QAbstractSocket::SocketError socketError)
QLocalSocket::LocalSocketError error = (QLocalSocket::LocalSocketError)socketError;
QString errorString = generateErrorString(error, function);
q->setErrorString(errorString);
- emit q->error(error);
+ emit q->errorOccurred(error);
}
void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
@@ -173,7 +172,7 @@ QString QLocalSocketPrivate::generateErrorString(QLocalSocket::LocalSocketError
return errorString;
}
-void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, const QString &function)
+void QLocalSocketPrivate::setErrorAndEmit(QLocalSocket::LocalSocketError error, const QString &function)
{
Q_Q(QLocalSocket);
switch (error) {
@@ -211,7 +210,7 @@ void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, co
QString errorString = generateErrorString(error, function);
q->setErrorString(errorString);
- emit q->error(error);
+ emit q->errorOccurred(error);
// errors cause a disconnect
unixSocket.setSocketState(QAbstractSocket::UnconnectedState);
@@ -228,7 +227,7 @@ void QLocalSocket::connectToServer(OpenMode openMode)
if (state() == ConnectedState || state() == ConnectingState) {
QString errorString = d->generateErrorString(QLocalSocket::OperationError, QLatin1String("QLocalSocket::connectToserver"));
setErrorString(errorString);
- emit error(QLocalSocket::OperationError);
+ emit errorOccurred(QLocalSocket::OperationError);
return;
}
@@ -238,15 +237,15 @@ void QLocalSocket::connectToServer(OpenMode openMode)
emit stateChanged(d->state);
if (d->serverName.isEmpty()) {
- d->errorOccurred(ServerNotFoundError,
- QLatin1String("QLocalSocket::connectToServer"));
+ d->setErrorAndEmit(ServerNotFoundError,
+ QLatin1String("QLocalSocket::connectToServer"));
return;
}
// create the socket
if (-1 == (d->connectingSocket = qt_safe_socket(PF_UNIX, SOCK_STREAM, 0, O_NONBLOCK))) {
- d->errorOccurred(UnsupportedSocketOperationError,
- QLatin1String("QLocalSocket::connectToServer"));
+ d->setErrorAndEmit(UnsupportedSocketOperationError,
+ QLatin1String("QLocalSocket::connectToServer"));
return;
}
@@ -282,7 +281,7 @@ void QLocalSocketPrivate::_q_connectToSocket()
name.sun_family = PF_UNIX;
if (sizeof(name.sun_path) < (uint)encodedConnectingPathName.size() + 1) {
QString function = QLatin1String("QLocalSocket::connectToServer");
- errorOccurred(QLocalSocket::ServerNotFoundError, function);
+ setErrorAndEmit(QLocalSocket::ServerNotFoundError, function);
return;
}
::memcpy(name.sun_path, encodedConnectingPathName.constData(),
@@ -293,17 +292,17 @@ void QLocalSocketPrivate::_q_connectToSocket()
{
case EINVAL:
case ECONNREFUSED:
- errorOccurred(QLocalSocket::ConnectionRefusedError, function);
+ setErrorAndEmit(QLocalSocket::ConnectionRefusedError, function);
break;
case ENOENT:
- errorOccurred(QLocalSocket::ServerNotFoundError, function);
+ setErrorAndEmit(QLocalSocket::ServerNotFoundError, function);
break;
case EACCES:
case EPERM:
- errorOccurred(QLocalSocket::SocketAccessError, function);
+ setErrorAndEmit(QLocalSocket::SocketAccessError, function);
break;
case ETIMEDOUT:
- errorOccurred(QLocalSocket::SocketTimeoutError, function);
+ setErrorAndEmit(QLocalSocket::SocketTimeoutError, function);
break;
case EAGAIN:
// Try again later, all of the sockets listening are full
@@ -321,7 +320,7 @@ void QLocalSocketPrivate::_q_connectToSocket()
delayConnect->setEnabled(true);
break;
default:
- errorOccurred(QLocalSocket::UnknownSocketError, function);
+ setErrorAndEmit(QLocalSocket::UnknownSocketError, function);
}
return;
}
@@ -337,11 +336,11 @@ void QLocalSocketPrivate::_q_connectToSocket()
q->emit connected();
} else {
QString function = QLatin1String("QLocalSocket::connectToServer");
- errorOccurred(QLocalSocket::UnknownSocketError, function);
+ setErrorAndEmit(QLocalSocket::UnknownSocketError, function);
}
connectingSocket = -1;
connectingName.clear();
- connectingOpenMode = 0;
+ connectingOpenMode = { };
}
bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor,
@@ -380,10 +379,10 @@ void QLocalSocketPrivate::cancelDelayedConnect()
if (delayConnect) {
delayConnect->setEnabled(false);
delete delayConnect;
- delayConnect = 0;
+ delayConnect = nullptr;
connectTimer->stop();
delete connectTimer;
- connectTimer = 0;
+ connectTimer = nullptr;
}
}
@@ -438,7 +437,7 @@ void QLocalSocket::close()
::close(d->connectingSocket);
d->connectingSocket = -1;
d->connectingName.clear();
- d->connectingOpenMode = 0;
+ d->connectingOpenMode = { };
d->serverName.clear();
d->fullServerName.clear();
QIODevice::close();
@@ -465,7 +464,7 @@ void QLocalSocket::disconnectFromServer()
QLocalSocket::LocalSocketError QLocalSocket::error() const
{
Q_D(const QLocalSocket);
- switch (d->unixSocket.error()) {
+ switch (d->unixSocket.socketError()) {
case QAbstractSocket::ConnectionRefusedError:
return QLocalSocket::ConnectionRefusedError;
case QAbstractSocket::RemoteHostClosedError:
@@ -530,8 +529,8 @@ bool QLocalSocket::waitForConnected(int msec)
const int result = qt_poll_msecs(&pfd, 1, timeout);
if (result == -1)
- d->errorOccurred(QLocalSocket::UnknownSocketError,
- QLatin1String("QLocalSocket::waitForConnected"));
+ d->setErrorAndEmit(QLocalSocket::UnknownSocketError,
+ QLatin1String("QLocalSocket::waitForConnected"));
else if (result > 0)
d->_q_connectToSocket();
} while (state() == ConnectingState && !timer.hasExpired(msec));
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index 4decbd5ded..48ffd87beb 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -91,7 +91,7 @@ void QLocalSocketPrivate::_q_winError(ulong windowsError, const QString &functio
if (state == QLocalSocket::UnconnectedState && currentState != QLocalSocket::ConnectingState)
emit q->disconnected();
}
- emit q->error(error);
+ emit q->errorOccurred(error);
}
QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
@@ -123,7 +123,7 @@ void QLocalSocket::connectToServer(OpenMode openMode)
if (state() == ConnectedState || state() == ConnectingState) {
d->error = OperationError;
d->errorString = tr("Trying to connect while connection is in progress");
- emit error(QLocalSocket::OperationError);
+ emit errorOccurred(QLocalSocket::OperationError);
return;
}
@@ -135,7 +135,7 @@ void QLocalSocket::connectToServer(OpenMode openMode)
d->error = ServerNotFoundError;
d->errorString = tr("%1: Invalid name").arg(QLatin1String("QLocalSocket::connectToServer"));
d->state = UnconnectedState;
- emit error(d->error);
+ emit errorOccurred(d->error);
emit stateChanged(d->state);
return;
}
diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp
index 5126a5330f..31628846dc 100644
--- a/src/network/socket/qnativesocketengine.cpp
+++ b/src/network/socket/qnativesocketengine.cpp
@@ -191,9 +191,9 @@ QT_BEGIN_NAMESPACE
*/
QNativeSocketEnginePrivate::QNativeSocketEnginePrivate() :
socketDescriptor(-1),
- readNotifier(0),
- writeNotifier(0),
- exceptNotifier(0)
+ readNotifier(nullptr),
+ writeNotifier(nullptr),
+ exceptNotifier(nullptr)
{
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
QSysInfo::machineHostName(); // this initializes ws2_32.dll
@@ -985,15 +985,15 @@ void QNativeSocketEngine::close()
d->inboundStreamCount = d->outboundStreamCount = 0;
if (d->readNotifier) {
qDeleteInEventHandler(d->readNotifier);
- d->readNotifier = 0;
+ d->readNotifier = nullptr;
}
if (d->writeNotifier) {
qDeleteInEventHandler(d->writeNotifier);
- d->writeNotifier = 0;
+ d->writeNotifier = nullptr;
}
if (d->exceptNotifier) {
qDeleteInEventHandler(d->exceptNotifier);
- d->exceptNotifier = 0;
+ d->exceptNotifier = nullptr;
}
}
@@ -1341,7 +1341,7 @@ void QNativeSocketEngine::setReadNotificationEnabled(bool enable)
Q_D(QNativeSocketEngine);
if (d->readNotifier) {
d->readNotifier->setEnabled(enable);
- } else if (enable && d->threadData->hasEventDispatcher()) {
+ } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
d->readNotifier = new QReadNotifier(d->socketDescriptor, this);
d->readNotifier->setEnabled(true);
}
@@ -1358,7 +1358,7 @@ void QNativeSocketEngine::setWriteNotificationEnabled(bool enable)
Q_D(QNativeSocketEngine);
if (d->writeNotifier) {
d->writeNotifier->setEnabled(enable);
- } else if (enable && d->threadData->hasEventDispatcher()) {
+ } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
d->writeNotifier = new QWriteNotifier(d->socketDescriptor, this);
d->writeNotifier->setEnabled(true);
}
@@ -1375,7 +1375,7 @@ void QNativeSocketEngine::setExceptionNotificationEnabled(bool enable)
Q_D(QNativeSocketEngine);
if (d->exceptNotifier) {
d->exceptNotifier->setEnabled(enable);
- } else if (enable && d->threadData->hasEventDispatcher()) {
+ } else if (enable && d->threadData.loadRelaxed()->hasEventDispatcher()) {
d->exceptNotifier = new QExceptionNotifier(d->socketDescriptor, this);
d->exceptNotifier->setEnabled(true);
}
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index 3ca586e247..e5b9fbbdb2 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -628,7 +628,7 @@ bool QNativeSocketEnginePrivate::nativeListen(int backlog)
int QNativeSocketEnginePrivate::nativeAccept()
{
- int acceptedDescriptor = qt_safe_accept(socketDescriptor, 0, 0);
+ int acceptedDescriptor = qt_safe_accept(socketDescriptor, nullptr, nullptr);
if (acceptedDescriptor == -1) {
switch (errno) {
case EBADF:
@@ -1002,7 +1002,7 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxS
struct cmsghdr *cmsgptr;
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wsign-compare")
- for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL;
+ for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != nullptr;
cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
QT_WARNING_POP
if (cmsgptr->cmsg_level == IPPROTO_IPV6 && cmsgptr->cmsg_type == IPV6_PKTINFO
@@ -1166,7 +1166,7 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l
#endif
if (msg.msg_controllen == 0)
- msg.msg_control = 0;
+ msg.msg_control = nullptr;
ssize_t sentBytes = qt_safe_sendmsg(socketDescriptor, &msg, 0);
if (sentBytes < 0) {
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 9edabd7822..dd115c33dc 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -53,6 +53,8 @@
#include <qnetworkinterface.h>
#include <qoperatingsystemversion.h>
+#include <algorithm>
+
//#define QNATIVESOCKETENGINE_DEBUG
#if defined(QNATIVESOCKETENGINE_DEBUG)
# include <qstring.h>
@@ -1141,13 +1143,14 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const
qint64 ret = -1;
int recvResult = 0;
DWORD flags;
- // 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;
+ // We increase the amount we peek by 2048 * 5 on each iteration
+ // Grabs most cases fast and early.
+ char udpMessagePeekBuffer[2048];
+ const int increments = 5;
+ QVarLengthArray<WSABUF, 10> buf;
for (;;) {
- buf.resize(buf.size() + 5, {sizeof(udpMessagePeekBuffer), udpMessagePeekBuffer});
+ buf.reserve(buf.size() + increments);
+ std::fill_n(std::back_inserter(buf), increments, WSABUF{sizeof(udpMessagePeekBuffer), udpMessagePeekBuffer});
flags = MSG_PEEK;
DWORD bytesRead = 0;
diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp
index 8a030601dc..f0ccc9054a 100644
--- a/src/network/socket/qsocks5socketengine.cpp
+++ b/src/network/socket/qsocks5socketengine.cpp
@@ -365,13 +365,13 @@ QSocks5BindData *QSocks5BindStore::retrieve(qintptr socketDescriptor)
QMutexLocker lock(&mutex);
const auto it = store.constFind(socketDescriptor);
if (it == store.cend())
- return 0;
+ return nullptr;
QSocks5BindData *bindData = it.value();
store.erase(it);
if (bindData) {
if (bindData->controlSocket->thread() != QThread::currentThread()) {
qWarning("Cannot access socks5 bind data from different thread");
- return 0;
+ return nullptr;
}
} else {
QSOCKS5_DEBUG << "__ERROR__ binddata == 0";
@@ -503,12 +503,12 @@ QSocks5SocketEnginePrivate::QSocks5SocketEnginePrivate()
, writeNotificationEnabled(false)
, exceptNotificationEnabled(false)
, socketDescriptor(-1)
- , data(0)
- , connectData(0)
+ , data(nullptr)
+ , connectData(nullptr)
#ifndef QT_NO_UDPSOCKET
- , udpData(0)
+ , udpData(nullptr)
#endif
- , bindData(0)
+ , bindData(nullptr)
, readNotificationActivated(false)
, writeNotificationActivated(false)
, readNotificationPending(false)
@@ -535,7 +535,7 @@ void QSocks5SocketEnginePrivate::initialize(Socks5Mode socks5Mode)
udpData = new QSocks5UdpAssociateData;
data = udpData;
udpData->udpSocket = new QUdpSocket(q);
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
udpData->udpSocket->setProperty("_q_networksession", q->property("_q_networksession"));
#endif
udpData->udpSocket->setProxy(QNetworkProxy::NoProxy);
@@ -549,7 +549,7 @@ void QSocks5SocketEnginePrivate::initialize(Socks5Mode socks5Mode)
}
data->controlSocket = new QTcpSocket(q);
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
data->controlSocket->setProperty("_q_networksession", q->property("_q_networksession"));
#endif
data->controlSocket->setProxy(QNetworkProxy::NoProxy);
@@ -594,7 +594,7 @@ void QSocks5SocketEnginePrivate::setErrorState(Socks5State state, const QString
case ConnectError:
case ControlSocketError: {
- QAbstractSocket::SocketError controlSocketError = data->controlSocket->error();
+ QAbstractSocket::SocketError controlSocketError = data->controlSocket->socketError();
if (socks5State != Connected) {
switch (controlSocketError) {
case QAbstractSocket::ConnectionRefusedError:
@@ -918,7 +918,7 @@ void QSocks5SocketEnginePrivate::_q_emitPendingReadNotification()
return;
// check if there needs to be a new zero read notification
if (data && data->controlSocket->state() == QAbstractSocket::UnconnectedState
- && data->controlSocket->error() == QAbstractSocket::RemoteHostClosedError) {
+ && data->controlSocket->socketError() == QAbstractSocket::RemoteHostClosedError) {
connectData->readBuffer.clear();
emitReadNotification();
}
@@ -1038,11 +1038,11 @@ bool QSocks5SocketEngine::initialize(qintptr socketDescriptor, QAbstractSocket::
d->data = d->connectData;
d->mode = QSocks5SocketEnginePrivate::ConnectMode;
d->data->controlSocket = bindData->controlSocket;
- bindData->controlSocket = 0;
+ bindData->controlSocket = nullptr;
d->data->controlSocket->setParent(this);
d->socketProtocol = d->data->controlSocket->localAddress().protocol();
d->data->authenticator = bindData->authenticator;
- bindData->authenticator = 0;
+ bindData->authenticator = nullptr;
d->localPort = bindData->localPort;
d->localAddress = bindData->localAddress;
d->peerPort = bindData->peerPort;
@@ -1256,7 +1256,7 @@ void QSocks5SocketEnginePrivate::_q_controlSocketError(QAbstractSocket::SocketEr
data->controlSocket->close();
emitConnectionNotification();
} else {
- q_func()->setError(data->controlSocket->error(), data->controlSocket->errorString());
+ q_func()->setError(data->controlSocket->socketError(), data->controlSocket->errorString());
emitReadNotification();
emitWriteNotification();
}
@@ -1348,7 +1348,7 @@ bool QSocks5SocketEngine::bind(const QHostAddress &addr, quint16 port)
if (d->mode == QSocks5SocketEnginePrivate::UdpAssociateMode) {
if (!d->udpData->udpSocket->bind(address, port)) {
QSOCKS5_Q_DEBUG << "local udp bind failed";
- setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
+ setError(d->udpData->udpSocket->socketError(), d->udpData->udpSocket->errorString());
return false;
}
d->localAddress = d->udpData->udpSocket->localAddress();
@@ -1367,7 +1367,7 @@ bool QSocks5SocketEngine::bind(const QHostAddress &addr, quint16 port)
QElapsedTimer stopWatch;
stopWatch.start();
d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port());
- if (!d->waitForConnected(msecs, 0) ||
+ if (!d->waitForConnected(msecs, nullptr) ||
d->data->controlSocket->state() == QAbstractSocket::UnconnectedState) {
// waitForConnected sets the error state and closes the socket
QSOCKS5_Q_DEBUG << "waitForConnected to proxy server" << d->data->controlSocket->errorString();
@@ -1428,13 +1428,13 @@ int QSocks5SocketEngine::accept()
case QSocks5SocketEnginePrivate::BindSuccess:
QSOCKS5_Q_DEBUG << "BindSuccess adding" << d->socketDescriptor << "to the bind store";
d->data->controlSocket->disconnect();
- d->data->controlSocket->setParent(0);
+ d->data->controlSocket->setParent(nullptr);
d->bindData->localAddress = d->localAddress;
d->bindData->localPort = d->localPort;
sd = d->socketDescriptor;
socks5BindStore()->add(sd, d->bindData);
- d->data = 0;
- d->bindData = 0;
+ d->data = nullptr;
+ d->bindData = nullptr;
d->socketDescriptor = 0;
//### do something about this socket layer ... set it closed and an error about why ...
// reset state and local port/address
@@ -1656,8 +1656,8 @@ qint64 QSocks5SocketEngine::writeDatagram(const char *data, qint64 len, const QI
}
if (d->udpData->udpSocket->writeDatagram(sealedBuf, d->udpData->associateAddress, d->udpData->associatePort) != sealedBuf.size()) {
//### try frgamenting
- if (d->udpData->udpSocket->error() == QAbstractSocket::DatagramTooLargeError)
- setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
+ if (d->udpData->udpSocket->socketError() == QAbstractSocket::DatagramTooLargeError)
+ setError(d->udpData->udpSocket->socketError(), d->udpData->udpSocket->errorString());
//### else maybe more serious error
return -1;
}
@@ -1727,7 +1727,7 @@ bool QSocks5SocketEnginePrivate::waitForConnected(int msecs, bool *timedOut)
return true;
setErrorState(QSocks5SocketEnginePrivate::ControlSocketError);
- if (timedOut && data->controlSocket->error() == QAbstractSocket::SocketTimeoutError)
+ if (timedOut && data->controlSocket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -1765,8 +1765,8 @@ bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut)
if (d->data->controlSocket->state() == QAbstractSocket::UnconnectedState)
return true;
- setError(d->data->controlSocket->error(), d->data->controlSocket->errorString());
- if (timedOut && d->data->controlSocket->error() == QAbstractSocket::SocketTimeoutError)
+ setError(d->data->controlSocket->socketError(), d->data->controlSocket->errorString());
+ if (timedOut && d->data->controlSocket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -1775,8 +1775,8 @@ bool QSocks5SocketEngine::waitForRead(int msecs, bool *timedOut)
} else {
while (!d->readNotificationActivated) {
if (!d->udpData->udpSocket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))) {
- setError(d->udpData->udpSocket->error(), d->udpData->udpSocket->errorString());
- if (timedOut && d->udpData->udpSocket->error() == QAbstractSocket::SocketTimeoutError)
+ setError(d->udpData->udpSocket->socketError(), d->udpData->udpSocket->errorString());
+ if (timedOut && d->udpData->udpSocket->socketError() == QAbstractSocket::SocketTimeoutError)
*timedOut = true;
return false;
}
@@ -1909,7 +1909,7 @@ QSocks5SocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socke
// proxy type must have been resolved by now
if (proxy.type() != QNetworkProxy::Socks5Proxy) {
QSOCKS5_DEBUG << "not proxying";
- return 0;
+ return nullptr;
}
QScopedPointer<QSocks5SocketEngine> engine(new QSocks5SocketEngine(parent));
engine->setProxy(proxy);
@@ -1923,7 +1923,7 @@ QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(qintptr so
QSOCKS5_DEBUG << "bind store contains" << socketDescriptor;
return new QSocks5SocketEngine(parent);
}
- return 0;
+ return nullptr;
}
QT_END_NAMESPACE
diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp
index 98e58192a2..c23b143de3 100644
--- a/src/network/socket/qtcpserver.cpp
+++ b/src/network/socket/qtcpserver.cpp
@@ -121,7 +121,7 @@ QTcpServerPrivate::QTcpServerPrivate()
: port(0)
, socketType(QAbstractSocket::UnknownSocketType)
, state(QAbstractSocket::UnconnectedState)
- , socketEngine(0)
+ , socketEngine(nullptr)
, serverSocketError(QAbstractSocket::UnknownSocketError)
, maxConnections(30)
{
@@ -314,7 +314,7 @@ bool QTcpServer::listen(const QHostAddress &address, quint16 port)
d->serverSocketErrorString = tr("Operation on socket is not supported");
return false;
}
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
//copy network session down to the socket engine (if it has been set)
d->socketEngine->setProperty("_q_networksession", property("_q_networksession"));
#endif
@@ -389,7 +389,7 @@ void QTcpServer::close()
// in out of memory situations, the socketEngine
// will be deleted in ~QTcpServer (it's a child-object of this)
}
- d->socketEngine = 0;
+ d->socketEngine = nullptr;
}
d->state = QAbstractSocket::UnconnectedState;
@@ -436,7 +436,7 @@ bool QTcpServer::setSocketDescriptor(qintptr socketDescriptor)
d->serverSocketErrorString = tr("Operation on socket is not supported");
return false;
}
-#ifndef QT_NO_BEARERMANAGEMENT
+#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
//copy network session down to the socket engine (if it has been set)
d->socketEngine->setProperty("_q_networksession", property("_q_networksession"));
#endif
@@ -561,7 +561,7 @@ QTcpSocket *QTcpServer::nextPendingConnection()
{
Q_D(QTcpServer);
if (d->pendingConnections.isEmpty())
- return 0;
+ return nullptr;
if (!d->socketEngine) {
qWarning("QTcpServer::nextPendingConnection() called while not listening");
diff --git a/src/network/socket/qudpsocket.cpp b/src/network/socket/qudpsocket.cpp
index 0e3d516535..9694dfa507 100644
--- a/src/network/socket/qudpsocket.cpp
+++ b/src/network/socket/qudpsocket.cpp
@@ -479,7 +479,7 @@ QNetworkDatagram QUdpSocket::receiveDatagram(qint64 maxSize)
/*!
Receives a datagram no larger than \a maxSize bytes and stores
it in \a data. The sender's host address and port is stored in
- *\a address and *\a port (unless the pointers are 0).
+ *\a address and *\a port (unless the pointers are \nullptr).
Returns the size of the datagram on success; otherwise returns
-1.