From 88c5644046dffd0c7bde9febc47f348fd73551e1 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 27 Aug 2020 02:57:43 +0200 Subject: [PATCH] Better fix for client notifyDisconnect --- src/dorkbox/network/Client.kt | 14 ++++++++++---- src/dorkbox/network/connection/Connection.kt | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/dorkbox/network/Client.kt b/src/dorkbox/network/Client.kt index c8262eb4..286ef36f 100644 --- a/src/dorkbox/network/Client.kt +++ b/src/dorkbox/network/Client.kt @@ -35,6 +35,7 @@ import dorkbox.network.rmi.RmiManagerConnections import dorkbox.network.rmi.TimeoutException import dorkbox.util.exceptions.SecurityException import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking /** * The client is both SYNC and ASYNC. It starts off SYNC (blocks thread until it's done), then once it's connected to the server, it's @@ -275,10 +276,6 @@ open class Client(config: Configuration = Configuration ClientRejectedException(errorMessage)) } - @Suppress("UNCHECKED_CAST") - newConnection.listenerManager.lazySet(listenerManager as ListenerManager) - - connection = newConnection connections.add(newConnection) @@ -431,9 +428,18 @@ open class Client(config: Configuration = Configuration } override fun close() { + val con = connection connection = null isConnected = false super.close() + + // in the client, "notifyDisconnect" will NEVER be called, because it's only called on a connection! + // manually call it. + if (con != null) { + runBlocking { + listenerManager.notifyDisconnect(con) + } + } } diff --git a/src/dorkbox/network/connection/Connection.kt b/src/dorkbox/network/connection/Connection.kt index 60799419..27a74c60 100644 --- a/src/dorkbox/network/connection/Connection.kt +++ b/src/dorkbox/network/connection/Connection.kt @@ -98,7 +98,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) { } private val endPoint = connectionParameters.endPoint - internal val listenerManager = atomic?>(null) + private val listenerManager = atomic?>(null) val logger = endPoint.logger