From d31d02c373f4cf0671a8c6269c2035a5741b83cf Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 6 Nov 2008 20:10:39 +0000 Subject: * refactor: Split BeginRecieve() into BeginReceive() and BeginRobustReceive() --- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 28 ++++++++++++++-------- .../ClientStack/LindenUDP/Tests/TestLLUDPServer.cs | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index b9da83e..14d98d4 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -231,7 +231,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } } - BeginReceive(); + BeginRobustReceive(); if (packet != null) { @@ -274,16 +274,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_log.Error("[CLIENT]: Exception in processing packet - ignoring: ", e); } } - + /// /// Begin an asynchronous receive of the next bit of raw data /// protected virtual void BeginReceive() { + m_socket.BeginReceiveFrom( + RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref reusedEpSender, ReceivedData, null); + } + + /// + /// Begin a robust asynchronous receive of the next bit of raw data. Robust means that SocketExceptions are + /// automatically dealt with until the next set of valid UDP data is received. + /// + private void BeginRobustReceive() + { try { - m_socket.BeginReceiveFrom( - RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref reusedEpSender, ReceivedData, null); + BeginReceive(); } catch (SocketException e) { @@ -293,7 +302,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // the next set of UDP data is for a valid client. ResetServerEndPoint(e); } - } + } /// /// Reset the server endpoint @@ -301,7 +310,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// /// The exception that has triggered the reset. Can be null if there was no exception. /// - protected void ResetServerEndPoint(Exception e) + private void ResetServerEndPoint(Exception e) { try { @@ -315,8 +324,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP // ENDLESS LOOP ON PURPOSE! // We need to purge the UDP stream of crap from the client that disconnected nastily or the UDP server will die - // The only way to do that is to beginreceive again! - BeginReceive(); + // The only way to do that is to BeginRobustReceive again! + BeginRobustReceive(); } /// @@ -470,8 +479,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP m_log.Info("[UDPSERVER]: UDP socket bound, getting ready to listen"); ReceivedData = OnReceivedData; - m_socket.BeginReceiveFrom( - RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref reusedEpSender, ReceivedData, null); + BeginReceive(); m_log.Info("[UDPSERVER]: Listening on port " + newPort); } diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs index 67b8f42..b5f065d 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs @@ -52,7 +52,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests { ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); reusedEpSender = tuple.Sender; - ResetServerEndPoint(new SocketException()); + throw new SocketException(); ReceiveData(null); } } -- cgit v1.1