示例#1
0
        public async System.Threading.Tasks.Task <R> DoAwaitCall(T arg, long timeOut,
                                                                 NetCore.ERouteTarget route = NetCore.ERouteTarget.Self,
                                                                 NetCore.NetConnection conn = null,
                                                                 NetCore.RPCRouter router   = null,
                                                                 byte userFlags             = 0)
        {
            if (conn == null)
            {
                conn = RPCProcessor.DefaultConnection;
            }
            var pkg = new NetCore.PkgWriter(arg.GetPkgSize());

            pkg.SetUserFlags(userFlags);
            RPCExecuter.RPCWait waiter = null;
            try
            {
                waiter = WritePkgHeader <T>(ref pkg, ref arg, timeOut, RPCAwaiter.NullCB, route, conn, router);

                OnWriteArugment(ref arg, ref pkg);

                if (conn != null)
                {
                    pkg.SendBuffer(conn);
                }
            }
            finally
            {
                pkg.Dispose();
            }

            waiter.Processor = this;
            var result = await RPCAwaiter.RPCWaitReturn <R>(waiter);

            return(result);
        }
示例#2
0
        public void DoHashCall(ref T arg,
                               NetCore.ERouteTarget route = NetCore.ERouteTarget.Self,
                               NetCore.NetConnection conn = null,
                               NetCore.RPCRouter router   = null,
                               byte userFlags             = 0)
        {
            if (conn == null)
            {
                conn = RPCProcessor.DefaultConnection;
            }
            var pkg = new NetCore.PkgWriter(arg.GetPkgSize());

            pkg.SetUserFlags(userFlags);
            try
            {
                WritePkgHeader_Hash <T>(ref pkg, ref arg, 0, null, route, conn, router);

                OnWriteArugment(ref arg, ref pkg);

                if (conn != null)
                {
                    pkg.SendBuffer(conn);
                }
            }
            finally
            {
                pkg.Dispose();
            }
        }
示例#3
0
        protected RPCExecuter.RPCWait WritePkgHeader_Hash <T>(ref NetCore.PkgWriter pkg, ref T arg, long timeOut, RPCExecuter.FRPCReturnCallBack cb,
                                                              NetCore.ERouteTarget route, NetCore.NetConnection conn, NetCore.RPCRouter router)
            where T : IArgument
        {
            var hash = MethodHash;

            pkg.SetHashIndex(true);
            pkg.Write((byte)route);
            if (router != null)
            {
                router.RouteInfo.Save(ref pkg, route);
            }
            RPCExecuter.RPCWait waiter = null;
            if (cb != null)
            {
                pkg.SetHasReturn(true);
                waiter     = RPCExecuter.Instance.AddCalBack(cb);
                pkg.Waiter = waiter;
                if (timeOut < 0)
                {
                    timeOut = long.MaxValue;
                }
                waiter.Timout = timeOut;
                pkg.Write(hash);
                pkg.Write(waiter.SerialId);
            }
            else
            {
                pkg.SetHasReturn(false);
                pkg.Write(hash);
            }
            return(waiter);
        }
