private byte[] AssureRecieve(Socket client, bool optimized) { byte[] buffer = new byte[CmdSizeHolderBytesCount + (optimized ? CmdSizeHolderBytesCount : 0)]; AssureRecieve(ref buffer, client); int commandSize; try { commandSize = HelperFxn.ToInt32(buffer, 0 + (optimized ? CmdSizeHolderBytesCount : 0), CmdSizeHolderBytesCount); } catch (InvalidCastException) { string str = System.Text.UTF8Encoding.UTF8.GetString(buffer); if (_logger.IsErrorLogsEnabled) { _logger.NCacheLog.Error("AssureReceive", str); } throw; } if (commandSize == 0) { return(new byte[0]); } buffer = new byte[commandSize]; AssureRecieve(ref buffer, client); return(buffer); }
/// <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); } }