Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
737069c
refactor: 重构代码
ArgoZhang Sep 13, 2025
62df305
doc: 更新 readme 文档
ArgoZhang Sep 13, 2025
33c4aef
chore: 更新 xml 配置文件
ArgoZhang Sep 13, 2025
c14fa7e
refactor: 删除 SendState 状态类
ArgoZhang Sep 13, 2025
687a603
refactor: 移除 UnsupportedOSPlatform 方法
ArgoZhang Sep 14, 2025
1d560bb
Merge branch 'master' into perf
ArgoZhang Sep 14, 2025
7c00c37
refactor: Sender 重构
ArgoZhang Sep 14, 2025
f299875
refactor: 重构 factory
ArgoZhang Sep 14, 2025
01bc4f5
chore: 更新依赖
ArgoZhang Sep 14, 2025
de50ccb
refactor: 精简代码
ArgoZhang Sep 14, 2025
985d294
refactor: 更改构造方法
ArgoZhang Sep 14, 2025
7827e3a
feat: 移除 EnableLog 设置
ArgoZhang Sep 15, 2025
7b223b1
feat: 增加 ThrowIfNotConnected 扩展
ArgoZhang Sep 15, 2025
c84eff0
refactor: 增加 TcpSocketClientOptions 扩展方法
ArgoZhang Sep 15, 2025
37cc0d8
refactor: 精简代码功能代码下沉
ArgoZhang Sep 15, 2025
3f5b9a8
refactor: DefaultTcpSocketClient 参数重构
ArgoZhang Sep 15, 2025
fc33029
doc: 更新注释
ArgoZhang Sep 15, 2025
b7cf796
refactor: 精简 Receiver 代码
ArgoZhang Sep 15, 2025
6b1450e
feat: 更改 ReceiveAsync 接口
ArgoZhang Sep 15, 2025
ed8206d
refactor: 增加 Options 属性
ArgoZhang Sep 15, 2025
9d91c0b
refactor: 更新 Options 参数
ArgoZhang Sep 15, 2025
b0774a2
refactor: 更改顺序
ArgoZhang Sep 15, 2025
fc08abc
refactor: 移除 Options 属性
ArgoZhang Sep 15, 2025
2245b89
refactor: 更新代码
ArgoZhang Sep 15, 2025
153a5b7
fix: 增加是否连接返回值
ArgoZhang Sep 15, 2025
ce65913
test: 更新单元测试
ArgoZhang Sep 15, 2025
f4e1400
test: 更新单元测试
ArgoZhang Sep 15, 2025
39978db
chore: 更新依赖
ArgoZhang Sep 15, 2025
01b1a96
refactor: 移除 ITcpSocketClientProvider 精简代码
ArgoZhang Sep 15, 2025
fb53d5a
test: 更新单元测试
ArgoZhang Sep 15, 2025
3ba6e82
test: 更新单元测试
ArgoZhang Sep 15, 2025
d6934b8
chore: bump version 9.0.8
ArgoZhang Sep 15, 2025
1bb0b01
chore: 更新更新依赖包
ArgoZhang Sep 15, 2025
dbc1b37
refactor: 增加配置 Options 逻辑
ArgoZhang Sep 15, 2025
8ad109f
refactor: 增加 Callback 回调防止死锁
ArgoZhang Sep 15, 2025
3a96781
refactor: 移动数据适配器到接口 ITcpSocketClient
ArgoZhang Sep 16, 2025
448bd56
test: 精简单元测试
ArgoZhang Sep 16, 2025
c1c5c14
refactor: 删除不需要的单元测试
ArgoZhang Sep 16, 2025
5a7a50f
refactor: 移动适配器相关代码到扩展方法中
ArgoZhang Sep 16, 2025
3e8cd64
test: 删除冗余单元测试
ArgoZhang Sep 16, 2025
ed3e0a9
test: 增加 SendAsync 单元测试覆盖率
ArgoZhang Sep 16, 2025
180dc67
refactor: 移除 ConfigureDataConverters 方法
ArgoZhang Sep 16, 2025
6080923
chore: 更新依赖版本 9.0.3
ArgoZhang Sep 16, 2025
0aef9d6
test: 精简单元测试
ArgoZhang Sep 16, 2025
372e0a4
fix: 修复 Callback 未释放问题
ArgoZhang Sep 16, 2025
6b64e2e
feat: 增加连接超时逻辑
ArgoZhang Sep 16, 2025
47e3d5a
test: 增加单元测试
ArgoZhang Sep 16, 2025
60e6b2f
feat: 增加连接超时功能
ArgoZhang Sep 16, 2025
f162258
test: 增加单元测试
ArgoZhang Sep 16, 2025
d9b85bb
feat: 重构 GetOrCreate 方法
ArgoZhang Sep 16, 2025
b682e46
test: 更新单元测试
ArgoZhang Sep 16, 2025
8019a1a
test: 增加接收取消单元测试
ArgoZhang Sep 16, 2025
09f6ec0
test: 增加单元测试
ArgoZhang Sep 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 95 additions & 144 deletions src/Longbow.TcpSocket/Extensions/ITcpSocketClientExtensions.cs

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions src/Longbow.TcpSocket/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,20 @@ public static class ServiceCollectionExtensions
/// 增加 ITcpSocketFactory 服务
/// </summary>
/// <param name="services"></param>
/// <param name="configureOptions"></param>
/// <returns></returns>
[UnsupportedOSPlatform("browser")]
public static IServiceCollection AddTcpSocketFactory(this IServiceCollection services)
public static IServiceCollection AddTcpSocketFactory(this IServiceCollection services, Action<TcpSocketClientOptions>? configureOptions = null)
{
// 添加 ITcpSocketFactory 服务
services.TryAddSingleton<ITcpSocketFactory, DefaultTcpSocketFactory>();

// 增加 ISocketClientProvider 服务
services.TryAddTransient<ITcpSocketClientProvider, DefaultTcpSocketClientProvider>();
services.TryAddTransient<ITcpSocketClient, DefaultTcpSocketClient>();

return services;
}
// 增加全局配置
services.Configure<TcpSocketClientOptions>(op => configureOptions?.Invoke(op));

