Ejemplo n.º 1
0
        /// <summary>
        /// Reads a single single response from the stream and processes it.
        /// </summary>
        /// <param name="stream"></param>
        private void ProcessResponse(Stream stream)
        {
            Response response;
            long     requestId = 0;

            if (WriteRequestIdInResponse)
            {
                byte[] requestIdBytes = new byte[sizeof(long)];
                stream.Read(requestIdBytes, 0, requestIdBytes.Length);
                requestId = BitConverter.ToInt64(requestIdBytes, 0);
            }

            byte[] responseTypeBytes = new byte[2];
            stream.Read(responseTypeBytes, 0, responseTypeBytes.Length);
            Response.Type responseType = (Response.Type)BitConverter.ToInt16(responseTypeBytes, 0);

            //Reading  a response's header...
            byte[] cmdSzBytes = new byte[CmdSizeHolderBytesCount];
            stream.Read(cmdSzBytes, 0, CmdSizeHolderBytesCount);
            int commandSize = HelperFxn.ToInt32(cmdSzBytes, 0, CmdSizeHolderBytesCount);

            byte[] cmdBytes = new byte[commandSize];
            stream.Read(cmdBytes, 0, commandSize);

            CommandResponse cmdRespose = new CommandResponse(false, new Address());

            cmdRespose.CacheId = _cacheId;
            cmdRespose.Src     = this.ServerAddress;

            if (WriteRequestIdInResponse)
            {
                cmdRespose.NeedsDeserialization = true;
                cmdRespose.RequestId            = requestId;
                cmdRespose.SerializedResponse   = cmdBytes;
                cmdRespose.Type = responseType;
            }
            else
            {
                using (Stream tempStream = new ClusteredMemoryStream(cmdBytes))
                    response = ResponseHelper.DeserializeResponse(responseType, tempStream);

                cmdRespose.NeedsDeserialization = false;
                if (response != null)
                {
                    cmdRespose.Result = response;
                }
            }

            if (_perfStatsColl.IsEnabled)
            {
                _perfStatsColl.IncrementClientResponsesPerSecStats(1);
            }

            if (cmdRespose != null)
            {
                _container.ProcessResponse(cmdRespose, _serverAddress);
            }
        }