From 25fcadcd390a659cfd568c2ba868ca330760d23e Mon Sep 17 00:00:00 2001 From: Elivo Date: Sun, 10 Aug 2025 14:32:04 +0800 Subject: [PATCH] =?UTF-8?q?TcpClient=20=E4=B8=8D=E5=86=8D=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=20timeout=20=E7=9A=84=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apewer/Network/TcpClient.cs | 2 -- Apewer/NetworkUtility.cs | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Apewer/Network/TcpClient.cs b/Apewer/Network/TcpClient.cs index 733a94a..0a42f31 100644 --- a/Apewer/Network/TcpClient.cs +++ b/Apewer/Network/TcpClient.cs @@ -64,12 +64,10 @@ namespace Apewer.Network /// 远程终结点。 /// 连接超时毫秒数。当达到指定时长,或达到系统默认时长时,将会发生超时异常。 /// - /// /// 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); diff --git a/Apewer/NetworkUtility.cs b/Apewer/NetworkUtility.cs index 4f35754..9bf98ed 100644 --- a/Apewer/NetworkUtility.cs +++ b/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)