aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
diff options
context:
space:
mode:
authorMelanie2012-10-16 23:22:37 +0100
committerMelanie2012-10-16 23:22:37 +0100
commitc4fcfec24e8e1f9c0c6ab1b3491ae5f7612fd094 (patch)
tree31b65ffd42acaee2f0cfb3755f829a991e6610d1 /OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
parentMerge branch 'master' into careminster (diff)
parentMake it possible to separate start and stop lludp packet processing from the ... (diff)
downloadopensim-SC_OLD-c4fcfec24e8e1f9c0c6ab1b3491ae5f7612fd094.zip
opensim-SC_OLD-c4fcfec24e8e1f9c0c6ab1b3491ae5f7612fd094.tar.gz
opensim-SC_OLD-c4fcfec24e8e1f9c0c6ab1b3491ae5f7612fd094.tar.bz2
opensim-SC_OLD-c4fcfec24e8e1f9c0c6ab1b3491ae5f7612fd094.tar.xz
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs44
1 files changed, 27 insertions, 17 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
index cfe7c9d..82775fd 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
@@ -58,11 +58,12 @@ namespace OpenMetaverse
58 /// <summary>Flag to process packets asynchronously or synchronously</summary> 58 /// <summary>Flag to process packets asynchronously or synchronously</summary>
59 private bool m_asyncPacketHandling; 59 private bool m_asyncPacketHandling;
60 60
61 /// <summary>The all important shutdown flag</summary> 61 /// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary>
62 private volatile bool m_shutdownFlag = true; 62 public bool IsRunningInbound { get; private set; }
63 63
64 /// <summary>Returns true if the server is currently listening, otherwise false</summary> 64 /// <summary>Returns true if the server is currently sending outbound packets, otherwise false</summary>
65 public bool IsRunning { get { return !m_shutdownFlag; } } 65 /// <remarks>If IsRunningOut = false, then any request to send a packet is simply dropped.</remarks>
66 public bool IsRunningOutbound { get; private set; }
66 67
67 /// <summary> 68 /// <summary>
68 /// Default constructor 69 /// Default constructor
@@ -76,7 +77,7 @@ namespace OpenMetaverse
76 } 77 }
77 78
78 /// <summary> 79 /// <summary>
79 /// Start the UDP server 80 /// Start inbound UDP packet handling.
80 /// </summary> 81 /// </summary>
81 /// <param name="recvBufferSize">The size of the receive buffer for 82 /// <param name="recvBufferSize">The size of the receive buffer for
82 /// the UDP socket. This value is passed up to the operating system 83 /// the UDP socket. This value is passed up to the operating system
@@ -91,11 +92,11 @@ namespace OpenMetaverse
91 /// manner (not throwing an exception when the remote side resets the 92 /// manner (not throwing an exception when the remote side resets the
92 /// connection). This call is ignored on Mono where the flag is not 93 /// connection). This call is ignored on Mono where the flag is not
93 /// necessary</remarks> 94 /// necessary</remarks>
94 public void Start(int recvBufferSize, bool asyncPacketHandling) 95 public void StartInbound(int recvBufferSize, bool asyncPacketHandling)
95 { 96 {
96 m_asyncPacketHandling = asyncPacketHandling; 97 m_asyncPacketHandling = asyncPacketHandling;
97 98
98 if (m_shutdownFlag) 99 if (!IsRunningInbound)
99 { 100 {
100 const int SIO_UDP_CONNRESET = -1744830452; 101 const int SIO_UDP_CONNRESET = -1744830452;
101 102
@@ -123,8 +124,7 @@ namespace OpenMetaverse
123 124
124 m_udpSocket.Bind(ipep); 125 m_udpSocket.Bind(ipep);
125 126
126 // we're not shutting down, we're starting up 127 IsRunningInbound = true;
127 m_shutdownFlag = false;
128 128
129 // kick off an async receive. The Start() method will return, the 129 // kick off an async receive. The Start() method will return, the
130 // actual receives will occur asynchronously and will be caught in 130 // actual receives will occur asynchronously and will be caught in
@@ -134,28 +134,38 @@ namespace OpenMetaverse
134 } 134 }
135 135
136 /// <summary> 136 /// <summary>
137 /// Stops the UDP server 137 /// Start outbound UDP packet handling.
138 /// </summary> 138 /// </summary>
139 public void Stop() 139 public void StartOutbound()
140 { 140 {
141 if (!m_shutdownFlag) 141 IsRunningOutbound = true;
142 }
143
144 public void StopInbound()
145 {
146 if (IsRunningInbound)
142 { 147 {
143 // wait indefinitely for a writer lock. Once this is called, the .NET runtime 148 // wait indefinitely for a writer lock. Once this is called, the .NET runtime
144 // will deny any more reader locks, in effect blocking all other send/receive 149 // will deny any more reader locks, in effect blocking all other send/receive
145 // threads. Once we have the lock, we set shutdownFlag to inform the other 150 // threads. Once we have the lock, we set IsRunningInbound = false to inform the other
146 // threads that the socket is closed. 151 // threads that the socket is closed.
147 m_shutdownFlag = true; 152 IsRunningInbound = false;
148 m_udpSocket.Close(); 153 m_udpSocket.Close();
149 } 154 }
150 } 155 }
151 156
157 public void StopOutbound()
158 {
159 IsRunningOutbound = false;
160 }
161
152 private void AsyncBeginReceive() 162 private void AsyncBeginReceive()
153 { 163 {
154 // allocate a packet buffer 164 // allocate a packet buffer
155 //WrappedObject<UDPPacketBuffer> wrappedBuffer = Pool.CheckOut(); 165 //WrappedObject<UDPPacketBuffer> wrappedBuffer = Pool.CheckOut();
156 UDPPacketBuffer buf = new UDPPacketBuffer(); 166 UDPPacketBuffer buf = new UDPPacketBuffer();
157 167
158 if (!m_shutdownFlag) 168 if (IsRunningInbound)
159 { 169 {
160 try 170 try
161 { 171 {
@@ -208,7 +218,7 @@ namespace OpenMetaverse
208 { 218 {
209 // Asynchronous receive operations will complete here through the call 219 // Asynchronous receive operations will complete here through the call
210 // to AsyncBeginReceive 220 // to AsyncBeginReceive
211 if (!m_shutdownFlag) 221 if (IsRunningInbound)
212 { 222 {
213 // Asynchronous mode will start another receive before the 223 // Asynchronous mode will start another receive before the
214 // callback for this packet is even fired. Very parallel :-) 224 // callback for this packet is even fired. Very parallel :-)
@@ -248,7 +258,7 @@ namespace OpenMetaverse
248 258
249 public void AsyncBeginSend(UDPPacketBuffer buf) 259 public void AsyncBeginSend(UDPPacketBuffer buf)
250 { 260 {
251 if (!m_shutdownFlag) 261 if (IsRunningOutbound)
252 { 262 {
253 try 263 try
254 { 264 {