|
@@ -4,7 +4,7 @@ namespace ET.Server
|
|
|
{
|
|
|
public abstract class AMRpcHandler<Request, Response>: IMHandler where Request : class, IRequest where Response : class, IResponse
|
|
|
{
|
|
|
- protected abstract ETTask Run(Session session, Request request, Response response, Action reply);
|
|
|
+ protected abstract ETTask Run(Session session, Request request, Response response);
|
|
|
|
|
|
public void Handle(Session session, object message)
|
|
|
{
|
|
@@ -22,34 +22,29 @@ namespace ET.Server
|
|
|
}
|
|
|
|
|
|
int rpcId = request.RpcId;
|
|
|
-
|
|
|
long instanceId = session.InstanceId;
|
|
|
|
|
|
Response response = Activator.CreateInstance<Response>();
|
|
|
|
|
|
- void Reply()
|
|
|
- {
|
|
|
- // 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样
|
|
|
- if (session.InstanceId != instanceId)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- response.RpcId = rpcId;
|
|
|
- session.Send(response);
|
|
|
- }
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
- await this.Run(session, request, response, Reply);
|
|
|
+ await this.Run(session, request, response);
|
|
|
}
|
|
|
catch (Exception exception)
|
|
|
{
|
|
|
Log.Error(exception);
|
|
|
response.Error = ErrorCore.ERR_RpcFail;
|
|
|
response.Message = exception.ToString();
|
|
|
- Reply();
|
|
|
}
|
|
|
+
|
|
|
+ // 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样
|
|
|
+ if (session.InstanceId != instanceId)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ response.RpcId = rpcId; // 在这里设置rpcId是为了防止在Run中不小心修改rpcId字段
|
|
|
+ session.Send(response);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|