aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorTeravus Ovares2007-12-17 20:24:49 +0000
committerTeravus Ovares2007-12-17 20:24:49 +0000
commitadf7afb6064a0510b2b9f466889161501603041e (patch)
treea6a8b1ec4d0de45432751a84f205bbb74e578f05 /OpenSim
parentmake it so prims don't relay into IRC (diff)
downloadopensim-SC_OLD-adf7afb6064a0510b2b9f466889161501603041e.zip
opensim-SC_OLD-adf7afb6064a0510b2b9f466889161501603041e.tar.gz
opensim-SC_OLD-adf7afb6064a0510b2b9f466889161501603041e.tar.bz2
opensim-SC_OLD-adf7afb6064a0510b2b9f466889161501603041e.tar.xz
* Turned all instances of ForEach loops in ClientManager into Local Arrays.
* Added Locking while the Copy is taking place. * Added an error message to describe what's actually happening.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/ClientManager.cs75
-rw-r--r--OpenSim/Region/ClientStack/ClientView.cs4
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs1
3 files changed, 63 insertions, 17 deletions
diff --git a/OpenSim/Framework/ClientManager.cs b/OpenSim/Framework/ClientManager.cs
index 629aab5..698171d 100644
--- a/OpenSim/Framework/ClientManager.cs
+++ b/OpenSim/Framework/ClientManager.cs
@@ -40,9 +40,25 @@ namespace OpenSim.Framework
40 40
41 public void ForEachClient(ForEachClientDelegate whatToDo) 41 public void ForEachClient(ForEachClientDelegate whatToDo)
42 { 42 {
43 foreach (IClientAPI client in m_clients.Values) 43
44 // Wasteful, I know
45 IClientAPI[] LocalClients = new IClientAPI[0];
46 lock (m_clients)
44 { 47 {
45 whatToDo(client); 48 LocalClients = new IClientAPI[m_clients.Count];
49 m_clients.Values.CopyTo(LocalClients, 0);
50 }
51
52 for (int i = 0; i < LocalClients.Length; i++)
53 {
54 try
55 {
56 whatToDo(LocalClients[i]);
57 }
58 catch (System.Exception e)
59 {
60 OpenSim.Framework.Console.MainLog.Instance.Warn("CLIENT", "Unable to do ForEachClient for one of the clients" + "\n Reason: " + e.ToString());
61 }
46 } 62 }
47 } 63 }
48 64
@@ -84,29 +100,48 @@ namespace OpenSim.Framework
84 public void CloseAllCircuits(LLUUID agentId) 100 public void CloseAllCircuits(LLUUID agentId)
85 { 101 {
86 uint[] circuits = GetAllCircuits(agentId); 102 uint[] circuits = GetAllCircuits(agentId);
87 foreach (uint circuit in circuits) 103 // We're using a for loop here so changes to the circuits don't cause it to completely fail.
104
105 for (int i = 0; i < circuits.Length; i++)
88 { 106 {
89 IClientAPI client; 107 IClientAPI client;
90 if (m_clients.TryGetValue(circuit, out client)) 108 try
109 {
110
111 if (m_clients.TryGetValue(circuits[i], out client))
112 {
113 Remove(client.CircuitCode);
114 client.Close();
115 }
116 }
117 catch (System.Exception e)
91 { 118 {
92 Remove(circuit); 119 OpenSim.Framework.Console.MainLog.Instance.Error("CLIENT", "Unable to shutdown circuit for: " + agentId.ToString() + "\n Reason: " + e.ToString());
93 client.Close();
94 } 120 }
95 } 121 }
122
123
96 } 124 }
97 125
98 private uint[] GetAllCircuits(LLUUID agentId) 126 private uint[] GetAllCircuits(LLUUID agentId)
99 { 127 {
100 List<uint> circuits = new List<uint>(); 128 List<uint> circuits = new List<uint>();
129 // Wasteful, I know
130 IClientAPI[] LocalClients = new IClientAPI[0];
131 lock (m_clients)
132 {
133 LocalClients = new IClientAPI[m_clients.Count];
134 m_clients.Values.CopyTo(LocalClients, 0);
135 }
136
101 137
102 foreach (KeyValuePair<uint, IClientAPI> pair in m_clients) 138 for (int i = 0; i < LocalClients.Length; i++ )
103 { 139 {
104 if (pair.Value.AgentId == agentId) 140 if (LocalClients[i].AgentId == agentId)
105 { 141 {
106 circuits.Add(pair.Key); 142 circuits.Add(LocalClients[i].CircuitCode);
107 } 143 }
108 } 144 }
109
110 return circuits.ToArray(); 145 return circuits.ToArray();
111 } 146 }
112 147
@@ -116,14 +151,24 @@ namespace OpenSim.Framework
116 ViewerEffectPacket packet = new ViewerEffectPacket(); 151 ViewerEffectPacket packet = new ViewerEffectPacket();
117 packet.Effect = effectBlock; 152 packet.Effect = effectBlock;
118 153
119 foreach (IClientAPI client in m_clients.Values) 154 // Wasteful, I know
155 IClientAPI[] LocalClients = new IClientAPI[0];
156 lock (m_clients)
120 { 157 {
121 if (client.AgentId != sender.AgentId) 158 LocalClients = new IClientAPI[m_clients.Count];
159 m_clients.Values.CopyTo(LocalClients, 0);
160 }
161
162
163 for (int i = 0; i < LocalClients.Length; i++)
164 {
165 if (LocalClients[i].AgentId != sender.AgentId)
122 { 166 {
123 packet.AgentData.AgentID = client.AgentId; 167 packet.AgentData.AgentID = LocalClients[i].AgentId;
124 packet.AgentData.SessionID = client.SessionId; 168 packet.AgentData.SessionID = LocalClients[i].SessionId;
125 client.OutPacket(packet,ThrottleOutPacketType.Task); 169 LocalClients[i].OutPacket(packet, ThrottleOutPacketType.Task);
126 } 170 }
171
127 } 172 }
128 } 173 }
129 174
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs
index 41e44a5..5e0ab65 100644
--- a/OpenSim/Region/ClientStack/ClientView.cs
+++ b/OpenSim/Region/ClientStack/ClientView.cs
@@ -209,8 +209,8 @@ namespace OpenSim.Region.ClientStack
209 m_scene.RemoveClient(AgentId); 209 m_scene.RemoveClient(AgentId);
210 210
211 // Send the STOP packet 211 // Send the STOP packet
212 libsecondlife.Packets.DisableSimulatorPacket disable = new libsecondlife.Packets.DisableSimulatorPacket(); 212 //libsecondlife.Packets.DisableSimulatorPacket disable = new libsecondlife.Packets.DisableSimulatorPacket();
213 OutPacket(disable, ThrottleOutPacketType.Task); 213 //OutPacket(disable, ThrottleOutPacketType.Task);
214 214
215 // FLUSH Packets 215 // FLUSH Packets
216 m_packetQueue.Close(); 216 m_packetQueue.Close();
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index db2e4b8..1145b00 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -459,6 +459,7 @@ namespace OpenSim.Region.Environment.Scenes
459 // This is the method that shuts down the scene. 459 // This is the method that shuts down the scene.
460 public override void Close() 460 public override void Close()
461 { 461 {
462 MainLog.Instance.Warn("SCENE", "Closing down the single simulator: " + RegionInfo.RegionName);
462 // Kick all ROOT agents with the message, 'The simulator is going down' 463 // Kick all ROOT agents with the message, 'The simulator is going down'
463 ForEachScenePresence(delegate(ScenePresence avatar) 464 ForEachScenePresence(delegate(ScenePresence avatar)
464 { 465 {