WinRT: Unregister callbacks when socket engine is destroyed
Change-Id: I66e8fff2556ce23a66db1148bdb68e9a448227b2 Reviewed-by: Andrew Knight <andrew.knight@intopalo.com>
This commit is contained in:
parent
d8130786b6
commit
1840cc982a
@ -318,8 +318,7 @@ bool QNativeSocketEngine::bind(const QHostAddress &address, quint16 port)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventRegistrationToken token;
|
d->tcpListener->add_ConnectionReceived(Callback<ClientConnectedHandler>(d, &QNativeSocketEnginePrivate::handleClientConnection).Get(), &d->connectionToken);
|
||||||
d->tcpListener->add_ConnectionReceived(Callback<ClientConnectedHandler>(d, &QNativeSocketEnginePrivate::handleClientConnection).Get(), &token);
|
|
||||||
hr = d->tcpListener->BindEndpointAsync(hostAddress.Get(), portString.Get(), &op);
|
hr = d->tcpListener->BindEndpointAsync(hostAddress.Get(), portString.Get(), &op);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
qErrnoWarning(hr, "Unable to bind socket."); // ### Set error message
|
qErrnoWarning(hr, "Unable to bind socket."); // ### Set error message
|
||||||
@ -779,9 +778,8 @@ bool QNativeSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType soc
|
|||||||
qWarning("Failed to create stream socket");
|
qWarning("Failed to create stream socket");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EventRegistrationToken token;
|
|
||||||
socketDescriptor = qintptr(socket.Detach());
|
socketDescriptor = qintptr(socket.Detach());
|
||||||
udpSocket()->add_MessageReceived(Callback<DatagramReceivedHandler>(this, &QNativeSocketEnginePrivate::handleNewDatagram).Get(), &token);
|
udpSocket()->add_MessageReceived(Callback<DatagramReceivedHandler>(this, &QNativeSocketEnginePrivate::handleNewDatagram).Get(), &connectionToken);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -807,11 +805,19 @@ QNativeSocketEnginePrivate::QNativeSocketEnginePrivate()
|
|||||||
, closingDown(false)
|
, closingDown(false)
|
||||||
, socketDescriptor(-1)
|
, socketDescriptor(-1)
|
||||||
, sslSocket(Q_NULLPTR)
|
, sslSocket(Q_NULLPTR)
|
||||||
|
, connectionToken( { -1 } )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QNativeSocketEnginePrivate::~QNativeSocketEnginePrivate()
|
QNativeSocketEnginePrivate::~QNativeSocketEnginePrivate()
|
||||||
{
|
{
|
||||||
|
if (socketDescriptor == -1 || connectionToken.value == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (socketType == QAbstractSocket::UdpSocket)
|
||||||
|
udpSocket()->remove_MessageReceived(connectionToken);
|
||||||
|
else if (socketType == QAbstractSocket::TcpSocket)
|
||||||
|
tcpListener->remove_ConnectionReceived(connectionToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QNativeSocketEnginePrivate::setError(QAbstractSocket::SocketError error, ErrorString errorString) const
|
void QNativeSocketEnginePrivate::setError(QAbstractSocket::SocketError error, ErrorString errorString) const
|
||||||
|
@ -210,6 +210,7 @@ private:
|
|||||||
QList<ABI::Windows::Networking::Sockets::IStreamSocket *> currentConnections;
|
QList<ABI::Windows::Networking::Sockets::IStreamSocket *> currentConnections;
|
||||||
QEventLoop eventLoop;
|
QEventLoop eventLoop;
|
||||||
QAbstractSocket *sslSocket;
|
QAbstractSocket *sslSocket;
|
||||||
|
EventRegistrationToken connectionToken;
|
||||||
|
|
||||||
HRESULT handleBindCompleted(ABI::Windows::Foundation::IAsyncAction *, ABI::Windows::Foundation::AsyncStatus);
|
HRESULT handleBindCompleted(ABI::Windows::Foundation::IAsyncAction *, ABI::Windows::Foundation::AsyncStatus);
|
||||||
HRESULT handleNewDatagram(ABI::Windows::Networking::Sockets::IDatagramSocket *socket,
|
HRESULT handleNewDatagram(ABI::Windows::Networking::Sockets::IDatagramSocket *socket,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user