diff options
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | 77 |
1 files changed, 33 insertions, 44 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index 3bdde3b..3c23dcf 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | |||
@@ -147,11 +147,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
147 | private int m_elapsed500MSOutgoingPacketHandler; | 147 | private int m_elapsed500MSOutgoingPacketHandler; |
148 | 148 | ||
149 | /// <summary>Flag to signal when clients should check for resends</summary> | 149 | /// <summary>Flag to signal when clients should check for resends</summary> |
150 | private bool m_resendUnacked; | 150 | protected bool m_resendUnacked; |
151 | |||
151 | /// <summary>Flag to signal when clients should send ACKs</summary> | 152 | /// <summary>Flag to signal when clients should send ACKs</summary> |
152 | private bool m_sendAcks; | 153 | protected bool m_sendAcks; |
154 | |||
153 | /// <summary>Flag to signal when clients should send pings</summary> | 155 | /// <summary>Flag to signal when clients should send pings</summary> |
154 | private bool m_sendPing; | 156 | protected bool m_sendPing; |
155 | 157 | ||
156 | private int m_defaultRTO = 0; | 158 | private int m_defaultRTO = 0; |
157 | private int m_maxRTO = 0; | 159 | private int m_maxRTO = 0; |
@@ -537,8 +539,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
537 | SendPacket(udpClient, completePing, ThrottleOutPacketType.Unknown, false, null); | 539 | SendPacket(udpClient, completePing, ThrottleOutPacketType.Unknown, false, null); |
538 | } | 540 | } |
539 | 541 | ||
540 | public void HandleUnacked(LLUDPClient udpClient) | 542 | public void HandleUnacked(LLClientView client) |
541 | { | 543 | { |
544 | LLUDPClient udpClient = client.UDPClient; | ||
545 | |||
542 | if (!udpClient.IsConnected) | 546 | if (!udpClient.IsConnected) |
543 | return; | 547 | return; |
544 | 548 | ||
@@ -551,12 +555,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
551 | if (udpClient.IsPaused) | 555 | if (udpClient.IsPaused) |
552 | timeoutTicks = m_pausedAckTimeout; | 556 | timeoutTicks = m_pausedAckTimeout; |
553 | 557 | ||
554 | if ((Environment.TickCount & Int32.MaxValue) - udpClient.TickLastPacketReceived > timeoutTicks) | 558 | if (!client.IsLoggingOut && |
559 | (Environment.TickCount & Int32.MaxValue) - udpClient.TickLastPacketReceived > timeoutTicks) | ||
555 | { | 560 | { |
556 | m_log.Warn("[LLUDPSERVER]: Ack timeout, disconnecting " + udpClient.AgentID); | 561 | m_log.Warn("[LLUDPSERVER]: Ack timeout, disconnecting " + udpClient.AgentID); |
557 | StatsManager.SimExtraStats.AddAbnormalClientThreadTermination(); | 562 | StatsManager.SimExtraStats.AddAbnormalClientThreadTermination(); |
563 | RemoveClient(client); | ||
558 | 564 | ||
559 | RemoveClient(udpClient); | ||
560 | return; | 565 | return; |
561 | } | 566 | } |
562 | 567 | ||
@@ -879,7 +884,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
879 | #endregion Ping Check Handling | 884 | #endregion Ping Check Handling |
880 | 885 | ||
881 | // Inbox insertion | 886 | // Inbox insertion |
882 | packetInbox.Enqueue(new IncomingPacket(udpClient, packet)); | 887 | packetInbox.Enqueue(new IncomingPacket((LLClientView)client, packet)); |
883 | } | 888 | } |
884 | 889 | ||
885 | #region BinaryStats | 890 | #region BinaryStats |
@@ -1105,21 +1110,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1105 | return client; | 1110 | return client; |
1106 | } | 1111 | } |
1107 | 1112 | ||
1108 | private void RemoveClient(LLUDPClient udpClient) | 1113 | private void RemoveClient(IClientAPI client) |
1109 | { | 1114 | { |
1110 | // Remove this client from the scene | 1115 | client.IsLoggingOut = true; |
1111 | IClientAPI client; | 1116 | Util.FireAndForget(o => client.Close()); |
1112 | if (m_scene.TryGetClient(udpClient.AgentID, out client)) | ||
1113 | { | ||
1114 | client.IsLoggingOut = true; | ||
1115 | client.Close(false); | ||
1116 | } | ||
1117 | else | ||
1118 | { | ||
1119 | m_log.WarnFormat( | ||
1120 | "[LLUDPSERVER]: Tried to remove client with id {0} but not such client in {1}", | ||
1121 | udpClient.AgentID, m_scene.RegionInfo.RegionName); | ||
1122 | } | ||
1123 | } | 1117 | } |
1124 | 1118 | ||
1125 | private void IncomingPacketHandler() | 1119 | private void IncomingPacketHandler() |
@@ -1246,7 +1240,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1246 | Watchdog.RemoveThread(); | 1240 | Watchdog.RemoveThread(); |
1247 | } | 1241 | } |
1248 | 1242 | ||
1249 | private void ClientOutgoingPacketHandler(IClientAPI client) | 1243 | protected void ClientOutgoingPacketHandler(IClientAPI client) |
1250 | { | 1244 | { |
1251 | m_currentOutgoingClient = client; | 1245 | m_currentOutgoingClient = client; |
1252 | 1246 | ||
@@ -1254,12 +1248,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1254 | { | 1248 | { |
1255 | if (client is LLClientView) | 1249 | if (client is LLClientView) |
1256 | { | 1250 | { |
1257 | LLUDPClient udpClient = ((LLClientView)client).UDPClient; | 1251 | LLClientView llClient = (LLClientView)client; |
1252 | LLUDPClient udpClient = llClient.UDPClient; | ||
1258 | 1253 | ||
1259 | if (udpClient.IsConnected) | 1254 | if (udpClient.IsConnected) |
1260 | { | 1255 | { |
1261 | if (m_resendUnacked) | 1256 | if (m_resendUnacked) |
1262 | HandleUnacked(udpClient); | 1257 | HandleUnacked(llClient); |
1263 | 1258 | ||
1264 | if (m_sendAcks) | 1259 | if (m_sendAcks) |
1265 | SendAcks(udpClient); | 1260 | SendAcks(udpClient); |
@@ -1308,7 +1303,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1308 | { | 1303 | { |
1309 | if (client is LLClientView) | 1304 | if (client is LLClientView) |
1310 | { | 1305 | { |
1311 | LLUDPClient udpClient = ((LLClientView)client).UDPClient; | 1306 | LLClientView llClient = (LLClientView)client; |
1307 | LLUDPClient udpClient = llClient.UDPClient; | ||
1312 | 1308 | ||
1313 | if (udpClient.IsConnected) | 1309 | if (udpClient.IsConnected) |
1314 | { | 1310 | { |
@@ -1317,7 +1313,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1317 | nticksUnack++; | 1313 | nticksUnack++; |
1318 | watch2.Start(); | 1314 | watch2.Start(); |
1319 | 1315 | ||
1320 | HandleUnacked(udpClient); | 1316 | HandleUnacked(llClient); |
1321 | 1317 | ||
1322 | watch2.Stop(); | 1318 | watch2.Stop(); |
1323 | avgResendUnackedTicks = (nticksUnack - 1)/(float)nticksUnack * avgResendUnackedTicks + (watch2.ElapsedTicks / (float)nticksUnack); | 1319 | avgResendUnackedTicks = (nticksUnack - 1)/(float)nticksUnack * avgResendUnackedTicks + (watch2.ElapsedTicks / (float)nticksUnack); |
@@ -1388,22 +1384,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1388 | 1384 | ||
1389 | #endregion | 1385 | #endregion |
1390 | 1386 | ||
1391 | private void ProcessInPacket(object state) | 1387 | private void ProcessInPacket(IncomingPacket incomingPacket) |
1392 | { | 1388 | { |
1393 | IncomingPacket incomingPacket = (IncomingPacket)state; | ||
1394 | Packet packet = incomingPacket.Packet; | 1389 | Packet packet = incomingPacket.Packet; |
1395 | LLUDPClient udpClient = incomingPacket.Client; | 1390 | LLClientView client = incomingPacket.Client; |
1396 | IClientAPI client; | ||
1397 | 1391 | ||
1398 | // Sanity check | 1392 | if (client.IsActive) |
1399 | if (packet == null || udpClient == null) | ||
1400 | { | ||
1401 | m_log.WarnFormat("[LLUDPSERVER]: Processing a packet with incomplete state. Packet=\"{0}\", UDPClient=\"{1}\"", | ||
1402 | packet, udpClient); | ||
1403 | } | ||
1404 | |||
1405 | // Make sure this client is still alive | ||
1406 | if (m_scene.TryGetClient(udpClient.AgentID, out client)) | ||
1407 | { | 1393 | { |
1408 | m_currentIncomingClient = client; | 1394 | m_currentIncomingClient = client; |
1409 | 1395 | ||
@@ -1421,8 +1407,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1421 | catch (Exception e) | 1407 | catch (Exception e) |
1422 | { | 1408 | { |
1423 | // Don't let a failure in an individual client thread crash the whole sim. | 1409 | // Don't let a failure in an individual client thread crash the whole sim. |
1424 | m_log.ErrorFormat("[LLUDPSERVER]: Client packet handler for {0} for packet {1} threw an exception", udpClient.AgentID, packet.Type); | 1410 | m_log.Error( |
1425 | m_log.Error(e.Message, e); | 1411 | string.Format( |
1412 | "[LLUDPSERVER]: Client packet handler for {0} for packet {1} threw ", | ||
1413 | client.Name, packet.Type), | ||
1414 | e); | ||
1426 | } | 1415 | } |
1427 | finally | 1416 | finally |
1428 | { | 1417 | { |
@@ -1433,15 +1422,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1433 | { | 1422 | { |
1434 | m_log.DebugFormat( | 1423 | m_log.DebugFormat( |
1435 | "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}", | 1424 | "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}", |
1436 | packet.Type, udpClient.AgentID, m_scene.RegionInfo.RegionName); | 1425 | packet.Type, client.Name, m_scene.RegionInfo.RegionName); |
1437 | } | 1426 | } |
1438 | } | 1427 | } |
1439 | 1428 | ||
1440 | protected void LogoutHandler(IClientAPI client) | 1429 | protected void LogoutHandler(IClientAPI client) |
1441 | { | 1430 | { |
1442 | client.SendLogoutPacket(); | 1431 | client.SendLogoutPacket(); |
1443 | if (client.IsActive) | 1432 | if (!client.IsLoggingOut) |
1444 | RemoveClient(((LLClientView)client).UDPClient); | 1433 | RemoveClient(client); |
1445 | } | 1434 | } |
1446 | } | 1435 | } |
1447 | } | 1436 | } |