From 1bdb5d546db7f992e497973e39b9cf4b0912dcb8 Mon Sep 17 00:00:00 2001 From: Robinson Date: Thu, 2 Mar 2023 19:46:08 +0100 Subject: [PATCH] Reconnects during a disconnect are now re-dispatched appropriately --- src/dorkbox/network/Client.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/dorkbox/network/Client.kt b/src/dorkbox/network/Client.kt index e575e5e4..be60c35d 100644 --- a/src/dorkbox/network/Client.kt +++ b/src/dorkbox/network/Client.kt @@ -366,6 +366,21 @@ open class Client( connectionTimeoutSec: Int = 30, reliable: Boolean = true) { + // NOTE: We CAN have a 'connect' inside the 'disconnect' callback (as a reconnect feature). THIS WILL CAUSE PROBLEMS! + // there can ALSO be recursion problems, so we must address that. + if (eventDispatch.isCurrent && !eventDispatch.wasForced) { + logger.trace { "Redispatching a connect request!" } + eventDispatch.forceLaunch { + connect(remoteAddress, + remoteAddressString, + remoteAddressPrettyString, + ipcId, + connectionTimeoutSec, + reliable) + } + return + } + // NOTE: it is critical to remember that Aeron DOES NOT like running from coroutines! config as ClientConfiguration