|
@@ -7,38 +7,24 @@ namespace ET
|
|
|
{
|
|
{
|
|
|
public readonly struct RpcInfo
|
|
public readonly struct RpcInfo
|
|
|
{
|
|
{
|
|
|
- public IRequest Request { get; }
|
|
|
|
|
|
|
+ public Type RequestType { get; }
|
|
|
|
|
|
|
|
private readonly ETTask<IResponse> tcs;
|
|
private readonly ETTask<IResponse> tcs;
|
|
|
|
|
|
|
|
- private readonly bool isFromPool;
|
|
|
|
|
-
|
|
|
|
|
- public RpcInfo(IRequest request)
|
|
|
|
|
|
|
+ public RpcInfo(Type requestType)
|
|
|
{
|
|
{
|
|
|
- this.Request = request;
|
|
|
|
|
|
|
+ this.RequestType = requestType;
|
|
|
|
|
|
|
|
- MessageObject messageObject = (MessageObject)this.Request;
|
|
|
|
|
- this.isFromPool = messageObject.IsFromPool;
|
|
|
|
|
- messageObject.IsFromPool = false;
|
|
|
|
|
-
|
|
|
|
|
this.tcs = ETTask<IResponse>.Create(true);
|
|
this.tcs = ETTask<IResponse>.Create(true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void SetResult(IResponse response)
|
|
public void SetResult(IResponse response)
|
|
|
{
|
|
{
|
|
|
- MessageObject messageObject = (MessageObject)this.Request;
|
|
|
|
|
- messageObject.IsFromPool = this.isFromPool;
|
|
|
|
|
- messageObject.Dispose();
|
|
|
|
|
-
|
|
|
|
|
this.tcs.SetResult(response);
|
|
this.tcs.SetResult(response);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void SetException(Exception exception)
|
|
public void SetException(Exception exception)
|
|
|
{
|
|
{
|
|
|
- MessageObject messageObject = (MessageObject)this.Request;
|
|
|
|
|
- messageObject.IsFromPool = this.isFromPool;
|
|
|
|
|
- messageObject.Dispose();
|
|
|
|
|
-
|
|
|
|
|
this.tcs.SetException(exception);
|
|
this.tcs.SetException(exception);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -82,7 +68,7 @@ namespace ET
|
|
|
|
|
|
|
|
public static void OnResponse(this Session self, IResponse response)
|
|
public static void OnResponse(this Session self, IResponse response)
|
|
|
{
|
|
{
|
|
|
- if (!self.requestCallbacks.Remove(response.RpcId, out var action))
|
|
|
|
|
|
|
+ if (!self.requestCallbacks.Remove(response.RpcId, out RpcInfo action))
|
|
|
{
|
|
{
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -92,7 +78,7 @@ namespace ET
|
|
|
public static async ETTask<IResponse> Call(this Session self, IRequest request, ETCancellationToken cancellationToken)
|
|
public static async ETTask<IResponse> Call(this Session self, IRequest request, ETCancellationToken cancellationToken)
|
|
|
{
|
|
{
|
|
|
int rpcId = ++self.RpcId;
|
|
int rpcId = ++self.RpcId;
|
|
|
- RpcInfo rpcInfo = new(request);
|
|
|
|
|
|
|
+ RpcInfo rpcInfo = new(request.GetType());
|
|
|
self.requestCallbacks[rpcId] = rpcInfo;
|
|
self.requestCallbacks[rpcId] = rpcInfo;
|
|
|
request.RpcId = rpcId;
|
|
request.RpcId = rpcId;
|
|
|
|
|
|
|
@@ -105,7 +91,7 @@ namespace ET
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Type responseType = OpcodeType.Instance.GetResponseType(action.Request.GetType());
|
|
|
|
|
|
|
+ Type responseType = OpcodeType.Instance.GetResponseType(action.RequestType);
|
|
|
IResponse response = (IResponse) Activator.CreateInstance(responseType);
|
|
IResponse response = (IResponse) Activator.CreateInstance(responseType);
|
|
|
response.Error = ErrorCore.ERR_Cancel;
|
|
response.Error = ErrorCore.ERR_Cancel;
|
|
|
action.SetResult(response);
|
|
action.SetResult(response);
|
|
@@ -127,7 +113,7 @@ namespace ET
|
|
|
public static async ETTask<IResponse> Call(this Session self, IRequest request, int time = 0)
|
|
public static async ETTask<IResponse> Call(this Session self, IRequest request, int time = 0)
|
|
|
{
|
|
{
|
|
|
int rpcId = ++self.RpcId;
|
|
int rpcId = ++self.RpcId;
|
|
|
- RpcInfo rpcInfo = new(request);
|
|
|
|
|
|
|
+ RpcInfo rpcInfo = new(request.GetType());
|
|
|
self.requestCallbacks[rpcId] = rpcInfo;
|
|
self.requestCallbacks[rpcId] = rpcInfo;
|
|
|
request.RpcId = rpcId;
|
|
request.RpcId = rpcId;
|
|
|
self.Send(request);
|
|
self.Send(request);
|
|
@@ -147,7 +133,7 @@ namespace ET
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- action.SetException(new Exception($"session call timeout: {request} {time}"));
|
|
|
|
|
|
|
+ action.SetException(new Exception($"session call timeout: {action.RequestType.FullName} {time}"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Timeout().Coroutine();
|
|
Timeout().Coroutine();
|