aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs60
1 files changed, 14 insertions, 46 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index abaea23..99356c2 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -36,7 +36,6 @@ using OpenSim.Framework.Console;
36 36
37namespace OpenSim.Framework.Communications.Cache 37namespace OpenSim.Framework.Communications.Cache
38{ 38{
39
40 public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset); 39 public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset);
41 40
42 /// <summary> 41 /// <summary>
@@ -77,7 +76,6 @@ namespace OpenSim.Framework.Communications.Cache
77 m_assetCacheThread.IsBackground = true; 76 m_assetCacheThread.IsBackground = true;
78 m_assetCacheThread.Start(); 77 m_assetCacheThread.Start();
79 78
80
81 m_log = log; 79 m_log = log;
82 } 80 }
83 81
@@ -100,7 +98,6 @@ namespace OpenSim.Framework.Communications.Cache
100 } 98 }
101 } 99 }
102 100
103
104 public AssetBase GetAsset(LLUUID assetID) 101 public AssetBase GetAsset(LLUUID assetID)
105 { 102 {
106 AssetBase asset = null; 103 AssetBase asset = null;
@@ -154,7 +151,6 @@ namespace OpenSim.Framework.Communications.Cache
154 } 151 }
155 } 152 }
156 153
157
158 public AssetBase GetAsset(LLUUID assetID, bool isTexture) 154 public AssetBase GetAsset(LLUUID assetID, bool isTexture)
159 { 155 {
160 AssetBase asset = GetAsset(assetID); 156 AssetBase asset = GetAsset(assetID);
@@ -236,8 +232,6 @@ namespace OpenSim.Framework.Communications.Cache
236 return asset; 232 return asset;
237 } 233 }
238 234
239
240
241 public void AssetReceived(AssetBase asset, bool IsTexture) 235 public void AssetReceived(AssetBase asset, bool IsTexture)
242 { 236 {
243 if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server 237 if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server
@@ -249,7 +243,7 @@ namespace OpenSim.Framework.Communications.Cache
249 243
250 if (IsTexture) 244 if (IsTexture)
251 { 245 {
252 //Console.WriteLine("asset recieved from asset server"); 246 //Console.WriteLine("asset received from asset server");
253 247
254 TextureImage image = new TextureImage(asset); 248 TextureImage image = new TextureImage(asset);
255 if (!Textures.ContainsKey(image.FullID)) 249 if (!Textures.ContainsKey(image.FullID))
@@ -260,7 +254,7 @@ namespace OpenSim.Framework.Communications.Cache
260 AssetRequest req = RequestedTextures[image.FullID]; 254 AssetRequest req = RequestedTextures[image.FullID];
261 req.ImageInfo = image; 255 req.ImageInfo = image;
262 256
263 req.NumPackets = CalculateNumPackets(image.Data.Length); 257 req.NumPackets = CalculateNumPackets(image.Data);
264 258
265 RequestedTextures.Remove(image.FullID); 259 RequestedTextures.Remove(image.FullID);
266 TextureRequests.Add(req); 260 TextureRequests.Add(req);
@@ -277,15 +271,7 @@ namespace OpenSim.Framework.Communications.Cache
277 { 271 {
278 AssetRequest req = RequestedAssets[assetInf.FullID]; 272 AssetRequest req = RequestedAssets[assetInf.FullID];
279 req.AssetInf = assetInf; 273 req.AssetInf = assetInf;
280 if (assetInf.Data.LongLength > 600) 274 req.NumPackets = CalculateNumPackets(assetInf.Data);
281 {
282 //over 600 bytes so split up file
283 req.NumPackets = 1 + (int)(assetInf.Data.Length - 600 + 999) / 1000;
284 }
285 else
286 {
287 req.NumPackets = 1;
288 }
289 RequestedAssets.Remove(assetInf.FullID); 275 RequestedAssets.Remove(assetInf.FullID);
290 AssetRequests.Add(req); 276 AssetRequests.Add(req);
291 } 277 }
@@ -326,16 +312,17 @@ namespace OpenSim.Framework.Communications.Cache
326 //} 312 //}
327 } 313 }
328 314
329 private int CalculateNumPackets(int length) 315 private int CalculateNumPackets(byte[] data)
330 { 316 {
317 const uint m_maxPacketSize = 600;
331 int numPackets = 1; 318 int numPackets = 1;
332 319
333 if (length > 600) 320 if (data.LongLength > m_maxPacketSize)
334 { 321 {
335 //over 600 bytes so split up file 322 // over max number of bytes so split up file
336 int restData = (length - 600); 323 long restData = data.LongLength - m_maxPacketSize;
337 int restPackets = ((restData + 999) / 1000); 324 int restPackets = (int) ((restData + m_maxPacketSize - 1) / m_maxPacketSize);
338 numPackets = 1 + restPackets; 325 numPackets += restPackets;
339 } 326 }
340 327
341 return numPackets; 328 return numPackets;
@@ -385,8 +372,7 @@ namespace OpenSim.Framework.Communications.Cache
385 //it is in our cache 372 //it is in our cache
386 AssetInfo asset = Assets[requestID]; 373 AssetInfo asset = Assets[requestID];
387 374
388 //work out how many packets it should be sent in 375 // add to the AssetRequests list
389 // and add to the AssetRequests list
390 AssetRequest req = new AssetRequest(); 376 AssetRequest req = new AssetRequest();
391 req.RequestUser = userInfo; 377 req.RequestUser = userInfo;
392 req.RequestAssetID = requestID; 378 req.RequestAssetID = requestID;
@@ -394,17 +380,7 @@ namespace OpenSim.Framework.Communications.Cache
394 req.AssetRequestSource = source; 380 req.AssetRequestSource = source;
395 req.Params = transferRequest.TransferInfo.Params; 381 req.Params = transferRequest.TransferInfo.Params;
396 req.AssetInf = asset; 382 req.AssetInf = asset;
397 383 req.NumPackets = CalculateNumPackets(asset.Data);
398 if (asset.Data.LongLength > 600)
399 {
400 //over 600 bytes so split up file
401 req.NumPackets = 1 + (int)(asset.Data.Length - 600 + 999) / 1000;
402 }
403 else
404 {
405 req.NumPackets = 1;
406 }
407
408 AssetRequests.Add(req); 384 AssetRequests.Add(req);
409 } 385 }
410 386
@@ -419,17 +395,9 @@ namespace OpenSim.Framework.Communications.Cache
419 //no requests waiting 395 //no requests waiting
420 return; 396 return;
421 } 397 }
422 int num; 398 // if less than 5, do all of them
399 int num = Math.Min(5, AssetRequests.Count);
423 400
424 if (AssetRequests.Count < 5)
425 {
426 //lower than 5 so do all of them
427 num = AssetRequests.Count;
428 }
429 else
430 {
431 num = 5;
432 }
433 AssetRequest req; 401 AssetRequest req;
434 for (int i = 0; i < num; i++) 402 for (int i = 0; i < num; i++)
435 { 403 {