Beispiel #1
0
        public RpcTcpMessage <RpcResponse> GetResponse()
        {
            var h = ProtoBufSerializer.FromByteArray <RpcResponseHeader>(_headerBuffer);

            int         offset   = IdentityLength + HeaderLength;
            RpcResponse response = new RpcResponse()
            {
                ErrorCode = (RpcErrorCode)h.ResponseCode,
                Options   = (RpcMessageOptions)h.Option,
            };
            int len = h.BodyLength - 1;

            if (len > 0)
            {
                response.BodyBuffer           = new RpcBodyBuffer(_bodyBuffer);
                response.BodyBuffer.TextError = true;
                offset += len;
            }
            else if (len == 0)
            {
                response.BodyBuffer = RpcBodyBuffer.EmptyBody;
            }
            else
            {
                response.BodyBuffer = null;
            }
            var message = new RpcTcpMessage <RpcResponse>()
            {
                Sequence = h.Sequence,
                Message  = response,
            };

            return(message);
        }
Beispiel #2
0
        private void ProcessReceivePacket(RpcTcpPacket packet)
        {
            _counter.ReceiveMessagePerSec.Increment();
            _counter.ReceiveMessageTotal.Increment();

            if (packet.Direction == RpcMessageDirection.Request)
            {
                ThreadPool.QueueUserWorkItem(
                    new WaitCallback(delegate(object state) {
                    try {
                        RpcTcpMessage <RpcRequest> request = packet.GetRequest();
                        RequestReceived(this, request.Sequence, request.Message);
                    } catch (Exception ex) {
                        _tracing.Error(ex, "ProcessRequest Failed");
                        _tracing.ErrorFmt("Packet: {0}", packet.DumpInfo());
                    }
                })
                    );
            }
            else
            {
                ThreadPool.QueueUserWorkItem(
                    new WaitCallback(delegate(object state) {
                    try {
                        RpcTcpMessage <RpcResponse> response = packet.GetResponse();
                        ResponseReceived(this, response.Sequence, response.Message);
                    } catch (Exception ex) {
                        _tracing.Error(ex, "ProcessResponse Failed");
                        _tracing.ErrorFmt("Packet: {0}", packet.DumpInfo());
                    }
                })
                    );
            }
        }
Beispiel #3
0
        public RpcTcpMessage <RpcRequest> GetRequest()
        {
            var h = ProtoBufSerializer.FromByteArray <RpcRequestHeader>(_headerBuffer);

            RpcRequest request = new RpcRequest()
            {
                Service      = h.Service,
                Method       = h.Method,
                FromComputer = h.FromComputer,
                FromService  = h.FromService,
                ContextUri   = h.ContextUri,
                Options      = (RpcMessageOptions)h.Option,
            };

            int len = h.BodyLength - 1;

            if (len > 0)
            {
                request.BodyBuffer = new RpcBodyBuffer(_bodyBuffer);
            }
            else if (len == 0)
            {
                request.BodyBuffer = RpcBodyBuffer.EmptyBody;
            }
            else
            {
                request.BodyBuffer = null;
            }
            var message = new RpcTcpMessage <RpcRequest>()
            {
                Sequence = h.Sequence,
                Message  = request,
            };

            return(message);
        }