/// <summary>
/// 配置第三方数据模型与 <see cref="DataConverterCollection"/> 数据转换器集合配置扩展方法
/// </summary>
/// <param name="services"></param>
/// <param name="configureOptions"></param>
/// <returns></returns>
public static IServiceCollection ConfigureDataConverters(this IServiceCollection services, Action<DataConverterCollection> configureOptions)
{
services.Configure(configureOptions);
return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Argo Zhang (argo@live.ca). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://github.com/LongbowExtensions/

namespace Longbow.TcpSocket;

static class TcpSocketClientOptionsExtensions
{
public static TcpSocketClientOptions CopyTo(this TcpSocketClientOptions source) => new()
{
ReceiveBufferSize = source.ReceiveBufferSize,
IsAutoReceive = source.IsAutoReceive,
ConnectTimeout = source.ConnectTimeout,
SendTimeout = source.SendTimeout,
ReceiveTimeout = source.ReceiveTimeout,
LocalEndPoint = source.LocalEndPoint,
IsAutoReconnect = source.IsAutoReconnect,
ReconnectInterval = source.ReconnectInterval,
NoDelay = source.NoDelay
};
}
4 changes: 0 additions & 4 deletions src/Longbow.TcpSocket/Extensions/TcpSocketUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.Net;
using System.Net.Sockets;
using System.Runtime.Versioning;

namespace Longbow.TcpSocket;

Expand All @@ -27,7 +26,6 @@ public static class TcpSocketUtility
/// string as an IP address or resolve it as a hostname.</param>
/// <returns>An <see cref="IPAddress"/> object representing the parsed or resolved IP address. If the input cannot be parsed
/// or resolved, the method returns a default IP address.</returns>
[UnsupportedOSPlatform("browser")]
public static IPAddress ConvertToIPAddress(string ipString)
{
if (string.IsNullOrEmpty(ipString))
Expand All @@ -48,7 +46,6 @@ public static IPAddress ConvertToIPAddress(string ipString)
}

[ExcludeFromCodeCoverage]
[UnsupportedOSPlatform("browser")]
private static IPAddress IPAddressByHostName => Dns.GetHostAddresses(Dns.GetHostName(), AddressFamily.InterNetwork).FirstOrDefault() ?? IPAddress.Any;

/// <summary>
Expand All @@ -59,7 +56,6 @@ public static IPAddress ConvertToIPAddress(string ipString)
/// <param name="port">The port number associated with the endpoint. Must be between 0 and 65535.</param>
/// <returns>An <see cref="IPEndPoint"/> representing the specified IP address and port.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="port"/> is less than 0 or greater than 65535.</exception>
[UnsupportedOSPlatform("browser")]
public static IPEndPoint ConvertToIpEndPoint(string ipString, int port)
{
if (port < 0 || port > 65535)
Expand Down
Loading
Loading