|
@@ -369,7 +369,10 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- deveiceConnId[psp.SourceNumber] = connId;
|
|
|
+ lock (deveiceConnId)
|
|
|
+ {
|
|
|
+ deveiceConnId[psp.SourceNumber] = connId;
|
|
|
+ }
|
|
|
clientInfo.SourceNumber = psp.SourceNumber;
|
|
|
clientInfo.DestNumber = psp.DestNumber;
|
|
|
PSProtocol protocol2;
|
|
@@ -455,9 +458,11 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
|
|
|
if (deveiceConnId != null && deveiceConnId.Count > 0)
|
|
|
{
|
|
|
- //KeyValuePair<string, IntPtr>[] nowDeveiceConnId = new KeyValuePair<string, IntPtr>[deveiceConnId.Count];
|
|
|
- Dictionary<string, IntPtr> nowDeveiceConnId = new Dictionary<string, IntPtr>(deveiceConnId);
|
|
|
- //deveiceConnId.ToArray().CopyTo(nowDeveiceConnId, 0);
|
|
|
+ Dictionary<string, IntPtr> nowDeveiceConnId = new Dictionary<string, IntPtr>();
|
|
|
+ lock (deveiceConnId)
|
|
|
+ {
|
|
|
+ nowDeveiceConnId = new Dictionary<string, IntPtr>(deveiceConnId);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
KeyValuePair<string, IntPtr>[] keyValues = nowDeveiceConnId.ToArray();
|
|
@@ -469,7 +474,10 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
{
|
|
|
if (deveiceConnId.Count > 0 && deveiceConnId.ContainsKey(conn.Key))
|
|
|
{
|
|
|
- deveiceConnId.Remove(conn.Key);
|
|
|
+ lock (deveiceConnId)
|
|
|
+ {
|
|
|
+ deveiceConnId.Remove(conn.Key);
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -619,11 +627,13 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
if (deveiceConnId != null && deveiceConnId.Count > 0)
|
|
|
{
|
|
|
|
|
|
- Dictionary<string, IntPtr> nowDeveiceConnId = new Dictionary<string, IntPtr>(deveiceConnId);
|
|
|
+ Dictionary<string, IntPtr> nowDeveiceConnId = new Dictionary<string, IntPtr>();
|
|
|
+ lock (deveiceConnId)
|
|
|
+ {
|
|
|
+ nowDeveiceConnId = new Dictionary<string, IntPtr>(deveiceConnId);
|
|
|
+ }
|
|
|
|
|
|
KeyValuePair<string, IntPtr>[] keyValues = nowDeveiceConnId.ToArray();
|
|
|
- //nowDeveiceConnId = new KeyValuePair<string, IntPtr>[deveiceConnId.Count];
|
|
|
- //deveiceConnId.ToArray().CopyTo(nowDeveiceConnId , 0);
|
|
|
|
|
|
// 处理设备对应的链接,如果超时则断开链接并移除设备-链接对应关系
|
|
|
foreach (KeyValuePair<string, IntPtr> conn in keyValues)
|
|
@@ -664,7 +674,10 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
{
|
|
|
if (deveiceConnId != null && deveiceConnId.Count > 0 && deveiceConnId.ContainsKey(key))
|
|
|
{
|
|
|
- deveiceConnId.Remove(key);
|
|
|
+ lock (deveiceConnId)
|
|
|
+ {
|
|
|
+ deveiceConnId.Remove(key);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -812,7 +825,6 @@ namespace NB_IOT_TCP_HP_SOCKET
|
|
|
// 处理数据
|
|
|
ClientInfo clientInfo = (ClientInfo)_SendConidQueue.Dequeue();
|
|
|
PSProtocol psp = clientInfo.pSProtocol;
|
|
|
- //clientInfo.NewConnId = deveiceConnId[psp.SourceNumber];
|
|
|
// 原地址
|
|
|
string sourceNumber = psp.SourceNumber;
|
|
|
|