diff options
author | Melanie | 2012-10-17 00:03:02 +0100 |
---|---|---|
committer | Melanie | 2012-10-17 00:03:02 +0100 |
commit | ad60a29c9303e68717ccc057988a36da0990b0ae (patch) | |
tree | a4e965250d291476b1449bd0e949e5e204cf0446 /OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | |
parent | Merge branch 'master' into careminster (diff) | |
parent | Add optional pool for the UDPPacketBuffer objects that handle all incoming UD... (diff) | |
download | opensim-SC-ad60a29c9303e68717ccc057988a36da0990b0ae.zip opensim-SC-ad60a29c9303e68717ccc057988a36da0990b0ae.tar.gz opensim-SC-ad60a29c9303e68717ccc057988a36da0990b0ae.tar.bz2 opensim-SC-ad60a29c9303e68717ccc057988a36da0990b0ae.tar.xz |
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | 31 |
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 82775fd..e7d8a30 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs | |||
@@ -30,6 +30,7 @@ using System.Net; | |||
30 | using System.Net.Sockets; | 30 | using System.Net.Sockets; |
31 | using System.Threading; | 31 | using System.Threading; |
32 | using log4net; | 32 | using log4net; |
33 | using OpenSim.Framework; | ||
33 | 34 | ||
34 | namespace OpenMetaverse | 35 | namespace 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) |
@@ -161,9 +178,12 @@ namespace OpenMetaverse | |||
161 | 178 | ||
162 | private void AsyncBeginReceive() | 179 | private void AsyncBeginReceive() |
163 | { | 180 | { |
164 | // allocate a packet buffer | 181 | UDPPacketBuffer buf; |
165 | //WrappedObject<UDPPacketBuffer> wrappedBuffer = Pool.CheckOut(); | 182 | |
166 | UDPPacketBuffer buf = new UDPPacketBuffer(); | 183 | if (UsePools) |
184 | buf = m_pool.GetObject(); | ||
185 | else | ||
186 | buf = new UDPPacketBuffer(); | ||
167 | 187 | ||
168 | if (IsRunningInbound) | 188 | if (IsRunningInbound) |
169 | { | 189 | { |
@@ -227,8 +247,6 @@ namespace OpenMetaverse | |||
227 | 247 | ||
228 | // get the buffer that was created in AsyncBeginReceive | 248 | // get the buffer that was created in AsyncBeginReceive |
229 | // this is the received data | 249 | // this is the received data |
230 | //WrappedObject<UDPPacketBuffer> wrappedBuffer = (WrappedObject<UDPPacketBuffer>)iar.AsyncState; | ||
231 | //UDPPacketBuffer buffer = wrappedBuffer.Instance; | ||
232 | UDPPacketBuffer buffer = (UDPPacketBuffer)iar.AsyncState; | 250 | UDPPacketBuffer buffer = (UDPPacketBuffer)iar.AsyncState; |
233 | 251 | ||
234 | try | 252 | try |
@@ -245,7 +263,8 @@ namespace OpenMetaverse | |||
245 | catch (ObjectDisposedException) { } | 263 | catch (ObjectDisposedException) { } |
246 | finally | 264 | finally |
247 | { | 265 | { |
248 | //wrappedBuffer.Dispose(); | 266 | if (UsePools) |
267 | m_pool.ReturnObject(buffer); | ||
249 | 268 | ||
250 | // Synchronous mode waits until the packet callback completes | 269 | // Synchronous mode waits until the packet callback completes |
251 | // before starting the receive to fetch another packet | 270 | // before starting the receive to fetch another packet |