v4.3.1
更新日期: 2026.8.9
更新描述:
- ReconnectionOption 新增 OnLog 统一回调:新增
OnLog异步日志回调,统一重连成功/失败/放弃事件通知;旧三个回调保持兼容。 - 新增 TouchSocket.Redis 模块:全新 Redis 客户端/服务端实现,支持 RESP 协议,内置内存数据库及常用命令。
更新详情:
TouchSocket
-
ReconnectionLogType枚举,包含Failed(重连失败)、GiveUp(放弃重连)、Success(重连成功)三个值。 -
ReconnectionLogEventArgs类,包含Type(日志类型)、Attempts(当前尝试次数)、MaxRetryCount(最大重连次数)、Message(日志消息)、Exception(可选异常)属性。 -
ReconnectionOption<TClient>.OnLog(Func<TClient, ReconnectionLogEventArgs, Task>)属性,统一异步重连日志回调;默认实现转调旧的OnFailed/OnGiveUp/OnSuccessed,重新赋值后旧三个回调不再被自动调用。 -
ReconnectionPlugin内部将三处回调调用(成功/失败/放弃)统一重构为调用InvokeReconnectionLogAsync,通过OnLog统一分发。
TouchSocket.Redis(新模块)
-
IRedisSession接口,定义SendRedisValueAsync发送 RESP 值方法。 -
IRedisClient接口,继承IRedisSession,新增ConnectAsync和ExecuteAsync方法,表示完整 Redis 客户端契约。 -
RedisValueKind枚举,定义 RESP 协议值类型:Null、SimpleString、Error、Integer、BulkString、Array。 -
RedisValue类,实现 RESP 值的构造、序列化与解析,提供Command、BulkStringValue、IntegerValue、Error、SimpleString等工厂方法。 -
RedisClient类,继承TcpClientBase实现IRedisClient,内置请求/响应队列,支持并发命令执行及自动 AUTH 认证。 -
RedisService类,继承TcpServiceBase<RedisSessionClient>,内置RedisDatabase内存数据库及RedisCommandProcessor命令处理器,提供兼容 Redis 协议的 TCP 服务端。 -
RedisSessionClient类,实现IRedisSession,负责服务端会话的 RESP 接收与响应、AUTH 认证及插件派发。 -
RedisDatabase类,基于内存的 Redis 数据库,支持 String(GET/SET/DEL/EXISTS/INCR/DECR/MGET/MSET/EXPIRE/TTL/KEYS)、List(LPUSH/RPUSH/LLEN/LRANGE)、SortedSet(ZADD/ZCARD/ZREM)数据结构。 -
RedisCommandProcessor类,处理 RESP 命令分发,内置 PING、ECHO、QUIT、SELECT、AUTH、DBSIZE、FLUSHDB 及全部上述数据结构命令,支持继承扩展。 -
RedisClientOption配置类,包含UserName、Password属性,为空密码时使用旧式 AUTH 认证。 -
RedisServerOption配置类,包含UserName、Password、AcceptSelectCommand属性,控制服务端认证与 SELECT 命令支持。 -
RedisConfigExtension,提供SetRedisClientOption/SetRedisServerOption配置扩展依赖属性。 -
RedisClientExtension,提供PingAsync、EchoAsync、QuitAsync、GetStringAsync、GetBytesAsync、SetAsync、ExecuteForStringResultAsync、ExecuteForLongResultAsync、ExecuteForStringArrayResultAsync、ExecuteForMemoryResultAsync等常用命令扩展方法。 -
IRedisReceivedPlugin插件接口,支持在服务端接收到 RESP 值时通过插件系统派发OnRedisReceived事件。 -
RedisReconnectionOptionsExtension.UseRedisCheckAction<TClient>扩展方法,为ReconnectionOption<TClient>配置 Redis PING 心跳检测,支持自定义活动时间间隔与 PING 间隔。
v4.3.0
更新日期: 2026.8.1
更新描述:
- 发送接口升级分段序列:
ISender、IIdSender、IUdpClientSender核心发送接口参数由ReadOnlyMemory<byte>升级为ReadOnlySequence<byte>,支持零拷贝分段发送。⚠️ 破坏性变更 - SendInput 升级为分段序列:
SingleStreamDataHandlingAdapter.SendInput参数升级为ReadOnlySequence<byte>。⚠️ 破坏性变更 - 新增 Memory 兼容扩展方法:
SenderExtension新增ReadOnlyMemory<byte>重载,向下兼容旧调用。 - HTTP 新增流式表单读取:新增
IStreamingFormReader、IStreamFormSection接口及GetStreamingFormReader扩展方法,支持流式读取表单,不加载整体请求体。 - McpHttpCallContext 暴露 HTTP 上下文:实现
IMcpHttpCallContext,新增HttpContext、HttpSessionClient属性。
更新详情:
TouchSocket.Core
-
SingleStreamDataHandlingAdapter.SendInput<TWriter>参数由in ReadOnlyMemory<byte> memory升级为in ReadOnlySequence<byte> sequence,默认实现遍历分段逐段写入,子类如需覆盖需同步更新签名。⚠️ 破坏性变更 -
FixedHeaderPackageAdapter.SendInput<TWriter>参数同步升级为ReadOnlySequence<byte>,长度计算改用checked((int)sequence.Length)防溢出,数据写入改为逐分段循环写入。 -
FixedSizePackageAdapter.SendInput<TWriter>参数同步升级为ReadOnlySequence<byte>,长度验证使用sequence.Length。 -
TerminatorPackageAdapter.SendInput<TWriter>参数同步升级为ReadOnlySequence<byte>,数据写入改为逐分段写入后追加终止符。
TouchSocket
-
ISender.SendAsync、IIdSender.SendAsync、IUdpClientSender.SendAsync接口方法签名统一由ReadOnlyMemory<byte>升级为ReadOnlySequence<byte>,支持分段只读序列直接发送。⚠️ 破坏性变更 -
SenderExtension新增三组ReadOnlyMemory<byte>重载扩展方法(对应ISender/IIdSender/IUdpClientSender),内部包装为ReadOnlySequence<byte>后转发,保持旧调用代码兼容。 - TCP/UDP/KCP/NatTarget 全系组件(
TcpClient、TcpSessionClient、TcpService<TClient>、UdpSession、KcpClient、KcpSessionClient、NatTargetClient)统一新增SendAsync(ReadOnlySequence<byte>, CancellationToken)公共方法,服务端同步新增按 Id 分段发送重载。
TouchSocket.NamedPipe
-
NamedPipeClient.SendAsync(ReadOnlySequence<byte>, CancellationToken)方法,委托至ProtectedSendAsync。 -
NamedPipeSessionClient.SendAsync(ReadOnlySequence<byte>, CancellationToken)和SendAsync(string, ReadOnlySequence<byte>, CancellationToken)方法。 -
NamedPipeService<TClient>.SendAsync(string, ReadOnlySequence<byte>, CancellationToken)方法,通过 Id 查找客户端后转发。
TouchSocket.SerialPorts
-
SerialPortClient.SendAsync(ReadOnlySequence<byte>, CancellationToken)方法,委托至ProtectedSendAsync。
TouchSocket.Http
-
IStreamingFormReader接口及GetStreamingFormReader<TRequest>扩展方法,支持流式拉取multipart/form-data或application/x-www-form-urlencoded表单数据,无论文件大小均不将请求体整体加载至内存。 -
IStreamFormSection接口,表示单个表单段,包含Name、FileName、IsFile、ContentType、DataPair等属性,以及ReadAsync/CopyToAsync/ReadAsStringAsync等流式读取方法。
TouchSocket.Mcp
-
IMcpHttpCallContext接口,定义HttpContext(HttpContext)和HttpSessionClient(IHttpSessionClient)属性,供 HTTP 传输场景访问请求上下文。 -
McpHttpCallContext实现IMcpHttpCallContext接口,构造函数新增HttpContext httpContext参数并存储到同名属性;同时暴露HttpSessionClient属性,对外提供当前 HTTP 会话客户端引用。