mirror of
https://github.com/RRQM/TouchSocket.git
synced 2025-12-19 01:46:44 +08:00
发布:3.1.18
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<BaseVersion>3.1.17</BaseVersion>
|
||||
<BaseVersion>3.1.18</BaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<TouchSocketVersion>$(BaseVersion)</TouchSocketVersion>
|
||||
|
||||
@@ -304,8 +304,9 @@ public class DmtpRpcActor : DisposableObject, IDmtpRpcActor
|
||||
//调用方不关心结果
|
||||
return;
|
||||
}
|
||||
else if (rpcMethod != null && rpcMethod.HasCallContext)
|
||||
else
|
||||
{
|
||||
//首先移除调用上下文。
|
||||
this.m_callContextDic.TryRemove(rpcRequestPackage.Sign, out _);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TouchSocket.Core;
|
||||
@@ -162,7 +163,16 @@ public abstract class WebSocketClientBase : HttpClientBase
|
||||
{
|
||||
if (dataFrame.IsClose)
|
||||
{
|
||||
var msg = dataFrame.PayloadData?.ToString();
|
||||
var bytes = dataFrame.PayloadData;
|
||||
bytes.SeekToStart();
|
||||
if (bytes.Length >= 2)
|
||||
{
|
||||
var closeStatus = (WebSocketCloseStatus)bytes.ReadUInt16(EndianType.Big);
|
||||
this.m_webSocket.CloseStatus = closeStatus;
|
||||
}
|
||||
|
||||
var msg = bytes.ReadToSpan(bytes.CanReadLength).ToString(System.Text.Encoding.UTF8);
|
||||
|
||||
await this.PrivateWebSocketClosing(new ClosedEventArgs(false, msg)).ConfigureAwait(EasyTask.ContinueOnCapturedContext);
|
||||
await this.m_webSocket.CloseAsync(msg).ConfigureAwait(EasyTask.ContinueOnCapturedContext);
|
||||
return;
|
||||
|
||||
@@ -15,6 +15,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TouchSocket.Core;
|
||||
|
||||
namespace TouchSocket.Rpc;
|
||||
@@ -246,11 +247,11 @@ public sealed class RpcMethod : Method
|
||||
/// <summary>
|
||||
/// 筛选器
|
||||
/// </summary>
|
||||
/// <param name="g_actionFilters">全局筛选器</param>
|
||||
/// <param name="filters">全局筛选器</param>
|
||||
/// <returns></returns>
|
||||
public IReadOnlyList<IRpcActionFilter> GetFilters(IReadOnlyList<IRpcActionFilter> g_actionFilters)
|
||||
public IReadOnlyList<IRpcActionFilter> GetFilters(IReadOnlyList<Type> filters, IResolver resolver)
|
||||
{
|
||||
if (this.m_hasFilters[0] || this.m_hasFilters[1] || this.m_hasFilters[2] || this.m_hasFilters[3] || (g_actionFilters?.Any()) == true)
|
||||
if (this.m_hasFilters[0] || this.m_hasFilters[1] || this.m_hasFilters[2] || this.m_hasFilters[3] || filters.Count > 0)
|
||||
{
|
||||
var actionFilters = new List<IRpcActionFilter>();
|
||||
//注册方法
|
||||
@@ -299,17 +300,15 @@ public sealed class RpcMethod : Method
|
||||
}
|
||||
}
|
||||
|
||||
if (g_actionFilters?.Any() == true)
|
||||
//全局筛选器
|
||||
foreach (var filterType in filters)
|
||||
{
|
||||
//全局筛选器
|
||||
foreach (var filter in g_actionFilters)
|
||||
{
|
||||
this.AddActionFilter(filter, ref actionFilters);
|
||||
}
|
||||
var filter = resolver.Resolve(filterType);
|
||||
this.AddActionFilter(Unsafe.As<object, IRpcActionFilter>(ref filter), ref actionFilters);
|
||||
}
|
||||
return actionFilters;
|
||||
}
|
||||
return new IRpcActionFilter[0];
|
||||
return [];
|
||||
}
|
||||
|
||||
private void AddActionFilter(IRpcActionFilter filter, ref List<IRpcActionFilter> filters)
|
||||
|
||||
@@ -40,6 +40,8 @@ public sealed class RpcStore
|
||||
/// </summary>
|
||||
public Type[] ServerTypes => this.m_serverTypes.Keys.ToArray();
|
||||
|
||||
public IReadOnlyList<Type> Filters => this.m_filters;
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有已注册的函数。
|
||||
/// </summary>
|
||||
@@ -110,41 +112,31 @@ public sealed class RpcStore
|
||||
|
||||
#region 全局筛选器
|
||||
|
||||
private readonly ConcurrentList<Type> m_filters = new ConcurrentList<Type>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取全局筛选器对象
|
||||
/// </summary>
|
||||
/// <param name="callContext"></param>
|
||||
/// <returns></returns>
|
||||
public IReadOnlyList<IRpcActionFilter> GetFilters(ICallContext callContext)
|
||||
{
|
||||
return m_filters.Select(s=>(IRpcActionFilter) callContext.Resolver.Resolve(s)).ToList();
|
||||
}
|
||||
private readonly List<Type> m_filters = new();
|
||||
|
||||
/// <summary>
|
||||
/// 添加全局筛选器
|
||||
/// </summary>
|
||||
/// <typeparam name="TFilter"></typeparam>
|
||||
public void Filter<TFilter>() where TFilter : class, IRpcActionFilter
|
||||
public void AddFilter<TFilter>() where TFilter : class, IRpcActionFilter
|
||||
{
|
||||
var filterType = typeof(TFilter);
|
||||
this.Filter(filterType);
|
||||
this.AddFilter(filterType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加全局过滤器
|
||||
/// </summary>
|
||||
public void Filter(Type filterType)
|
||||
public void AddFilter(Type filterType)
|
||||
{
|
||||
if (!typeof(IRpcActionFilter).IsAssignableFrom(filterType))
|
||||
{
|
||||
throw new RpcException($"注册类型必须与{nameof(IRpcActionFilter)}有继承关系");
|
||||
}
|
||||
|
||||
if (!m_filters.Any(s => s.FullName == filterType.FullName))
|
||||
if (!this.m_filters.Any(s => s == filterType))
|
||||
{
|
||||
m_filters.Add(filterType);
|
||||
this.m_filters.Add(filterType);
|
||||
this.m_registrator.RegisterTransient(filterType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ internal sealed class InternalRpcServerProvider : IRpcServerProvider
|
||||
return new InvokeResult(InvokeStatus.UnFound);
|
||||
}
|
||||
|
||||
var filters = method.GetFilters(m_rpcStore.GetFilters(callContext));
|
||||
var filters = method.GetFilters(this.m_rpcStore.Filters, callContext.Resolver);
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < filters.Count; i++)
|
||||
|
||||
@@ -417,23 +417,21 @@ internal sealed class TcpCore : DisposableObject
|
||||
#endif
|
||||
else
|
||||
{
|
||||
var offset = 0;
|
||||
while (length > 0 && !this.m_cancellationToken.IsCancellationRequested)
|
||||
var sentLength = 0;
|
||||
while (sentLength < length && !this.m_cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
var result = await this.m_socketSender.SendAsync(this.m_socket, memory[offset..]).ConfigureAwait(EasyTask.ContinueOnCapturedContext);
|
||||
var result = await this.m_socketSender.SendAsync(this.m_socket, memory.Slice(sentLength))
|
||||
.ConfigureAwait(EasyTask.ContinueOnCapturedContext);
|
||||
if (result.SocketError != null)
|
||||
{
|
||||
throw result.SocketError;
|
||||
}
|
||||
if (result.BytesTransferred == 0 && length > 0)
|
||||
if (result.BytesTransferred == 0 && memory.Length > 0)
|
||||
{
|
||||
throw new Exception(TouchSocketResource.IncompleteDataTransmission);
|
||||
}
|
||||
offset += result.BytesTransferred;
|
||||
length -= result.BytesTransferred;
|
||||
sentLength += result.BytesTransferred;
|
||||
}
|
||||
|
||||
//this.m_socketSender.Reset();
|
||||
}
|
||||
this.m_sentCounter.Increment(length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user