chore: 调整 goaway 处理逻辑

oneRain 2020-06-23 18:37:09 +08:00
parent d5879d777a
commit b353bf5536
3 changed files with 3 additions and 27 deletions

View File

@ -123,6 +123,7 @@ namespace LeanCloud.Realtime.Internal.Connection {
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
internal async Task Reset() { internal async Task Reset() {
state = State.Closed;
heartBeat?.Stop(); heartBeat?.Stop();
// 关闭就连接 // 关闭就连接
await ws.Close(); await ws.Close();
@ -205,6 +206,8 @@ namespace LeanCloud.Realtime.Internal.Connection {
} else { } else {
if (command.Cmd == CommandType.Echo) { if (command.Cmd == CommandType.Echo) {
heartBeat.Pong(); heartBeat.Pong();
} else if (command.Cmd == CommandType.Goaway) {
_ = Reset();
} else { } else {
// 通知 // 通知
if (idToClients.TryGetValue(command.PeerId, out LCIMClient client)) { if (idToClients.TryGetValue(command.PeerId, out LCIMClient client)) {

View File

@ -1,19 +0,0 @@
using System.Threading.Tasks;
using LeanCloud.Realtime.Internal.Protocol;
namespace LeanCloud.Realtime.Internal.Controller {
internal class LCIMGoAwayController : LCIMController {
internal LCIMGoAwayController(LCIMClient client) : base(client) {
}
#region 消息处理
internal override void HandleNotification(GenericCommand notification) {
// 清空缓存,断开连接,等待重新连接
_ = Connection.Reset();
}
#endregion
}
}

View File

@ -240,10 +240,6 @@ namespace LeanCloud.Realtime {
get; private set; get; private set;
} }
internal LCIMGoAwayController GoAwayController {
get; private set;
}
internal LCIMConversationController ConversationController { internal LCIMConversationController ConversationController {
get; private set; get; private set;
} }
@ -290,7 +286,6 @@ namespace LeanCloud.Realtime {
SessionController = new LCIMSessionController(this); SessionController = new LCIMSessionController(this);
ConversationController = new LCIMConversationController(this); ConversationController = new LCIMConversationController(this);
MessageController = new LCIMMessageController(this); MessageController = new LCIMMessageController(this);
GoAwayController = new LCIMGoAwayController(this);
} }
/// <summary> /// <summary>
@ -451,9 +446,6 @@ namespace LeanCloud.Realtime {
case CommandType.Rcp: case CommandType.Rcp:
MessageController.HandleNotification(notification); MessageController.HandleNotification(notification);
break; break;
case CommandType.Goaway:
GoAwayController.HandleNotification(notification);
break;
default: default:
break; break;
} }