From 8f5efc499456edd03d3d22e64a0151386cbf47b1 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Thu, 25 Jun 2009 07:50:02 +0000 Subject: - adds the possibility of setting the socket receive buffer size option for LLUDPServer. On windows .NET the default socket receive buffer size is 8192 bytes, on recent linux systems it's about 111K. both value can be a bit small for an OpenSim instance serving many clients. The socket receive buffer size can be configured via an OpenSim.ini config option - adds a general catch clause to LLUDPServer.OnReceivedData() to prevent it submerging when an unexpected Exception occurs. --- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 86 +++++++++++++--------- 1 file changed, 51 insertions(+), 35 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 0b17d1b..24bb502 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -76,6 +76,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP protected IPAddress listenIP = IPAddress.Parse("0.0.0.0"); protected IScene m_localScene; protected IAssetCache m_assetCache; + protected int m_clientSocketReceiveBuffer = 0; /// /// Manages authentication for agent circuits @@ -157,6 +158,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP { if (config.Contains("client_throttle_multiplier")) userSettings.ClientThrottleMultipler = config.GetFloat("client_throttle_multiplier"); + if (config.Contains("client_socket_rcvbuf_size")) + m_clientSocketReceiveBuffer = config.GetInt("client_socket_rcvbuf_size"); } m_log.DebugFormat("[CLIENT]: client_throttle_multiplier = {0}", userSettings.ClientThrottleMultipler); @@ -188,47 +191,54 @@ namespace OpenSim.Region.ClientStack.LindenUDP Packet packet = null; int numBytes = 1; EndPoint epSender = new IPEndPoint(IPAddress.Any, 0); + EndPoint epProxy = null; - if (EndReceive(out numBytes, result, ref epSender)) + try { - // Make sure we are getting zeroes when running off the - // end of grab / degrab packets from old clients - Array.Clear(RecvBuffer, numBytes, RecvBuffer.Length - numBytes); - - int packetEnd = numBytes - 1; - if (proxyPortOffset != 0) packetEnd -= 6; - - try - { - packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer); - } - catch (MalformedDataException e) - { - m_log.DebugFormat("[CLIENT]: Dropped Malformed Packet due to MalformedDataException: {0}", e.StackTrace); - } - catch (IndexOutOfRangeException e) + if (EndReceive(out numBytes, result, ref epSender)) { - m_log.DebugFormat("[CLIENT]: Dropped Malformed Packet due to IndexOutOfRangeException: {0}", e.StackTrace); - } - catch (Exception e) - { - m_log.Debug("[CLIENT]: " + e); - } - } + // Make sure we are getting zeroes when running off the + // end of grab / degrab packets from old clients + Array.Clear(RecvBuffer, numBytes, RecvBuffer.Length - numBytes); + + int packetEnd = numBytes - 1; + if (proxyPortOffset != 0) packetEnd -= 6; + + try + { + packet = PacketPool.Instance.GetPacket(RecvBuffer, ref packetEnd, ZeroBuffer); + } + catch (MalformedDataException e) + { + m_log.DebugFormat("[CLIENT]: Dropped Malformed Packet due to MalformedDataException: {0}", e.StackTrace); + } + catch (IndexOutOfRangeException e) + { + m_log.DebugFormat("[CLIENT]: Dropped Malformed Packet due to IndexOutOfRangeException: {0}", e.StackTrace); + } + catch (Exception e) + { + m_log.Debug("[CLIENT]: " + e); + } + } - EndPoint epProxy = null; - - if (proxyPortOffset != 0) - { - // If we've received a use circuit packet, then we need to decode an endpoint proxy, if one exists, - // before allowing the RecvBuffer to be overwritten by the next packet. - if (packet != null && packet.Type == PacketType.UseCircuitCode) + + if (proxyPortOffset != 0) { - epProxy = epSender; + // If we've received a use circuit packet, then we need to decode an endpoint proxy, if one exists, + // before allowing the RecvBuffer to be overwritten by the next packet. + if (packet != null && packet.Type == PacketType.UseCircuitCode) + { + epProxy = epSender; + } + + // Now decode the message from the proxy server + epSender = ProxyCodec.DecodeProxyMessage(RecvBuffer, ref numBytes); } - - // Now decode the message from the proxy server - epSender = ProxyCodec.DecodeProxyMessage(RecvBuffer, ref numBytes); + } + catch (Exception ex) + { + m_log.ErrorFormat("[CLIENT]: Exception thrown during EndReceive(): {0}", ex); } BeginRobustReceive(); @@ -324,6 +334,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP done = true; } + catch (Exception ex) + { + m_log.ErrorFormat("[CLIENT]: Exception thrown during BeginReceive(): {0}", ex); + } } } @@ -472,6 +486,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP ServerIncoming = new IPEndPoint(listenIP, (int)newPort); m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + if (0 != m_clientSocketReceiveBuffer) + m_socket.ReceiveBufferSize = m_clientSocketReceiveBuffer; m_socket.Bind(ServerIncoming); // Add flags to the UDP socket to prevent "Socket forcibly closed by host" // uint IOC_IN = 0x80000000; -- cgit v1.1