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.cs48
1 files changed, 36 insertions, 12 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
index 6e6b3ef..3f7ca2b 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
@@ -31,6 +31,7 @@ using System.Net.Sockets;
31using System.Threading; 31using System.Threading;
32using log4net; 32using log4net;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Monitoring;
34 35
35namespace OpenMetaverse 36namespace OpenMetaverse
36{ 37{
@@ -60,14 +61,14 @@ namespace OpenMetaverse
60 private bool m_asyncPacketHandling; 61 private bool m_asyncPacketHandling;
61 62
62 /// <summary> 63 /// <summary>
63 /// Pool to use for handling data. May be null if UsePools = false; 64 /// Are we to use object pool(s) to reduce memory churn when receiving data?
64 /// </summary> 65 /// </summary>
65 protected OpenSim.Framework.Pool<UDPPacketBuffer> m_pool; 66 public bool UsePools { get; protected set; }
66 67
67 /// <summary> 68 /// <summary>
68 /// Are we to use object pool(s) to reduce memory churn when receiving data? 69 /// Pool to use for handling data. May be null if UsePools = false;
69 /// </summary> 70 /// </summary>
70 public bool UsePools { get; protected set; } 71 protected OpenSim.Framework.Pool<UDPPacketBuffer> Pool { get; private set; }
71 72
72 /// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary> 73 /// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary>
73 public bool IsRunningInbound { get; private set; } 74 public bool IsRunningInbound { get; private set; }
@@ -106,11 +107,6 @@ namespace OpenMetaverse
106 /// necessary</remarks> 107 /// necessary</remarks>
107 public void StartInbound(int recvBufferSize, bool asyncPacketHandling) 108 public void StartInbound(int recvBufferSize, bool asyncPacketHandling)
108 { 109 {
109 if (UsePools)
110 m_pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500);
111 else
112 m_pool = null;
113
114 m_asyncPacketHandling = asyncPacketHandling; 110 m_asyncPacketHandling = asyncPacketHandling;
115 111
116 if (!IsRunningInbound) 112 if (!IsRunningInbound)
@@ -180,12 +176,40 @@ namespace OpenMetaverse
180 IsRunningOutbound = false; 176 IsRunningOutbound = false;
181 } 177 }
182 178
179 protected virtual bool EnablePools()
180 {
181 if (!UsePools)
182 {
183 Pool = new Pool<UDPPacketBuffer>(() => new UDPPacketBuffer(), 500);
184
185 UsePools = true;
186
187 return true;
188 }
189
190 return false;
191 }
192
193 protected virtual bool DisablePools()
194 {
195 if (UsePools)
196 {
197 UsePools = false;
198
199 // We won't null out the pool to avoid a race condition with code that may be in the middle of using it.
200
201 return true;
202 }
203
204 return false;
205 }
206
183 private void AsyncBeginReceive() 207 private void AsyncBeginReceive()
184 { 208 {
185 UDPPacketBuffer buf; 209 UDPPacketBuffer buf;
186 210
187 if (UsePools) 211 if (UsePools)
188 buf = m_pool.GetObject(); 212 buf = Pool.GetObject();
189 else 213 else
190 buf = new UDPPacketBuffer(); 214 buf = new UDPPacketBuffer();
191 215
@@ -268,7 +292,7 @@ namespace OpenMetaverse
268 finally 292 finally
269 { 293 {
270 if (UsePools) 294 if (UsePools)
271 m_pool.ReturnObject(buffer); 295 Pool.ReturnObject(buffer);
272 296
273 // Synchronous mode waits until the packet callback completes 297 // Synchronous mode waits until the packet callback completes
274 // before starting the receive to fetch another packet 298 // before starting the receive to fetch another packet
@@ -310,4 +334,4 @@ namespace OpenMetaverse
310 catch (ObjectDisposedException) { } 334 catch (ObjectDisposedException) { }
311 } 335 }
312 } 336 }
313} 337} \ No newline at end of file