aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs31
1 files changed, 25 insertions, 6 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
index 828c23c..6e6b3ef 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
@@ -30,6 +30,7 @@ using System.Net;
30using System.Net.Sockets; 30using System.Net.Sockets;
31using System.Threading; 31using System.Threading;
32using log4net; 32using log4net;
33using OpenSim.Framework;
33 34
34namespace OpenMetaverse 35namespace OpenMetaverse
35{ 36{
@@ -58,6 +59,16 @@ namespace OpenMetaverse
58 /// <summary>Flag to process packets asynchronously or synchronously</summary> 59 /// <summary>Flag to process packets asynchronously or synchronously</summary>
59 private bool m_asyncPacketHandling; 60 private bool m_asyncPacketHandling;
60 61
62 /// <summary>
63 /// Pool to use for handling data. May be null if UsePools = false;
64 /// </summary>
65 protected OpenSim.Framework.Pool<UDPPacketBuffer> m_pool;
66
67 /// <summary>
68 /// Are we to use object pool(s) to reduce memory churn when receiving data?
69 /// </summary>
70 public bool UsePools { get; protected set; }
71
61 /// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary> 72 /// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary>
62 public bool IsRunningInbound { get; private set; } 73 public bool IsRunningInbound { get; private set; }
63 74
@@ -70,6 +81,7 @@ namespace OpenMetaverse
70 /// </summary> 81 /// </summary>
71 /// <param name="bindAddress">Local IP address to bind the server to</param> 82 /// <param name="bindAddress">Local IP address to bind the server to</param>
72 /// <param name="port">Port to listening for incoming UDP packets on</param> 83 /// <param name="port">Port to listening for incoming UDP packets on</param>
84 /// /// <param name="usePool">Are we to use an object pool to get objects for handing inbound data?</param>
73 public OpenSimUDPBase(IPAddress bindAddress, int port) 85 public OpenSimUDPBase(IPAddress bindAddress, int port)
74 { 86 {
75 m_localBindAddress = bindAddress; 87 m_localBindAddress = bindAddress;
@@ -94,6 +106,11 @@ namespace OpenMetaverse
94 /// necessary</remarks> 106 /// necessary</remarks>
95 public void StartInbound(int recvBufferSize, bool asyncPacketHandling) 107 public void StartInbound(int recvBufferSize, bool asyncPacketHandling)
96 { 108 {
109 if (UsePools)
110 m_pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500);
111 else
112 m_pool = null;
113
97 m_asyncPacketHandling = asyncPacketHandling; 114 m_asyncPacketHandling = asyncPacketHandling;
98 115
99 if (!IsRunningInbound) 116 if (!IsRunningInbound)
@@ -165,9 +182,12 @@ namespace OpenMetaverse
165 182
166 private void AsyncBeginReceive() 183 private void AsyncBeginReceive()
167 { 184 {
168 // allocate a packet buffer 185 UDPPacketBuffer buf;
169 //WrappedObject<UDPPacketBuffer> wrappedBuffer = Pool.CheckOut(); 186
170 UDPPacketBuffer buf = new UDPPacketBuffer(); 187 if (UsePools)
188 buf = m_pool.GetObject();
189 else
190 buf = new UDPPacketBuffer();
171 191
172 if (IsRunningInbound) 192 if (IsRunningInbound)
173 { 193 {
@@ -231,8 +251,6 @@ namespace OpenMetaverse
231 251
232 // get the buffer that was created in AsyncBeginReceive 252 // get the buffer that was created in AsyncBeginReceive
233 // this is the received data 253 // this is the received data
234 //WrappedObject<UDPPacketBuffer> wrappedBuffer = (WrappedObject<UDPPacketBuffer>)iar.AsyncState;
235 //UDPPacketBuffer buffer = wrappedBuffer.Instance;
236 UDPPacketBuffer buffer = (UDPPacketBuffer)iar.AsyncState; 254 UDPPacketBuffer buffer = (UDPPacketBuffer)iar.AsyncState;
237 255
238 try 256 try
@@ -249,7 +267,8 @@ namespace OpenMetaverse
249 catch (ObjectDisposedException) { } 267 catch (ObjectDisposedException) { }
250 finally 268 finally
251 { 269 {
252 //wrappedBuffer.Dispose(); 270 if (UsePools)
271 m_pool.ReturnObject(buffer);
253 272
254 // Synchronous mode waits until the packet callback completes 273 // Synchronous mode waits until the packet callback completes
255 // before starting the receive to fetch another packet 274 // before starting the receive to fetch another packet