From 035085cf4596355ddbbaf24622237445ede5d1c5 Mon Sep 17 00:00:00 2001
From: Him188 <Him188@mamoe.net>
Date: Thu, 22 Apr 2021 12:24:15 +0800
Subject: [PATCH] Remove state CONNECTION_LOST

---
 .../kotlin/network/handler/NetworkHandler.kt   |  9 ---------
 .../AbstractKeepAliveNetworkHandlerSelector.kt |  1 -
 .../network/impl/netty/NettyNetworkHandler.kt  | 18 ------------------
 3 files changed, 28 deletions(-)

diff --git a/mirai-core/src/commonMain/kotlin/network/handler/NetworkHandler.kt b/mirai-core/src/commonMain/kotlin/network/handler/NetworkHandler.kt
index adf3cb0d1..d04a69368 100644
--- a/mirai-core/src/commonMain/kotlin/network/handler/NetworkHandler.kt
+++ b/mirai-core/src/commonMain/kotlin/network/handler/NetworkHandler.kt
@@ -72,15 +72,6 @@ internal interface NetworkHandler {
          */
         OK,
 
-        /**
-         * No Internet Connection available or for any other reasons
-         * but it is possible to establish a connection again(switching state to [CONNECTING]).
-         *
-         * At this state [resumeConnection] turns the handle to [CONNECTING].
-         * [sendAndExpect] throws [IllegalStateException]
-         */
-        CONNECTION_LOST,
-
         /**
          * Cannot resume anymore. Both [resumeConnection] and [sendAndExpect] throw a [CancellationException].
          *
diff --git a/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt b/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt
index 972620f29..25d22842b 100644
--- a/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt
+++ b/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt
@@ -47,7 +47,6 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector<H : NetworkHandl
                     this.current.compareAndSet(current, null) // invalidate the instance and try again.
                     awaitResumeInstance() // will create new instance.
                 }
-                NetworkHandler.State.CONNECTION_LOST,
                 NetworkHandler.State.CONNECTING,
                 NetworkHandler.State.INITIALIZED -> {
                     current.resumeConnection()
diff --git a/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt
index 141eea41e..dbe11e117 100644
--- a/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt
+++ b/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt
@@ -317,24 +317,6 @@ internal class NettyNetworkHandler(
         override fun toString(): String = "StateOK"
     }
 
-    private inner class StateConnectionLost(
-        private val cause: Throwable?
-    ) : NettyState(State.CONNECTION_LOST) {
-        override fun getCause(): Throwable? = cause
-
-        override suspend fun sendPacketImpl(packet: OutgoingPacket) {
-            throw IllegalStateException(
-                "Internal error: connection is lost so cannot send packet. Call resumeConnection first.",
-                cause
-            )
-        }
-
-        override suspend fun resumeConnection0() {
-            setState { StateConnecting(ExceptionCollector(cause)) }
-                .resumeConnection()
-        } // noop
-    }
-
     private inner class StateClosed(
         val exception: Throwable?
     ) : NettyState(State.CLOSED) {