minor cleanup

0.9.1.0-post-fixes
UbitUmarov 2019-06-13 00:08:51 +01:00
parent 4b8c5ee6e8
commit 086248c13b
1 changed files with 39 additions and 45 deletions

View File

@ -50,8 +50,8 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private object timeTickLock = new object(); private object timeTickLock = new object();
private double lastTimeTick = 0.0; private int lastTimeTick = 0;
private double lastFilesExpire = 0.0; private int lastFilesExpire = 0;
private bool inTimeTick = false; private bool inTimeTick = false;
public struct XferRequest public struct XferRequest
@ -66,15 +66,15 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
{ {
public byte[] Data; public byte[] Data;
public int refsCount; public int refsCount;
public double timeStampMS; public int timeStampMS;
} }
#region INonSharedRegionModule Members #region INonSharedRegionModule Members
public void Initialise(IConfigSource config) public void Initialise(IConfigSource config)
{ {
lastTimeTick = Util.GetTimeStampMS() + 30000.0; lastTimeTick = (int)Util.GetTimeStampMS() + 30000;
lastFilesExpire = lastTimeTick + 180000.0; lastFilesExpire = lastTimeTick + 180000;
} }
public void AddRegion(Scene scene) public void AddRegion(Scene scene)
@ -121,10 +121,9 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
{ {
if(!inTimeTick) if(!inTimeTick)
{ {
double now = Util.GetTimeStampMS(); int now = (int)Util.GetTimeStampMS();
if(now - lastTimeTick > 750.0) if(now - lastTimeTick > 750)
{ {
if(Transfers.Count == 0 && NewFiles.Count == 0) if(Transfers.Count == 0 && NewFiles.Count == 0)
lastTimeTick = now; lastTimeTick = now;
else else
@ -163,7 +162,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
{ {
lock (NewFiles) lock (NewFiles)
{ {
double now = Util.GetTimeStampMS(); int now = (int)Util.GetTimeStampMS();
if (NewFiles.ContainsKey(fileName)) if (NewFiles.ContainsKey(fileName))
{ {
NewFiles[fileName].refsCount++; NewFiles[fileName].refsCount++;
@ -183,18 +182,18 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
} }
#endregion #endregion
public void expireFiles(double now) public void expireFiles(int now)
{ {
lock (NewFiles) lock (NewFiles)
{ {
// hopefully we will not have many files so nasty code will do it // hopefully we will not have many files so nasty code will do it
if(now - lastFilesExpire > 120000.0) if(now - lastFilesExpire > 120000)
{ {
lastFilesExpire = now; lastFilesExpire = now;
List<string> expires = new List<string>(); List<string> expires = new List<string>();
foreach(string fname in NewFiles.Keys) foreach(string fname in NewFiles.Keys)
{ {
if(NewFiles[fname].refsCount == 0 && now - NewFiles[fname].timeStampMS > 120000.0) if(NewFiles[fname].refsCount == 0 && now - NewFiles[fname].timeStampMS > 120000)
expires.Add(fname); expires.Add(fname);
} }
foreach(string fname in expires) foreach(string fname in expires)
@ -230,7 +229,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
} }
} }
public void transfersTimeTick(double now) public void transfersTimeTick(int now)
{ {
XferDownLoad[] xfrs; XferDownLoad[] xfrs;
lock(Transfers) lock(Transfers)
@ -241,6 +240,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
xfrs = new XferDownLoad[Transfers.Count]; xfrs = new XferDownLoad[Transfers.Count];
Transfers.Values.CopyTo(xfrs,0); Transfers.Values.CopyTo(xfrs,0);
} }
foreach(XferDownLoad xfr in xfrs) foreach(XferDownLoad xfr in xfrs)
{ {
if(xfr.checkTime(now)) if(xfr.checkTime(now))
@ -274,12 +274,13 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
byte[] fileData = NewFiles[fileName].Data; byte[] fileData = NewFiles[fileName].Data;
int burstSize = remoteClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Task) >> 10; int burstSize = remoteClient.GetAgentThrottleSilent((int)ThrottleOutPacketType.Task) >> 10;
burstSize *= remoteClient.PingTimeMS; burstSize *= remoteClient.PingTimeMS;
burstSize >>= 10; // ping is ms, 1 round trips burstSize >>= 10; // ping is ms, 1 round trip
if(burstSize > 32)
burstSize = 32;
XferDownLoad transaction = XferDownLoad transaction =
new XferDownLoad(fileName, fileData, xferID, remoteClient, burstSize); new XferDownLoad(fileName, fileData, xferID, remoteClient, burstSize);
Transfers.Add(xferID, transaction); Transfers.Add(xferID, transaction);
transaction.StartSend(); transaction.StartSend();
// The transaction for this file is on its way // The transaction for this file is on its way
@ -327,7 +328,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
public bool isDeleted = false; public bool isDeleted = false;
private object myLock = new object(); private object myLock = new object();
private double lastACKTimeMS; private int lastACKTimeMS;
private int LastPacket; private int LastPacket;
private int lastBytes; private int lastBytes;
private int lastSentPacket; private int lastSentPacket;
@ -385,30 +386,25 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
lastAckPacket = -1; lastAckPacket = -1;
lastSentPacket = -1; lastSentPacket = -1;
double now = Util.GetTimeStampMS();
retries = 0; retries = 0;
SendBurst(now); SendBurst();
return; return;
} }
} }
private void SendBurst(double now) private void SendBurst()
{ {
lock(myLock) int start = lastAckPacket + 1;
{ int end = start + burstSize;
lastACKTimeMS = (int)now; // reset timeout if (end > LastPacket)
int start = lastAckPacket + 1; end = LastPacket;
int end = start + burstSize; while (start <= end)
if (end > LastPacket) SendPacket(start++);
end = LastPacket; lastACKTimeMS = (int)Util.GetTimeStampMS(); // reset timeout
while (start <= end)
SendPacket(start++ , now);
}
} }
private void SendPacket(int pkt, double now) private void SendPacket(int pkt)
{ {
if(pkt > LastPacket) if(pkt > LastPacket)
return; return;
@ -443,45 +439,43 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
if(isDeleted) if(isDeleted)
return true; return true;
packet &= 0x7fffffff; packet &= 0x7fffffff;
if(lastAckPacket < packet) if (lastAckPacket < packet)
lastAckPacket = (int)packet; lastAckPacket = (int)packet;
else if (lastAckPacket == LastPacket)
if(lastAckPacket == LastPacket)
{ {
done(); done();
return true; return true;
} }
double now = Util.GetTimeStampMS(); lastACKTimeMS = (int)Util.GetTimeStampMS();
lastACKTimeMS = (int)now;
retries = 0; retries = 0;
SendPacket(lastSentPacket + 1, now); SendPacket(lastSentPacket + 1);
return false; return false;
} }
} }
public bool checkTime(double now) public bool checkTime(int now)
{ {
if (Monitor.TryEnter(myLock)) if (Monitor.TryEnter(myLock))
{ {
if (!isDeleted) if (!isDeleted)
{ {
double timeMS = now - lastACKTimeMS; int timeMS = now - lastACKTimeMS;
int tout = 5 * remoteClient.PingTimeMS;
double tout = 5 * remoteClient.PingTimeMS;
if(tout > 10000) if(tout > 10000)
tout = 10000; tout = 10000;
else if (tout < 1000) else if (tout < 1000)
tout = 1000; tout = 1000;
if (timeMS > tout) if (timeMS > tout)
{ {
if (++retries >= 4) if (++retries > 4)
done(); done();
else else
{ {
burstSize >>= 2; burstSize = lastSentPacket - lastAckPacket - 1;
SendBurst(now); SendBurst();
} }
} }
} }