Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make it possible to separate start and stop lludp packet processing f…

…rom the console for debug processes.

This is controlled via the "debug lludp start <in|out|all>" and "debug lludp stop <in|out|all>" region console commands.
The command "debug lludp status" will show current status.
  • Loading branch information...
commit db4ca57590db44aba7d19530285091c7ea4c082c 1 parent 8459b98
Justin Clark-Casey authored October 16, 2012
116  OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
@@ -37,6 +37,7 @@
37 37
 using Nini.Config;
38 38
 using OpenMetaverse.Packets;
39 39
 using OpenSim.Framework;
  40
+using OpenSim.Framework.Console;
40 41
 using OpenSim.Framework.Monitoring;
41 42
 using OpenSim.Region.Framework.Scenes;
42 43
 using OpenMetaverse;
@@ -274,16 +275,21 @@ public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, b
274 275
 
275 276
         public void Start()
276 277
         {
277  
-            if (m_scene == null)
278  
-                throw new InvalidOperationException("[LLUDPSERVER]: Cannot LLUDPServer.Start() without an IScene reference");
  278
+            StartInbound();
  279
+            StartOutbound();
279 280
 
  281
+            m_elapsedMSSinceLastStatReport = Environment.TickCount;
  282
+        }
  283
+
  284
+        private void StartInbound()
  285
+        {
280 286
             m_log.InfoFormat(
281  
-                "[LLUDPSERVER]: Starting the LLUDP server in {0} mode",
  287
+                "[LLUDPSERVER]: Starting inbound packet processing for the LLUDP server in {0} mode",
282 288
                 m_asyncPacketHandling ? "asynchronous" : "synchronous");
283 289
 
284  
-            base.Start(m_recvBufferSize, m_asyncPacketHandling);
  290
+            base.StartInbound(m_recvBufferSize, m_asyncPacketHandling);
285 291
 
286  
-            // Start the packet processing threads
  292
+            // This thread will process the packets received that are placed on the packetInbox
287 293
             Watchdog.StartThread(
288 294
                 IncomingPacketHandler,
289 295
                 string.Format("Incoming Packets ({0})", m_scene.RegionInfo.RegionName),
@@ -292,7 +298,15 @@ public void Start()
292 298
                 true,
293 299
                 GetWatchdogIncomingAlarmData,
294 300
                 Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS);
  301
+        }
295 302
 
  303
+        private void StartOutbound()
  304
+        {
  305
+            m_log.Info("[LLUDPSERVER]: Starting outbound packet processing for the LLUDP server");
  306
+
  307
+            base.StartOutbound();
  308
+
  309
+            // This thread will process the packets received that are placed on the packetInbox
296 310
             Watchdog.StartThread(
297 311
                 OutgoingPacketHandler,
298 312
                 string.Format("Outgoing Packets ({0})", m_scene.RegionInfo.RegionName),
@@ -301,8 +315,13 @@ public void Start()
301 315
                 true,
302 316
                 GetWatchdogOutgoingAlarmData,
303 317
                 Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS);
  318
+        }
304 319
 
305  
-            m_elapsedMSSinceLastStatReport = Environment.TickCount;
  320
+        public new void Stop()
  321
+        {
  322
+            m_log.Info("[LLUDPSERVER]: Shutting down the LLUDP server for " + m_scene.RegionInfo.RegionName);
  323
+            base.StopOutbound();
  324
+            base.StopInbound();
306 325
         }
307 326
 
308 327
         /// <summary>
@@ -327,12 +346,6 @@ private string GetWatchdogOutgoingAlarmData()
327 346
                 m_currentOutgoingClient != null ? m_currentOutgoingClient.Name : "none");
328 347
         }
329 348
 
330  
-        public new void Stop()
331  
-        {
332  
-            m_log.Info("[LLUDPSERVER]: Shutting down the LLUDP server for " + m_scene.RegionInfo.RegionName);
333  
-            base.Stop();
334  
-        }
335  
-
336 349
         public void AddScene(IScene scene)
