Exemple #1
0
        private async Task <bool> SendRPC(RPCSend send, CancellationToken token)
        {
            var reqHeader = new RequestHeader
            {
                CallId       = send.RPC.CallId,
                MethodName   = send.RPC.Name,
                RequestParam = true
            };

            while (_idRPCDict.ContainsKey(send.RPC.CallId) == false)
            {
                _idRPCDict.TryAdd(send.RPC.CallId, send);
            }

            var payload = send.RPC.Serialize();

            var payloadLen = ProtoBufEx.EncodeVarint((ulong)payload.Length);

            var headerData = reqHeader.ToByteArray();

            var buf = new byte[4 + 1 + headerData.Length + Math.Max(1, payloadLen.Length) + payload.Length];

            BinaryPrimitives.WriteUInt32BigEndian(buf, (uint)(buf.Length - 4));
            buf[4] = (byte)headerData.Length;
            headerData.CopyTo(buf, 5);
            payloadLen.CopyTo(buf, 5 + headerData.Length);
            payload.CopyTo(buf, 5 + headerData.Length + payloadLen.Length);
            return(await Write(buf, token));
        }
Exemple #2
0
        public async Task QueueRPC(ICall rpc)
        {
            rpc.CallId = (uint)GetNextCallId();
            var send = new RPCSend
            {
                RPC = rpc
            };

            while (_rpcQueue.TryAdd(send) == false)
            {
                await Task.Delay(1);
            }

            send.QueueTime = DateTime.Now;
        }