Browse Source

TcpClient 不再检查 timeout 的范围

master
王厅 3 weeks ago
parent
commit
25fcadcd39
  1. 2
      Apewer/Network/TcpClient.cs
  2. 8
      Apewer/NetworkUtility.cs

2
Apewer/Network/TcpClient.cs

@ -64,12 +64,10 @@ namespace Apewer.Network
/// <param name="endpoint">远程终结点。</param>
/// <param name="timeout">连接超时毫秒数。当达到指定时长,或达到系统默认时长时,将会发生超时异常。</param>
/// <exception cref="ArgumentNullException" />
/// <exception cref="ArgumentOutOfRangeException" />
/// <exception cref="SocketException" />
public TcpClient(IPEndPoint endpoint, int timeout)
{
if (endpoint == null) throw new ArgumentNullException(nameof(endpoint));
if (timeout < 1) throw new ArgumentOutOfRangeException(nameof(timeout));
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_socket.Connect(endpoint, timeout);

8
Apewer/NetworkUtility.cs

@ -606,7 +606,13 @@ namespace Apewer
{
if (socket == null) throw new ArgumentNullException(nameof(socket));
if (endpoint == null) throw new ArgumentNullException(nameof(endpoint));
if (timeout < 1) throw new ArgumentOutOfRangeException(nameof(timeout));
// 不指定超时
if (timeout < 1)
{
socket.Connect(endpoint);
return;
}
var connecting = true;
if (timeout > 0)

Loading…
Cancel
Save