From 4e7763f8def82f09fa7d1b2214ab337a3c4e1a90 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Fri, 14 Dec 2007 20:09:44 +0000 Subject: Thank you Justin for: 0000188: Clean up of some AssetCache.ProcessAssetQueue() code --- .../Framework/Communications/Cache/AssetCache.cs | 79 ++++++++-------------- 1 file changed, 27 insertions(+), 52 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index 3edc7eb..abaea23 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs @@ -469,63 +469,38 @@ namespace OpenSim.Framework.Communications.Cache } else { - //more than one packet so split file up , for now it can't be bigger than 2000 bytes - TransferPacketPacket TransferPacket = new TransferPacketPacket(); - TransferPacket.TransferData.Packet = 0; - TransferPacket.TransferData.ChannelType = 2; - TransferPacket.TransferData.TransferID = req.TransferRequestID; - byte[] chunk = null; - if (req.AssetInf.Data.Length <= 1000) + int processedLength = 0; + // libsecondlife hardcodes 1500 as the maximum data chunk size + int maxChunkSize = 1500; + int packetNumber = 0; + + while (processedLength < req.AssetInf.Data.Length) { - chunk = new byte[req.AssetInf.Data.Length]; - Array.Copy(req.AssetInf.Data, chunk, req.AssetInf.Data.Length); - TransferPacket.TransferData.Data = chunk; - TransferPacket.TransferData.Status = 1; - req.RequestUser.OutPacket(TransferPacket, ThrottleOutPacketType.Asset); - } - else - { - chunk = new byte[1000]; - Array.Copy(req.AssetInf.Data, chunk, 1000); - + TransferPacketPacket TransferPacket = new TransferPacketPacket(); + TransferPacket.TransferData.Packet = packetNumber; + TransferPacket.TransferData.ChannelType = 2; + TransferPacket.TransferData.TransferID = req.TransferRequestID; + + int chunkSize = Math.Min(req.AssetInf.Data.Length - processedLength, maxChunkSize); + byte[] chunk = new byte[chunkSize]; + Array.Copy(req.AssetInf.Data, processedLength, chunk, 0, chunk.Length); + TransferPacket.TransferData.Data = chunk; - TransferPacket.TransferData.Status = 0; - req.RequestUser.OutPacket(TransferPacket, ThrottleOutPacketType.Asset); - - int processedLength = 1000; - // libsecondlife tells us that the largest allowable chunk is 1500 bytes - // XXX Fix up this magic number (and others)! - int maxChunkSize = 1500; - int packetNumber = 1; - while (processedLength < req.AssetInf.Data.Length) + // 0 indicates more packets to come, 1 indicates last packet + if (req.AssetInf.Data.Length - processedLength > maxChunkSize) { - TransferPacket = new TransferPacketPacket(); - TransferPacket.TransferData.Packet = packetNumber; - TransferPacket.TransferData.ChannelType = 2; - TransferPacket.TransferData.TransferID = req.TransferRequestID; - - int chunkSize = Math.Min(req.AssetInf.Data.Length - processedLength, maxChunkSize); - byte[] chunk1 = new byte[chunkSize]; - Array.Copy(req.AssetInf.Data, processedLength, chunk1, 0, chunk1.Length); - - TransferPacket.TransferData.Data = chunk1; - - // 0 indicates more packets to come, 1 indicates last packet - if (req.AssetInf.Data.Length - processedLength > maxChunkSize) - { - TransferPacket.TransferData.Status = 0; - } - else - { - TransferPacket.TransferData.Status = 1; - } - - req.RequestUser.OutPacket(TransferPacket, ThrottleOutPacketType.Asset); - - processedLength += chunkSize; - packetNumber++; + TransferPacket.TransferData.Status = 0; } + else + { + TransferPacket.TransferData.Status = 1; + } + + req.RequestUser.OutPacket(TransferPacket, ThrottleOutPacketType.Asset); + + processedLength += chunkSize; + packetNumber++; } } } -- cgit v1.1