@@ -96,10 +96,7 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector<H : NetworkHandl
96
96
* 只有 [NetworkException] 是期望的异常 (根据 [NetworkException.recoverable] 决定是否可挽救). 任何其他异常都是未期望的, 将会被原封不动地抛出.
97
97
*/
98
98
@Throws(
99
- NetworkException ::class ,
100
- MaxAttemptsReachedException ::class ,
101
- CancellationException ::class ,
102
- Throwable ::class
99
+ NetworkException ::class , MaxAttemptsReachedException ::class , CancellationException ::class , Throwable ::class
103
100
)
104
101
suspend fun run (): H {
105
102
return try {
@@ -127,9 +124,8 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector<H : NetworkHandl
127
124
// == false 表示第一次登录失败, 且此失败没必要重试
128
125
logIfEnabled { " [FIRST LOGIN ERROR] current = $current " }
129
126
logIfEnabled { " [FIRST LOGIN ERROR] current.state = ${current.state} " }
130
- throw current.getLastFailure()
131
- ? : exceptionCollector.getLast()
132
- ? : error(" Failed to login with unknown reason." )
127
+ throw current.getLastFailure() ? : exceptionCollector.getLast()
128
+ ? : error(" Failed to login with unknown reason." )
133
129
}
134
130
}
135
131
@@ -201,13 +197,18 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector<H : NetworkHandl
201
197
attempted + = 1
202
198
runImpl() // will create new instance (see the `else` branch).
203
199
}
204
- NetworkHandler .State .CONNECTING ,
205
- NetworkHandler .State .INITIALIZED ,
206
- -> {
200
+ NetworkHandler .State .INITIALIZED -> {
207
201
if (! current.resumeInstanceCatchingException()) {
208
202
attempted + = 1
203
+ return runImpl()
209
204
}
210
- return runImpl()
205
+ logIfEnabled { " RETURN" }
206
+ return current
207
+ }
208
+ NetworkHandler .State .CONNECTING -> {
209
+ logIfEnabled { " RETURN" }
210
+ // can send packet
211
+ return current
211
212
}
212
213
NetworkHandler .State .LOADING -> {
213
214
logIfEnabled { " RETURN" }
@@ -243,8 +244,7 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector<H : NetworkHandl
243
244
companion object {
244
245
var DEFAULT_MAX_ATTEMPTS by atomic(
245
246
systemProp(
246
- " mirai.network.handler.selector.max.attempts" ,
247
- Long .MAX_VALUE
247
+ " mirai.network.handler.selector.max.attempts" , Long .MAX_VALUE
248
248
).coerceIn(1 .. Int .MAX_VALUE .toLongUnsigned()).toInt()
249
249
)
250
250
0 commit comments