337 350
         {
338 351
             if (m_scene != null)
@@ -349,6 +362,81 @@ public void AddScene(IScene scene)
349 362
 
350 363
             m_scene = (Scene)scene;
351 364
             m_location = new Location(m_scene.RegionInfo.RegionHandle);
  365
+
  366
+            MainConsole.Instance.Commands.AddCommand(
  367
+                "Debug",
  368
+                false,
  369
+                "debug lludp start",
  370
+                "debug lludp start <in|out|all>",
  371
+                "Control LLUDP packet processing.",
  372
+                "No effect if packet processing has already started.\n"
  373
+                    + "in  - start inbound processing.\n"
  374
+                    + "out - start outbound processing.\n"
  375
+                    + "all - start in and outbound processing.\n",
  376
+                HandleStartCommand);
  377
+
  378
+            MainConsole.Instance.Commands.AddCommand(
  379
+                "Debug",
  380
+                false,
  381
+                "debug lludp stop",
  382
+                "debug lludp stop <in|out|all>",
  383
+                "Stop LLUDP packet processing.",
  384
+                "No effect if packet processing has already stopped.\n"
  385
+                    + "in  - stop inbound processing.\n"
  386
+                    + "out - stop outbound processing.\n"
  387
+                    + "all - stop in and outbound processing.\n",
  388
+                HandleStopCommand);
  389
+
  390
+            MainConsole.Instance.Commands.AddCommand(
  391
+                "Debug",
  392
+                false,
  393
+                "debug lludp status",
  394
+                "debug lludp status",
  395
+                "Return status of LLUDP packet processing.",
  396
+                HandleStatusCommand);
  397
+        }
  398
+
  399
+        private void HandleStartCommand(string module, string[] args)
  400
+        {
  401
+            if (args.Length != 4)
  402
+            {
  403
+                MainConsole.Instance.Output("Usage: debug lludp start <in|out|all>");
  404
+                return;
  405
+            }
  406
+
  407
+            string subCommand = args[3];
  408
+
  409
+            if (subCommand == "in" || subCommand == "all")
  410
+                StartInbound();
  411
+
  412
+            if (subCommand == "out" || subCommand == "all")
  413
+                StartOutbound();
  414
+        }
  415
+
  416
+        private void HandleStopCommand(string module, string[] args)
  417
+        {
  418
+            if (args.Length != 4)
  419
+            {
  420
+                MainConsole.Instance.Output("Usage: debug lludp stop <in|out|all>");
  421
+                return;
  422
+            }
  423
+
  424
+            string subCommand = args[3];
  425
+
  426
+            if (subCommand == "in" || subCommand == "all")
  427
+                StopInbound();
  428
+
  429
+            if (subCommand == "out" || subCommand == "all")
  430
+                StopOutbound();
  431
+        }
  432
+
  433
+        private void HandleStatusCommand(string module, string[] args)
  434
+        {
  435
+            MainConsole.Instance.OutputFormat(
  436
+                "IN  LLUDP packet processing for {0} is {1}", m_scene.Name, IsRunningInbound ? "enabled" : "disabled");
  437
+
  438
+            MainConsole.Instance.OutputFormat(
  439
+                "OUT LLUDP packet processing for {0} is {1}", m_scene.Name, IsRunningOutbound ? "enabled" : "disabled");
352 440
         }
353 441
 
354 442
         public bool HandlesRegion(Location x)
@@ -1174,7 +1262,7 @@ private void IncomingPacketHandler()
1174 1262
             // on to en-US to avoid number parsing issues
1175 1263
             Culture.SetCurrentCulture();
1176 1264
 
1177  
-            while (base.IsRunning)
  1265
