|
|
@@ -38,8 +38,6 @@ namespace ETModel
|
|
|
#region 连接相关
|
|
|
// 记录等待连接的channel,10秒后或者第一个消息过来才会从这个dict中删除
|
|
|
private readonly Dictionary<uint, KChannel> waitConnectChannels = new Dictionary<uint, KChannel>();
|
|
|
- private readonly List<uint> connectTimeoutChannels = new List<uint>();
|
|
|
- private uint lastCheckTime;
|
|
|
#endregion
|
|
|
|
|
|
#region 定时器相关
|
|
|
@@ -162,10 +160,9 @@ namespace ETModel
|
|
|
|
|
|
remoteConn = BitConverter.ToUInt32(this.cache, 1);
|
|
|
|
|
|
- // 如果等待连接状态,则重新响应请求
|
|
|
+ // 如果已经收到连接,则忽略
|
|
|
if (this.waitConnectChannels.TryGetValue(remoteConn, out kChannel))
|
|
|
{
|
|
|
- kChannel.HandleAccept(remoteConn);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
@@ -174,8 +171,6 @@ namespace ETModel
|
|
|
this.localConnChannels[kChannel.LocalConn] = kChannel;
|
|
|
this.waitConnectChannels[remoteConn] = kChannel;
|
|
|
|
|
|
- kChannel.HandleAccept(remoteConn);
|
|
|
-
|
|
|
this.OnAccept(kChannel);
|
|
|
|
|
|
break;
|
|
|
@@ -224,6 +219,9 @@ namespace ETModel
|
|
|
// 处理chanel
|
|
|
remoteConn = BitConverter.ToUInt32(this.cache, 1);
|
|
|
localConn = BitConverter.ToUInt32(this.cache, 5);
|
|
|
+
|
|
|
+ this.waitConnectChannels.Remove(remoteConn);
|
|
|
+
|
|
|
kChannel = this.GetKChannel(localConn);
|
|
|
if (kChannel != null)
|
|
|
{
|
|
|
@@ -249,11 +247,6 @@ namespace ETModel
|
|
|
return (KChannel)aChannel;
|
|
|
}
|
|
|
|
|
|
- public void RemoveFromWaitConnectChannels(uint remoteConn)
|
|
|
- {
|
|
|
- this.waitConnectChannels.Remove(remoteConn);
|
|
|
- }
|
|
|
-
|
|
|
public override AChannel GetChannel(long id)
|
|
|
{
|
|
|
if (this.removedChannels.Contains(id))
|
|
|
@@ -309,7 +302,16 @@ namespace ETModel
|
|
|
return;
|
|
|
}
|
|
|
this.removedChannels.Enqueue(id);
|
|
|
- channel.Dispose();
|
|
|
+
|
|
|
+ // 删除channel时检查等待连接状态的字典是否要清除
|
|
|
+ KChannel waitConnectChannel;
|
|
|
+ if (this.waitConnectChannels.TryGetValue(channel.RemoteConn, out waitConnectChannel))
|
|
|
+ {
|
|
|
+ if (waitConnectChannel.LocalConn == channel.LocalConn)
|
|
|
+ {
|
|
|
+ this.waitConnectChannels.Remove(channel.RemoteConn);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#if !SERVER
|
|
|
@@ -329,14 +331,16 @@ namespace ETModel
|
|
|
kv.Value.Update();
|
|
|
}
|
|
|
|
|
|
- while (true)
|
|
|
+ while (this.removedChannels.Count > 0)
|
|
|
{
|
|
|
- if (this.removedChannels.Count <= 0)
|
|
|
+ long id = this.removedChannels.Dequeue();
|
|
|
+ KChannel channel;
|
|
|
+ if (!this.localConnChannels.TryGetValue(id, out channel))
|
|
|
{
|
|
|
- break;
|
|
|
+ continue;
|
|
|
}
|
|
|
- long id = this.removedChannels.Dequeue();
|
|
|
this.localConnChannels.Remove(id);
|
|
|
+ channel.Dispose();
|
|
|
}
|
|
|
}
|
|
|
#else
|
|
|
@@ -360,8 +364,6 @@ namespace ETModel
|
|
|
this.TimeNow = (uint)(TimeHelper.ClientNow() - this.StartTime);
|
|
|
|
|
|
this.Recv();
|
|
|
-
|
|
|
- this.CheckWaitTimeout();
|
|
|
|
|
|
this.TimerOut();
|
|
|
|
|
|
@@ -380,52 +382,16 @@ namespace ETModel
|
|
|
}
|
|
|
this.updateChannels.Clear();
|
|
|
|
|
|
- while (true)
|
|
|
+ while (this.removedChannels.Count > 0)
|
|
|
{
|
|
|
- if (this.removedChannels.Count <= 0)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
long id = this.removedChannels.Dequeue();
|
|
|
- this.localConnChannels.Remove(id);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 2秒钟检查一次, 删除连接成功但是超过10秒还未发第一个消息过来的channel
|
|
|
- private void CheckWaitTimeout()
|
|
|
- {
|
|
|
- if (this.TimeNow - this.lastCheckTime < 2000)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.lastCheckTime = this.TimeNow;
|
|
|
-
|
|
|
- if (this.waitConnectChannels.Count == 0)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.connectTimeoutChannels.Clear();
|
|
|
- foreach (KeyValuePair<uint,KChannel> kv in this.waitConnectChannels)
|
|
|
- {
|
|
|
- if (this.TimeNow - kv.Value.CreateTime < 10000)
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
- this.connectTimeoutChannels.Add(kv.Key);
|
|
|
- }
|
|
|
-
|
|
|
- foreach (uint remoteConn in this.connectTimeoutChannels)
|
|
|
- {
|
|
|
- KChannel kChannel;
|
|
|
- if (!this.waitConnectChannels.TryGetValue(remoteConn, out kChannel))
|
|
|
+ KChannel channel;
|
|
|
+ if (!this.localConnChannels.TryGetValue(id, out channel))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- this.waitConnectChannels.Remove(remoteConn);
|
|
|
- this.Remove(kChannel.LocalConn);
|
|
|
+ this.localConnChannels.Remove(id);
|
|
|
+ channel.Dispose();
|
|
|
}
|
|
|
}
|
|
|
|