提交 f879380a 编写于 作者: D dwx666

优化TCP重连的策略

上级 a4b57848
......@@ -37,6 +37,7 @@ namespace TouchSocket.Core.Plugins
public static IPluginsManager UseReconnection(this IPluginsManager pluginsManager, int tryCount = 10,
bool printLog = false, int sleepTime = 1000, Action<ITcpClient> successCallback = null)
{
bool first = true;
var reconnectionPlugin = new ReconnectionPlugin<ITcpClient>(client=>
{
int tryT = tryCount;
......@@ -50,9 +51,11 @@ namespace TouchSocket.Core.Plugins
}
else
{
if (first) Thread.Sleep(1000);
first = false;
client.Connect();
first = true;
}
successCallback?.Invoke(client);
return true;
}
......@@ -85,6 +88,7 @@ namespace TouchSocket.Core.Plugins
Func<ITcpClient,int,Exception,bool> failCallback=null,
Action<ITcpClient> successCallback = null)
{
bool first = true;
var reconnectionPlugin = new ReconnectionPlugin<ITcpClient>(client =>
{
int tryT = 0;
......@@ -98,7 +102,10 @@ namespace TouchSocket.Core.Plugins
}
else
{
if (first) Thread.Sleep(1000);
first = false;
client.Connect();
first = true;
}
successCallback?.Invoke(client);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册