示例#4
0
        //protected async Task<R> C2S_AwaitCall<R,T>(T arg, long timeOut, ERouteTarget route = ERouteTarget.Hall)
        //    where R : struct, IReturnValue
        //    where T : struct, IArgument
        //{
        //    AssertReturnType(this.GetType(), typeof(R));
        //    if (route == ERouteTarget.Gate)
        //        route = ERouteTarget.Self;

        //    RPCExecuter.RPCWait waiter = null;
        //    if (timeOut == 0)
        //        waiter = WaitDoCallImpl<T>(ref arg, 0, null, route, RPCExecuter.Instance.C2SConnect);
        //    else
        //        waiter = WaitDoCallImpl<T>(ref arg, timeOut, RPCAwaiter.NullCB, route, RPCExecuter.Instance.C2SConnect);

        //    var result = await RPCAwaiter.RPCWaitReturn<R>(waiter);
        //    return result;
        //}
        //protected RPCExecuter.RPCWait C2S_Call<R, T>(ref T arg, long timeOut, ERouteTarget route = ERouteTarget.Hall, FRPCTypeReturnCallBack<R> cb = null)
        //    where R : struct, IReturnValue
        //    where T : struct, IArgument
        //{
        //    AssertReturnType(this.GetType(), typeof(R));
        //    if (route == ERouteTarget.Gate)
        //        route = ERouteTarget.Self;
        //    if (cb == null)
        //        return WaitDoCallImpl<T>(ref arg, 0, null, route, RPCExecuter.Instance.C2SConnect);
        //    RPCExecuter.FRPCReturnCallBack fn = (PkgReader data, bool isTimeOut) =>
        //    {
        //        if (isTimeOut)
        //        {
        //            cb(default(R), true);
        //            return;
        //        }
        //        R retValue = new R();
        //        IO.Serializer.SerializerHelper.ReadObject(retValue, data);
        //        cb(retValue, false);
        //    };
        //    return WaitDoCallImpl<T>(ref arg, timeOut, fn, route, RPCExecuter.Instance.C2SConnect);
        //}

        //protected RPCExecuter.RPCWait S2C_Call<T>(ref T arg, RPCRouter router, ERouteTarget sender = ERouteTarget.Unknown)
        //    where T : struct, IArgument
        //{
        //    if (sender == ERouteTarget.Unknown)
        //    {
        //        //sender = RPCExecuter.Instance.AppTarget;
        //        sender = ERouteTarget.Self;
        //    }

        //    switch (sender)
        //    {
        //        case ERouteTarget.Gate:
        //            return WaitDoCallImpl<T>(ref arg, 0, null, ERouteTarget.Self, router.C2GConnect);
        //        case ERouteTarget.Hall:
        //            return WaitDoCallImpl<T>(ref arg, 0, null, ERouteTarget.Client, router.ToGConnect, router);
        //        case ERouteTarget.Keep:
        //            return WaitDoCallImpl<T>(ref arg, 0, null, ERouteTarget.Client, router.ToGConnect, router);
        //        case ERouteTarget.Data:
        //            return WaitDoCallImpl<T>(ref arg, 0, null, ERouteTarget.Client, router.ToGConnect, router);
        //        case ERouteTarget.Reg:
        //            return WaitDoCallImpl<T>(ref arg, 0, null, ERouteTarget.Client, router.ToGConnect, router);
        //        default:
        //            return null;
        //    }
        //}

        //protected async Task<R> S2S_AwaitCall<R, T>(T arg, long timeOut, ERouteTarget target = ERouteTarget.Data)
        //    where R : struct, IReturnValue
        //    where T : struct, IArgument
        //{
        //    AssertReturnType(this.GetType(), typeof(R));

        //    RPCExecuter.RPCWait writer = null;
        //    if (timeOut == 0)
        //        writer = WaitDoCallImpl<T>(ref arg, timeOut, null, ERouteTarget.Self, RPCExecuter.Instance.GetServerConnect(target));
        //    else
        //        writer = WaitDoCallImpl<T>(ref arg, timeOut, RPCAwaiter.NullCB, ERouteTarget.Self, RPCExecuter.Instance.GetServerConnect(target));

        //    var result = await RPCAwaiter.RPCWaitReturn<R>(writer);
        //    return result;
        //}

        //protected RPCExecuter.RPCWait S2S_Call<R,T>(ref T arg, long timeOut, ERouteTarget target = ERouteTarget.Data, FRPCTypeReturnCallBack<R> cb = null)
        //    where R : struct, IReturnValue
        //    where T : struct, IArgument
        //{
        //    AssertReturnType(this.GetType(), typeof(R));
        //    if (cb == null)
        //    {
        //        return WaitDoCallImpl<T>(ref arg, timeOut, null, ERouteTarget.Self, RPCExecuter.Instance.GetServerConnect(target));
        //    }

        //    RPCExecuter.FRPCReturnCallBack fn = (PkgReader data, bool isTimeOut) =>
        //    {
        //        if (isTimeOut)
        //        {
        //            cb(default(R), true);
        //            return;
        //        }
        //        R retValue = new R();
        //        IO.Serializer.SerializerHelper.ReadObject(retValue, data);
        //        cb(retValue, false);
        //    };
        //    return WaitDoCallImpl<T>(ref arg, timeOut, fn, ERouteTarget.Self, RPCExecuter.Instance.GetServerConnect(target));
        //}
        #endregion

        #region Pkg Implement
        protected RPCExecuter.RPCWait WritePkgHeader <T>(ref NetCore.PkgWriter pkg, ref T arg, long timeOut, RPCExecuter.FRPCReturnCallBack cb,
                                                         NetCore.ERouteTarget route, NetCore.NetConnection conn, NetCore.RPCRouter router) where T : IArgument
        {
            var Index = RPCIndex;

            if (Index >= RPCExecuter.MaxRPC)
            {
                System.Diagnostics.Debug.WriteLine($"RPC Index is invalid:{this.GetType().FullName}");
                return(null);
            }
            pkg.Write((byte)route);
            if (router != null)
            {
                router.RouteInfo.Save(ref pkg, route);
            }

            RPCExecuter.RPCWait waiter = null;
            if (cb != null)
            {
                waiter     = RPCExecuter.Instance.AddCalBack(cb);
                pkg.Waiter = waiter;
                if (timeOut < 0)
                {
                    timeOut = long.MaxValue;
                }
                waiter.Timout = timeOut;
                Index        |= RPCExecuter.WaitFlag;
                pkg.SetHasReturn(true);
                pkg.Write(Index);
                pkg.Write(waiter.SerialId);
            }
            else
            {
                pkg.SetHasReturn(false);
                pkg.Write(Index);
            }
            return(waiter);
        }
示例#5
0
        private NetCore.NetConnection RouterTargetConnect(NetCore.ERouteTarget target, NetCore.RPCRouter router)
        {
            switch (target)
            {
            case NetCore.ERouteTarget.Reg:
            case NetCore.ERouteTarget.Log:
            case NetCore.ERouteTarget.Path:
            case NetCore.ERouteTarget.Data:
            case NetCore.ERouteTarget.Keep:
                return(PkgRcver.GetServerConnect(target));

            case NetCore.ERouteTarget.Hall:
                return(router.ToHConnect);

            case NetCore.ERouteTarget.Gate:
                return(router.ToGConnect);

            default:
                break;
            }
            return(null);
        }