+            while (base.IsRunningInbound)
1178 1266
             {
1179 1267
                 try
1180 1268
                 {
@@ -1216,7 +1304,7 @@ private void OutgoingPacketHandler()
1216 1304
             // Action generic every round
1217 1305
             Action<IClientAPI> clientPacketHandler = ClientOutgoingPacketHandler;
1218 1306
 
1219  
-            while (base.IsRunning)
  1307
+            while (base.IsRunningOutbound)
1220 1308
             {
1221 1309
                 try
1222 1310
                 {
44  OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
@@ -58,11 +58,12 @@ public abstract class OpenSimUDPBase
58 58
         /// <summary>Flag to process packets asynchronously or synchronously</summary>
59 59
         private bool m_asyncPacketHandling;
60 60
 
61  
-        /// <summary>The all important shutdown flag</summary>
62  
-        private volatile bool m_shutdownFlag = true;
  61
+        /// <summary>Returns true if the server is currently listening for inbound packets, otherwise false</summary>
  62
+        public bool IsRunningInbound { get; private set; }
63 63
 
64  
-        /// <summary>Returns true if the server is currently listening, otherwise false</summary>
65  
-        public bool IsRunning { get { return !m_shutdownFlag; } }
  64
+        /// <summary>Returns true if the server is currently sending outbound packets, otherwise false</summary>
  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 68
         /// <summary>
68 69
         /// Default constructor
@@ -76,7 +77,7 @@ public OpenSimUDPBase(IPAddress bindAddress, int port)
76 77
         }
77 78
 
78 79
         /// <summary>
79  
-        /// Start the UDP server
  80
+        /// Start inbound UDP packet handling.
80 81
         /// </summary>
81 82
         /// <param name="recvBufferSize">The size of the receive buffer for 
82 83
         /// the UDP socket. This value is passed up to the operating system 
@@ -91,11 +92,11 @@ public OpenSimUDPBase(IPAddress bindAddress, int port)
91 92
         /// manner (not throwing an exception when the remote side resets the
92 93
         /// connection). This call is ignored on Mono where the flag is not
93 94
         /// necessary</remarks>
94  
-        public void Start(int recvBufferSize, bool asyncPacketHandling)
  95
+        public void StartInbound(int recvBufferSize, bool asyncPacketHandling)
95 96
         {
96 97
             m_asyncPacketHandling = asyncPacketHandling;
97 98
 
98  
-            if (m_shutdownFlag)
  99
+            if (!IsRunningInbound)
99 100
             {
100 101
                 const int SIO_UDP_CONNRESET = -1744830452;
101 102
 
@@ -127,8 +128,7 @@ public void Start(int recvBufferSize, bool asyncPacketHandling)
127 128
 
128 129
                 m_udpSocket.Bind(ipep);
129 130
 
130  
-                // we're not shutting down, we're starting up
131  
-                m_shutdownFlag = false;
  131
+                IsRunningInbound = true;
132 132
 
133 133
                 // kick off an async receive.  The Start() method will return, the
134 134
                 // actual receives will occur asynchronously and will be caught in
@@ -138,28 +138,38 @@ public void Start(int recvBufferSize, bool asyncPacketHandling)
138 138
         }
139 139
 
140 140
         /// <summary>
141  
-        /// Stops the UDP server
  141
+        /// Start outbound UDP packet handling.
142 142
         /// </summary>
143  
-        public void Stop()
  143
+        public void StartOutbound()
144 144
         {
145  
-            if (!m_shutdownFlag)
  145
+            IsRunningOutbound = true;
  146
+        }
  147
+
  148
+        public void StopInbound()
  149
+        {
  150
+            if (IsRunningInbound)
146 151
             {
147 152
                 // wait indefinitely for a writer lock.  Once this is called, the .NET runtime
148 153
                 // will deny any more reader locks, in effect blocking all other send/receive
149  
-                // threads.  Once we have the lock, we set shutdownFlag to inform the other
  154
+                // threads.  Once we have the lock, we set IsRunningInbound = false to inform the other
150 155
                 // threads that the socket is closed.
151  
-                m_shutdownFlag = true;
  156
+                IsRunningInbound = false;
152 157
                 m_udpSocket.Close();
153 158
             }
154 159
         }
155 160
 
  161
+        public void StopOutbound()
  162
+        {
  163
+            IsRunningOutbound = false;
  164
+        }
  165
+
156 166
         private void AsyncBeginReceive()
157 167
         {
158 168
             // allocate a packet buffer
159 169
             //WrappedObject<UDPPacketBuffer> wrappedBuffer = Pool.CheckOut();
160 170
             UDPPacketBuffer buf = new UDPPacketBuffer();
161 171
 
162  
-            if (!m_shutdownFlag)
  172
+            if (IsRunningInbound)
163 173
             {
164 174
                 try
165 175
                 {
@@ -212,7 +222,7 @@ private void AsyncEndReceive(IAsyncResult iar)
212 222
         {
213 223
             // Asynchronous receive operations will complete here through the call
214 224
             // to AsyncBeginReceive
215  
-            if (!m_shutdownFlag)
  225
+            if (IsRunningInbound)
216 226
             {
217 227
                 // Asynchronous mode will start another receive before the
218 228
                 // callback for this packet is even fired. Very parallel :-)
@@ -252,7 +262,7 @@ private void AsyncEndReceive(IAsyncResult iar)
252 262
 
253 263
         public void AsyncBeginSend(UDPPacketBuffer buf)
254 264
         {
255  
-            if (!m_shutdownFlag)
  265
+            if (IsRunningOutbound)
256 266
             {
257 267
                 try
258 268
                 {

0 notes on commit db4ca57

Please sign in to comment.
Something went wrong with that request. Please try again.