aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/LLPacketThrottle.cs
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-06 12:13:16 -0700
committerJohn Hurliman2009-10-06 12:13:16 -0700
commit61b537215328499155c58f46e6338d459aba87ec (patch)
treed410fa5de01aeeacc6c66c23a886a2ae3e5248cc /OpenSim/Region/ClientStack/LindenUDP/LLPacketThrottle.cs
parent* Try/catch around EndInvoke() when Util.FireAndForget() returns to catch exc... (diff)
downloadopensim-SC_OLD-61b537215328499155c58f46e6338d459aba87ec.zip
opensim-SC_OLD-61b537215328499155c58f46e6338d459aba87ec.tar.gz
opensim-SC_OLD-61b537215328499155c58f46e6338d459aba87ec.tar.bz2
opensim-SC_OLD-61b537215328499155c58f46e6338d459aba87ec.tar.xz
* Added missing references to prebuild.xml and commented out the LindenUDP tests until a new test harness is written
* Clients are no longer disconnected when a packet handler crashes. We'll see how this works out in practice * Added documentation and cleanup, getting ready for the first public push * Deleted an old LLUDP file
Diffstat (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLPacketThrottle.cs')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLPacketThrottle.cs128
1 files changed, 0 insertions, 128 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLPacketThrottle.cs b/OpenSim/Region/ClientStack/LindenUDP/LLPacketThrottle.cs
deleted file mode 100644
index 52effc5..0000000
--- a/OpenSim/Region/ClientStack/LindenUDP/LLPacketThrottle.cs
+++ /dev/null
@@ -1,128 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28namespace OpenSim.Region.ClientStack.LindenUDP
29{
30 public class LLPacketThrottle
31 {
32 private readonly int m_maxAllowableThrottle;
33 private readonly int m_minAllowableThrottle;
34 private int m_currentThrottle;
35 private const int m_throttleTimeDivisor = 7;
36 private int m_currentBitsSent;
37 private int m_throttleBits;
38
39 /// <value>
40 /// Value with which to multiply all the throttle fields
41 /// </value>
42 private float m_throttleMultiplier;
43
44 public int Max
45 {
46 get { return m_maxAllowableThrottle; }
47 }
48
49 public int Min
50 {
51 get { return m_minAllowableThrottle; }
52 }
53
54 public int Current
55 {
56 get { return m_currentThrottle; }
57 }
58
59 /// <summary>
60 /// Constructor.
61 /// </summary>
62 /// <param name="min"></param>
63 /// <param name="max"></param>
64 /// <param name="throttle"></param>
65 /// <param name="throttleMultiplier">
66 /// A parameter that's ends up multiplying all throttle settings. An alternative solution would have been
67 /// to multiply all the parameters by this before giving them to the constructor. But doing it this way
68 /// represents the fact that the multiplier is a hack that pumps data to clients much faster than the actual
69 /// settings that we are given.
70 /// </param>
71 public LLPacketThrottle(int min, int max, int throttle, float throttleMultiplier)
72 {
73 m_throttleMultiplier = throttleMultiplier;
74 m_maxAllowableThrottle = max;
75 m_minAllowableThrottle = min;
76 m_currentThrottle = throttle;
77 m_currentBitsSent = 0;
78
79 CalcBits();
80 }
81
82 /// <summary>
83 /// Calculate the actual throttle required.
84 /// </summary>
85 private void CalcBits()
86 {
87 m_throttleBits = (int)((float)m_currentThrottle * m_throttleMultiplier / (float)m_throttleTimeDivisor);
88 }
89
90 public void Reset()
91 {
92 m_currentBitsSent = 0;
93 }
94
95 public bool UnderLimit()
96 {
97 return m_currentBitsSent < m_throttleBits;
98 }
99
100 public int AddBytes(int bytes)
101 {
102 m_currentBitsSent += bytes * 8;
103 return m_currentBitsSent;
104 }
105
106 public int Throttle
107 {
108 get { return m_currentThrottle; }
109 set
110 {
111 if (value < m_minAllowableThrottle)
112 {
113 m_currentThrottle = m_minAllowableThrottle;
114 }
115 else if (value > m_maxAllowableThrottle)
116 {
117 m_currentThrottle = m_maxAllowableThrottle;
118 }
119 else
120 {
121 m_currentThrottle = value;
122 }
123
124 CalcBits();
125 }
126 }
127 }
128}