Better fix for client notifyDisconnect
This commit is contained in:
parent
eceb9bbcee
commit
88c5644046
|
@ -35,6 +35,7 @@ import dorkbox.network.rmi.RmiManagerConnections
|
||||||
import dorkbox.network.rmi.TimeoutException
|
import dorkbox.network.rmi.TimeoutException
|
||||||
import dorkbox.util.exceptions.SecurityException
|
import dorkbox.util.exceptions.SecurityException
|
||||||
import kotlinx.coroutines.launch
|
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
|
* 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<CONNECTION : Connection>(config: Configuration = Configuration
|
||||||
ClientRejectedException(errorMessage))
|
ClientRejectedException(errorMessage))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
newConnection.listenerManager.lazySet(listenerManager as ListenerManager<Connection>)
|
|
||||||
|
|
||||||
|
|
||||||
connection = newConnection
|
connection = newConnection
|
||||||
connections.add(newConnection)
|
connections.add(newConnection)
|
||||||
|
|
||||||
|
@ -431,9 +428,18 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
|
val con = connection
|
||||||
connection = null
|
connection = null
|
||||||
isConnected = false
|
isConnected = false
|
||||||
super.close()
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ open class Connection(connectionParameters: ConnectionParams<*>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private val endPoint = connectionParameters.endPoint
|
private val endPoint = connectionParameters.endPoint
|
||||||
internal val listenerManager = atomic<ListenerManager<Connection>?>(null)
|
private val listenerManager = atomic<ListenerManager<Connection>?>(null)
|
||||||
|
|
||||||
val logger = endPoint.logger
|
val logger = endPoint.logger
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user