Fixed server.onDisconnect() listener notification.

This commit is contained in:
Robinson 2022-03-15 14:33:58 +01:00
parent 04fa453ff3
commit 29d63a4268
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C

View File

@ -20,7 +20,11 @@ import dorkbox.network.ServerConfiguration
import dorkbox.network.aeron.AeronDriver
import dorkbox.network.aeron.IpcMediaDriverConnection
import dorkbox.network.aeron.UdpMediaDriverPairedConnection
import dorkbox.network.connection.*
import dorkbox.network.connection.Connection
import dorkbox.network.connection.ConnectionParams
import dorkbox.network.connection.ListenerManager
import dorkbox.network.connection.PublicKeyValidationState
import dorkbox.network.connection.eventLoop
import dorkbox.network.exceptions.AllocationException
import dorkbox.network.rmi.RmiManagerConnections
import io.aeron.Publication
@ -31,7 +35,7 @@ import net.jodah.expiringmap.ExpirationPolicy
import net.jodah.expiringmap.ExpiringMap
import java.net.Inet4Address
import java.net.InetAddress
import java.util.concurrent.TimeUnit
import java.util.concurrent.*
/**
@ -108,6 +112,16 @@ internal class ServerHandshake<CONNECTION : Connection>(logger: KLogger,
} else {
logger.trace { "[${pendingConnection.id}] Connection from client $connectionString done with handshake." }
pendingConnection.postCloseAction = {
// this is called whenever connection.close() is called by the framework or via client.close()
// this always has to be on event dispatch, otherwise we can have weird logic loops if we reconnect within a disconnect callback
actionDispatch.eventLoop {
listenerManager.notifyDisconnect(pendingConnection)
}
}
// this enables the connection to start polling for messages
server.addConnection(pendingConnection)
@ -313,7 +327,7 @@ internal class ServerHandshake<CONNECTION : Connection>(logger: KLogger,
successMessage.publicKey = server.crypto.publicKeyBytes
// before we notify connect, we have to wait for the client to tell us that they can receive data
pendingConnections.put(sessionId, connection)
pendingConnections[sessionId] = connection
// this tells the client all of the info to connect.
server.writeHandshakeMessage(handshakePublication, successMessage) // exception is already caught!
@ -491,7 +505,7 @@ internal class ServerHandshake<CONNECTION : Connection>(logger: KLogger,
successMessage.publicKey = server.crypto.publicKeyBytes
// before we notify connect, we have to wait for the client to tell us that they can receive data
pendingConnections.put(sessionId, connection)
pendingConnections[sessionId] = connection
// this tells the client all of the info to connect.
server.writeHandshakeMessage(handshakePublication, successMessage) // exception is already caught