Emit error if trying to connect while socket is connected or connecting.
This applies to both local and abstract sockets. Task-number: QTBUG-22450 Change-Id: I5c58d68da95ffb6bcde5be510853359b288e5984 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>bb10
parent
f821d6352e
commit
b494672208
|
|
@ -315,6 +315,8 @@
|
|||
proxy) was not found.
|
||||
\value ProxyProtocolError The connection negotiation with the proxy server
|
||||
because the response from the proxy server could not be understood.
|
||||
\value OperationError An operation was attempted while the socket was in a state that
|
||||
did not permit it.
|
||||
|
||||
\value UnknownSocketError An unidentified error occurred.
|
||||
\sa QAbstractSocket::error()
|
||||
|
|
@ -1497,6 +1499,9 @@ void QAbstractSocket::connectToHostImplementation(const QString &hostName, quint
|
|||
if (d->state == ConnectedState || d->state == ConnectingState
|
||||
|| d->state == ClosingState || d->state == HostLookupState) {
|
||||
qWarning("QAbstractSocket::connectToHost() called when already looking up or connecting/connected to \"%s\"", qPrintable(hostName));
|
||||
d->socketError = QAbstractSocket::OperationError;
|
||||
setErrorString(QAbstractSocket::tr("Trying to connect while connection is in progress"));
|
||||
emit error(d->socketError);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ public:
|
|||
ProxyConnectionTimeoutError,
|
||||
ProxyNotFoundError,
|
||||
ProxyProtocolError,
|
||||
OperationError,
|
||||
|
||||
UnknownSocketError = -1
|
||||
};
|
||||
|
|
|
|||
|
|
@ -419,6 +419,8 @@ bool QLocalSocket::isSequential() const
|
|||
\value ConnectionError An error occurred with the connection.
|
||||
\value UnsupportedSocketOperationError The requested socket operation
|
||||
is not supported by the local operating system.
|
||||
\value OperationError An operation was attempted while the socket was in a state that
|
||||
did not permit it.
|
||||
\value UnknownSocketError An unidentified error occurred.
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ public:
|
|||
DatagramTooLargeError = QAbstractSocket::DatagramTooLargeError,
|
||||
ConnectionError = QAbstractSocket::NetworkError,
|
||||
UnsupportedSocketOperationError = QAbstractSocket::UnsupportedSocketOperationError,
|
||||
UnknownSocketError = QAbstractSocket::UnknownSocketError
|
||||
UnknownSocketError = QAbstractSocket::UnknownSocketError,
|
||||
OperationError = QAbstractSocket::OperationError
|
||||
};
|
||||
|
||||
enum LocalSocketState
|
||||
|
|
|
|||
|
|
@ -155,6 +155,9 @@ QString QLocalSocketPrivate::generateErrorString(QLocalSocket::LocalSocketError
|
|||
case QLocalSocket::UnsupportedSocketOperationError:
|
||||
errorString = QLocalSocket::tr("%1: The socket operation is not supported").arg(function);
|
||||
break;
|
||||
case QLocalSocket::OperationError:
|
||||
errorString = QLocalSocket::tr("%1: Operation not permitted when socket is in this state").arg(function);
|
||||
break;
|
||||
case QLocalSocket::UnknownSocketError:
|
||||
default:
|
||||
errorString = QLocalSocket::tr("%1: Unknown error").arg(function);
|
||||
|
|
|
|||
|
|
@ -162,6 +162,9 @@ QString QLocalSocketPrivate::generateErrorString(QLocalSocket::LocalSocketError
|
|||
case QLocalSocket::UnsupportedSocketOperationError:
|
||||
errorString = QLocalSocket::tr("%1: The socket operation is not supported").arg(function);
|
||||
break;
|
||||
case QLocalSocket::OperationError:
|
||||
errorString = QLocalSocket::tr("%1: Operation not permitted when socket is in this state").arg(function);
|
||||
break;
|
||||
case QLocalSocket::UnknownSocketError:
|
||||
default:
|
||||
errorString = QLocalSocket::tr("%1: Unknown error %2").arg(function).arg(errno);
|
||||
|
|
@ -221,9 +224,12 @@ void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, co
|
|||
void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
|
||||
{
|
||||
Q_D(QLocalSocket);
|
||||
if (state() == ConnectedState
|
||||
|| state() == ConnectingState)
|
||||
if (state() == ConnectedState || state() == ConnectingState) {
|
||||
QString errorString = d->generateErrorString(QLocalSocket::OperationError, QLatin1String("QLocalSocket::connectToserver"));
|
||||
setErrorString(errorString);
|
||||
emit error(QLocalSocket::OperationError);
|
||||
return;
|
||||
}
|
||||
|
||||
d->errorString.clear();
|
||||
d->unixSocket.setSocketState(QAbstractSocket::ConnectingState);
|
||||
|
|
|
|||
|
|
@ -131,8 +131,11 @@ void QLocalSocketPrivate::destroyPipeHandles()
|
|||
void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
|
||||
{
|
||||
Q_D(QLocalSocket);
|
||||
if (state() == ConnectedState || state() == ConnectingState)
|
||||
if (state() == ConnectedState || state() == ConnectingState) {
|
||||
setErrorString("Trying to connect while connection is in progress");
|
||||
emit error(QLocalSocket::OperationError);
|
||||
return;
|
||||
}
|
||||
|
||||
d->error = QLocalSocket::UnknownSocketError;
|
||||
d->errorString = QString();
|
||||
|
|
|
|||
Loading…
Reference in New Issue