aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs28
1 files changed, 23 insertions, 5 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
index 44a6ed6..d16837d 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
@@ -62,6 +62,9 @@ namespace OpenMetaverse
62 /// <summary>UDP socket, used in either client or server mode</summary> 62 /// <summary>UDP socket, used in either client or server mode</summary>
63 private Socket m_udpSocket; 63 private Socket m_udpSocket;
64 64
65 /// <summary>Flag to process packets asynchronously or synchronously</summary>
66 private bool m_asyncPacketHandling;
67
65 /// <summary>The all important shutdown flag</summary> 68 /// <summary>The all important shutdown flag</summary>
66 private volatile bool m_shutdownFlag = true; 69 private volatile bool m_shutdownFlag = true;
67 70
@@ -73,7 +76,6 @@ namespace OpenMetaverse
73 /// </summary> 76 /// </summary>
74 /// <param name="bindAddress">Local IP address to bind the server to</param> 77 /// <param name="bindAddress">Local IP address to bind the server to</param>
75 /// <param name="port">Port to listening for incoming UDP packets on</param> 78 /// <param name="port">Port to listening for incoming UDP packets on</param>
76 ///
77 public OpenSimUDPBase(IPAddress bindAddress, int port) 79 public OpenSimUDPBase(IPAddress bindAddress, int port)
78 { 80 {
79 m_localBindAddress = bindAddress; 81 m_localBindAddress = bindAddress;
@@ -87,13 +89,19 @@ namespace OpenMetaverse
87 /// the UDP socket. This value is passed up to the operating system 89 /// the UDP socket. This value is passed up to the operating system
88 /// and used in the system networking stack. Use zero to leave this 90 /// and used in the system networking stack. Use zero to leave this
89 /// value as the default</param> 91 /// value as the default</param>
92 /// <param name="asyncPacketHandling">Set this to true to start
93 /// receiving more packets while current packet handler callbacks are
94 /// still running. Setting this to false will complete each packet
95 /// callback before the next packet is processed</param>
90 /// <remarks>This method will attempt to set the SIO_UDP_CONNRESET flag 96 /// <remarks>This method will attempt to set the SIO_UDP_CONNRESET flag
91 /// on the socket to get newer versions of Windows to behave in a sane 97 /// on the socket to get newer versions of Windows to behave in a sane
92 /// manner (not throwing an exception when the remote side resets the 98 /// manner (not throwing an exception when the remote side resets the
93 /// connection). This call is ignored on Mono where the flag is not 99 /// connection). This call is ignored on Mono where the flag is not
94 /// necessary</remarks> 100 /// necessary</remarks>
95 public void Start(int recvBufferSize) 101 public void Start(int recvBufferSize, bool asyncPacketHandling)
96 { 102 {
103 m_asyncPacketHandling = asyncPacketHandling;
104
97 if (m_shutdownFlag) 105 if (m_shutdownFlag)
98 { 106 {
99 const int SIO_UDP_CONNRESET = -1744830452; 107 const int SIO_UDP_CONNRESET = -1744830452;
@@ -209,8 +217,10 @@ namespace OpenMetaverse
209 // to AsyncBeginReceive 217 // to AsyncBeginReceive
210 if (!m_shutdownFlag) 218 if (!m_shutdownFlag)
211 { 219 {
212 // start another receive - this keeps the server going! 220 // Asynchronous mode will start another receive before the
213 AsyncBeginReceive(); 221 // callback for this packet is even fired. Very parallel :-)
222 if (m_asyncPacketHandling)
223 AsyncBeginReceive();
214 224
215 // get the buffer that was created in AsyncBeginReceive 225 // get the buffer that was created in AsyncBeginReceive
216 // this is the received data 226 // this is the received data
@@ -230,7 +240,15 @@ namespace OpenMetaverse
230 } 240 }
231 catch (SocketException) { } 241 catch (SocketException) { }
232 catch (ObjectDisposedException) { } 242 catch (ObjectDisposedException) { }
233 //finally { wrappedBuffer.Dispose(); } 243 finally
244 {
245 //wrappedBuffer.Dispose();
246
247 // Synchronous mode waits until the packet callback completes
248 // before starting the receive to fetch another packet
249 if (!m_asyncPacketHandling)
250 AsyncBeginReceive();
251 }
234 252
235 } 253 }
236 } 254 }