完善因对象已被销毁不能访问的问题

This commit is contained in:
SpringHgui 2019-12-16 21:29:17 +08:00
parent 02780363c8
commit cff0ba7cc8

View File

@ -44,18 +44,18 @@ namespace FastTunnel.Core
private void swapCallback(object state)
{
var chanel = state as Channel;
byte[] result = new byte[1024];
while (true)
{
try
{
byte[] result = new byte[1024];
if (!chanel.Receive.Connected)
break;
int num = chanel.Receive.Receive(result, result.Length, SocketFlags.None);
if (num == 0)
{
if (chanel.Send.Connected)
{
chanel.Send.Close();
}
if (chanel.Receive.Connected)
{
chanel.Receive.Close();
@ -63,19 +63,18 @@ namespace FastTunnel.Core
break;
}
if (!chanel.Send.Connected)
break;
chanel.Send.Send(result, num, SocketFlags.None);
}
catch (SocketException)
{
if (chanel.Send.Connected)
chanel.Send.Close();
if (chanel.Receive.Connected)
chanel.Receive.Close();
break;
}
catch (Exception)
{
throw;
if (chanel.Receive.Connected)
chanel.Receive.Close();
if (chanel.Send.Connected)
chanel.Send.Close();
break;
}
}
}