From 3733c54b18e1c0ee6c7350ba92b4fc06660ac239 Mon Sep 17 00:00:00 2001 From: Carywang Date: Tue, 29 Oct 2024 12:05:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9ATouchSocket=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Tcp/TcpServiceController.cs | 6 +- .../Handlers/Tcp/TcpServicePlugin.cs | 16 +-- backend/Magic.Web.Core/Magic.Web.Core.csproj | 6 +- backend/Magic.Web.Core/Magic.Web.Core.xml | 120 +++++++++++++++++- 4 files changed, 130 insertions(+), 18 deletions(-) diff --git a/backend/Magic.Web.Core/Controller/Tcp/TcpServiceController.cs b/backend/Magic.Web.Core/Controller/Tcp/TcpServiceController.cs index 217e4a8..cb38062 100644 --- a/backend/Magic.Web.Core/Controller/Tcp/TcpServiceController.cs +++ b/backend/Magic.Web.Core/Controller/Tcp/TcpServiceController.cs @@ -40,14 +40,14 @@ namespace Magic.Web.Core /// /// [HttpPost] - public void SendMessage(string id,[FromBody]string msg) + public async Task SendMessage(string id, [FromBody] string msg) { - if (!this.m_tcpService.TryGetSocketClient(id,out var socketClient)) + if (!this.m_tcpService.TryGetClient(id, out var socketClient)) { throw new Exception("没有找到对于Id的客户端"); } - socketClient.Send(msg); + await socketClient.SendAsync(msg); } } } diff --git a/backend/Magic.Web.Core/Handlers/Tcp/TcpServicePlugin.cs b/backend/Magic.Web.Core/Handlers/Tcp/TcpServicePlugin.cs index b45103a..8b85460 100644 --- a/backend/Magic.Web.Core/Handlers/Tcp/TcpServicePlugin.cs +++ b/backend/Magic.Web.Core/Handlers/Tcp/TcpServicePlugin.cs @@ -18,24 +18,24 @@ namespace Magic.Web.Core.Handlers.Tcp this.m_logger = logger; } - [GeneratorPlugin(nameof(ITcpConnectedPlugin.OnTcpConnected))] - public async Task OnTcpConnected(ITcpClientBase client, ConnectedEventArgs e) + [GeneratorPlugin(typeof(ITcpConnectedPlugin))] + public async Task OnTcpConnected(ITcpSession client, ConnectedEventArgs e) { m_logger.LogInformation("Tcp客户端已连接。信息:{0}", client.GetIPPort()); await e.InvokeNext(); } - [GeneratorPlugin(nameof(ITcpDisconnectedPlugin.OnTcpDisconnected))] - public async Task OnTcpDisconnected(ITcpClientBase client, DisconnectEventArgs e) + [GeneratorPlugin(typeof(ITcpClosedPlugin))] + public async Task OnTcpClosed(ITcpSession client, ClosedEventArgs e) { - m_logger.LogInformation("Tcp客户端已断开。信息:{0},断开信息:{1}", client.GetIPPort(),e.Message); + m_logger.LogInformation("Tcp客户端已断开。信息:{0},断开信息:{1}", client.GetIPPort(), e.Message); await e.InvokeNext(); } - [GeneratorPlugin(nameof(ITcpReceivedPlugin.OnTcpReceived))] - public async Task OnTcpReceived(ITcpClientBase client, ReceivedDataEventArgs e) + [GeneratorPlugin(typeof(ITcpReceivedPlugin))] + public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e) { - m_logger.LogInformation("Tcp收到信息:{0}", Encoding.UTF8.GetString(e.ByteBlock.ToArray())); + m_logger.LogInformation("Tcp收到信息:{0}", e.ByteBlock.Span.ToString(Encoding.UTF8)); await e.InvokeNext(); } } diff --git a/backend/Magic.Web.Core/Magic.Web.Core.csproj b/backend/Magic.Web.Core/Magic.Web.Core.csproj index 97fd524..89ccc75 100644 --- a/backend/Magic.Web.Core/Magic.Web.Core.csproj +++ b/backend/Magic.Web.Core/Magic.Web.Core.csproj @@ -27,11 +27,7 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/backend/Magic.Web.Core/Magic.Web.Core.xml b/backend/Magic.Web.Core/Magic.Web.Core.xml index 3f9b878..9db7f26 100644 --- a/backend/Magic.Web.Core/Magic.Web.Core.xml +++ b/backend/Magic.Web.Core/Magic.Web.Core.xml @@ -1576,21 +1576,137 @@ 注册类型 实例类型 + + + 标识源生成的实现。 + + + + + 标识源生成成员的特性。 + + + + + 生成行为。一般来说,对于非只读、非重写、且同时拥有get,set(可以私有)访问器的属性,会自动生成。 + 对于字段,均不会自动生成。所以可以使用该设置,来指示生成器的生成行为。 + + 使用源生成插件的调用。 - + 使用源生成插件的调用。 - 插件名称,一般建议使用nameof()解决。 + 插件名称,一般建议使用解决。 + + + + 标识该接口将使用源生成自动生成调用的代理类 + + + + + 调用键的前缀,包括服务的命名空间,类名,不区分大小写。格式:命名空间.类名 + + + + + 生成泛型方法的约束 + + + + + 是否仅以函数名调用,当为True是,调用时仅需要传入方法名即可。 + + + + + 生成代码的命名空间 + + + + + 生成的类名,不要包含“I”,生成接口时会自动添加。 + + + + + 生成代码 + + + + + 继承接口 + + + + + 代码生成标识 + + + + + 生成扩展同步代码 + + + + + 生成扩展异步代码 + + + + + 生成实例类同步代码(源代码生成无效) + + + + + 生成实例类异步代码(源代码生成无效) + + + + + 生成接口同步代码 + + + + + 生成接口异步代码 + 标识将通过源生成器生成Rpc服务的调用委托。 + + + 标识将通过源生成器生成Rpc服务的注册代码。 + + + + + 方法名称。默认是“RegisterAllFrom+AssemblyName” + + + + + 扩展类类名,默认是“RegisterRpcServerFrom+AssemblyName+Extension” + + + + + 访问修饰。 + + 如果为,将生成注册公共Rpc服务与非公共服务两个方法。其中非公共方法会在之前以Internal开头。 + 如果为,将只生成注册非公共Rpc服务。 + 如果为,将只生成注册公共Rpc服务。 + + + -- Gitee