From 6702b0373371fd2a546a580ad82f5cc175fa29e0 Mon Sep 17 00:00:00 2001
From: Jeff Ames
Date: Wed, 19 Dec 2007 08:44:25 +0000
Subject: Misc. cleanup: * added Util.Clip(value, min, max) * modified asset
cache's numPackets calculation to use max packet size (600) instead of 1000 *
removed a few magic numbers
---
.../Framework/Communications/Cache/AssetCache.cs | 60 +++++-----------------
OpenSim/Framework/Data.DB4o/DB4oUserData.cs | 2 +-
OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs | 4 +-
OpenSim/Framework/Data.MySQL/MySQLUserData.cs | 4 +-
OpenSim/Framework/Data.SQLite/SQLiteUserData.cs | 2 +-
OpenSim/Framework/Data/GridData.cs | 4 +-
OpenSim/Framework/Remoting.cs | 2 +-
OpenSim/Framework/Util.cs | 10 ++++
8 files changed, 33 insertions(+), 55 deletions(-)
(limited to 'OpenSim/Framework')
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;
namespace OpenSim.Framework.Communications.Cache
{
-
public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset);
///
@@ -77,7 +76,6 @@ namespace OpenSim.Framework.Communications.Cache
m_assetCacheThread.IsBackground = true;
m_assetCacheThread.Start();
-
m_log = log;
}
@@ -100,7 +98,6 @@ namespace OpenSim.Framework.Communications.Cache
}
}
-
public AssetBase GetAsset(LLUUID assetID)
{
AssetBase asset = null;
@@ -154,7 +151,6 @@ namespace OpenSim.Framework.Communications.Cache
}
}
-
public AssetBase GetAsset(LLUUID assetID, bool isTexture)
{
AssetBase asset = GetAsset(assetID);
@@ -236,8 +232,6 @@ namespace OpenSim.Framework.Communications.Cache
return asset;
}
-
-
public void AssetReceived(AssetBase asset, bool IsTexture)
{
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
if (IsTexture)
{
- //Console.WriteLine("asset recieved from asset server");
+ //Console.WriteLine("asset received from asset server");
TextureImage image = new TextureImage(asset);
if (!Textures.ContainsKey(image.FullID))
@@ -260,7 +254,7 @@ namespace OpenSim.Framework.Communications.Cache
AssetRequest req = RequestedTextures[image.FullID];
req.ImageInfo = image;
- req.NumPackets = CalculateNumPackets(image.Data.Length);
+ req.NumPackets = CalculateNumPackets(image.Data);
RequestedTextures.Remove(image.FullID);
TextureRequests.Add(req);
@@ -277,15 +271,7 @@ namespace OpenSim.Framework.Communications.Cache
{
AssetRequest req = RequestedAssets[assetInf.FullID];
req.AssetInf = assetInf;
- if (assetInf.Data.LongLength > 600)
- {
- //over 600 bytes so split up file
- req.NumPackets = 1 + (int)(assetInf.Data.Length - 600 + 999) / 1000;
- }
- else
- {
- req.NumPackets = 1;
- }
+ req.NumPackets = CalculateNumPackets(assetInf.Data);
RequestedAssets.Remove(assetInf.FullID);
AssetRequests.Add(req);
}
@@ -326,16 +312,17 @@ namespace OpenSim.Framework.Communications.Cache
//}
}
- private int CalculateNumPackets(int length)
+ private int CalculateNumPackets(byte[] data)
{
+ const uint m_maxPacketSize = 600;
int numPackets = 1;
- if (length > 600)
+ if (data.LongLength > m_maxPacketSize)
{
- //over 600 bytes so split up file
- int restData = (length - 600);
- int restPackets = ((restData + 999) / 1000);
- numPackets = 1 + restPackets;
+ // over max number of bytes so split up file
+ long restData = data.LongLength - m_maxPacketSize;
+ int restPackets = (int) ((restData + m_maxPacketSize - 1) / m_maxPacketSize);
+ numPackets += restPackets;
}
return numPackets;
@@ -385,8 +372,7 @@ namespace OpenSim.Framework.Communications.Cache
//it is in our cache
AssetInfo asset = Assets[requestID];
- //work out how many packets it should be sent in
- // and add to the AssetRequests list
+ // add to the AssetRequests list
AssetRequest req = new AssetRequest();
req.RequestUser = userInfo;
req.RequestAssetID = requestID;
@@ -394,17 +380,7 @@ namespace OpenSim.Framework.Communications.Cache
req.AssetRequestSource = source;
req.Params = transferRequest.TransferInfo.Params;
req.AssetInf = asset;
-
- if (asset.Data.LongLength > 600)
- {
- //over 600 bytes so split up file
- req.NumPackets = 1 + (int)(asset.Data.Length - 600 + 999) / 1000;
- }
- else
- {
- req.NumPackets = 1;
- }
-
+ req.NumPackets = CalculateNumPackets(asset.Data);
AssetRequests.Add(req);
}
@@ -419,17 +395,9 @@ namespace OpenSim.Framework.Communications.Cache
//no requests waiting
return;
}
- int num;
+ // if less than 5, do all of them
+ int num = Math.Min(5, AssetRequests.Count);
- if (AssetRequests.Count < 5)
- {
- //lower than 5 so do all of them
- num = AssetRequests.Count;
- }
- else
- {
- num = 5;
- }
AssetRequest req;
for (int i = 0; i < num; i++)
{
diff --git a/OpenSim/Framework/Data.DB4o/DB4oUserData.cs b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
index 9e5a679..383bfbe 100644
--- a/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
+++ b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
@@ -199,7 +199,7 @@ namespace OpenSim.Framework.Data.DB4o
///
/// Move to inventory server
/// Senders account
- /// Recievers account
+ /// Receivers account
/// Inventory item
/// Success?
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
index 80b65c1..ccab57b 100644
--- a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
+++ b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
@@ -387,7 +387,7 @@ namespace OpenSim.Framework.Data.MSSQL
/// Performs a money transfer request between two accounts
///
/// The senders account ID
- /// The recievers account ID
+ /// The receivers account ID
/// The amount to transfer
/// Success?
public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
@@ -400,7 +400,7 @@ namespace OpenSim.Framework.Data.MSSQL
///
/// TODO: Move to inventory server
/// The senders account ID
- /// The recievers account ID
+ /// The receivers account ID
/// The item to transfer
/// Success?
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
index 6a7cf49..05e5127 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
@@ -363,7 +363,7 @@ namespace OpenSim.Framework.Data.MySQL
/// Performs a money transfer request between two accounts
///
/// The senders account ID
- /// The recievers account ID
+ /// The receivers account ID
/// The amount to transfer
/// Success?
public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
@@ -376,7 +376,7 @@ namespace OpenSim.Framework.Data.MySQL
///
/// TODO: Move to inventory server
/// The senders account ID
- /// The recievers account ID
+ /// The receivers account ID
/// The item to transfer
/// Success?
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
index 346febc..99121be 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
@@ -320,7 +320,7 @@ namespace OpenSim.Framework.Data.SQLite
///
/// Move to inventory server
/// Senders account
- /// Recievers account
+ /// Receivers account
/// Inventory item
/// Success?
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
diff --git a/OpenSim/Framework/Data/GridData.cs b/OpenSim/Framework/Data/GridData.cs
index 1aebbda..7864dda 100644
--- a/OpenSim/Framework/Data/GridData.cs
+++ b/OpenSim/Framework/Data/GridData.cs
@@ -79,12 +79,12 @@ namespace OpenSim.Framework.Data
List GeneratePickerResults(LLUUID queryID, string query);
///
- /// Authenticates a sim by use of it's recv key.
+ /// Authenticates a sim by use of its recv key.
/// WARNING: Insecure
///
/// The UUID sent by the sim
/// The regionhandle sent by the sim
- /// The recieving key sent by the sim
+ /// The receiving key sent by the sim
/// Whether the sim has been authenticated
bool AuthenticateSim(LLUUID UUID, ulong regionHandle, string simrecvkey);
diff --git a/OpenSim/Framework/Remoting.cs b/OpenSim/Framework/Remoting.cs
index aa7e947..9cf0d11 100644
--- a/OpenSim/Framework/Remoting.cs
+++ b/OpenSim/Framework/Remoting.cs
@@ -38,7 +38,7 @@ namespace OpenSim.Framework
/// Suggested implementation
/// Store two digests for each foreign host. A local copy of the local hash using the local challenge (when issued), and a local copy of the remote hash using the remote challenge.
/// When sending data to the foreign host - run 'Sign' on the data and affix the returned byte[] to the message.
- /// When recieving data from the foreign host - run 'Authenticate' against the data and the attached byte[].
+ /// When receiving data from the foreign host - run 'Authenticate' against the data and the attached byte[].
/// Both hosts should be performing these operations for this to be effective.
///
internal class RemoteDigest
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index a8eef51..740f527 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -373,5 +373,15 @@ namespace OpenSim.Framework
config.Configs[(string) row[0]].Set(row.Table.Columns[i].ColumnName, row[i]);
}
}
+
+ public static float Clip(float x, float min, float max)
+ {
+ return Math.Min(Math.Max(x, min), max);
+ }
+
+ public static int Clip(int x, int min, int max)
+ {
+ return Math.Min(Math.Max(x, min), max);
+ }
}
}
--
cgit v1.1