summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2018-11-13 10:42:14 +0100
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2018-11-22 14:28:29 +0000
commitcbac5a1a6edfd0d7a1e351bbe50bab118d1155e5 (patch)
treec63f93e9f55bfbf86b0ab79f963735c99208fb07 /src/network
parent7c93f1cf5d31cb1031fa52a0a610916e4f996457 (diff)
QLocalSocket (windows) - remove broken setErrorString
We report two types of errors - those found by our code and errors coming from the OS. setErrorString(), despite its name, does not just set a string, but extracts a windows error code via GetLastError() and then calls _q_winError(). This is wrong: some arbitrary error code (or no error) can be reported when it was actually an error found by Qt. Worse yet, string operations (allocations etc.) can potentially clear the real error code. So remove setErrorString(), set errors explicitly if it's the application code error or use _q_WinError directly. Task-number: QTBUG-71744 Change-Id: I67277d84006c4ad365f5636caf850e1f3ba4e1dc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/socket/qlocalsocket_p.h1
-rw-r--r--src/network/socket/qlocalsocket_win.cpp16
2 files changed, 6 insertions, 11 deletions
diff --git a/src/network/socket/qlocalsocket_p.h b/src/network/socket/qlocalsocket_p.h
index 8b72da397f..d93b53be0c 100644
--- a/src/network/socket/qlocalsocket_p.h
+++ b/src/network/socket/qlocalsocket_p.h
@@ -131,7 +131,6 @@ public:
#elif defined(Q_OS_WIN)
~QLocalSocketPrivate();
void destroyPipeHandles();
- void setErrorString(const QString &function);
void _q_canWrite();
void _q_pipeClosed();
void _q_winError(ulong windowsError, const QString &function);
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index 8e20f9efbe..d6ee76043f 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -50,12 +50,6 @@ void QLocalSocketPrivate::init()
q->connect(pipeReader, SIGNAL(winError(ulong,QString)), SLOT(_q_winError(ulong,QString)));
}
-void QLocalSocketPrivate::setErrorString(const QString &function)
-{
- DWORD windowsError = GetLastError();
- _q_winError(windowsError, function);
-}
-
void QLocalSocketPrivate::_q_winError(ulong windowsError, const QString &function)
{
Q_Q(QLocalSocket);
@@ -127,7 +121,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
{
Q_D(QLocalSocket);
if (state() == ConnectedState || state() == ConnectingState) {
- setErrorString(tr("Trying to connect while connection is in progress"));
+ d->error = OperationError;
+ d->errorString = tr("Trying to connect while connection is in progress");
emit error(QLocalSocket::OperationError);
return;
}
@@ -137,8 +132,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
d->state = ConnectingState;
emit stateChanged(d->state);
if (d->serverName.isEmpty()) {
- d->error = QLocalSocket::ServerNotFoundError;
- setErrorString(QLocalSocket::tr("%1: Invalid name").arg(QLatin1String("QLocalSocket::connectToServer")));
+ d->error = ServerNotFoundError;
+ d->errorString = tr("%1: Invalid name").arg(QLatin1String("QLocalSocket::connectToServer"));
d->state = UnconnectedState;
emit error(d->error);
emit stateChanged(d->state);
@@ -177,7 +172,8 @@ void QLocalSocket::connectToServer(OpenMode openMode)
}
if (localSocket == INVALID_HANDLE_VALUE) {
- d->setErrorString(QLatin1String("QLocalSocket::connectToServer"));
+ const DWORD winError = GetLastError();
+ d->_q_winError(winError, QLatin1String("QLocalSocket::connectToServer"));
d->fullServerName = QString();
return;
}