Пример #1
0
        public static void TestWHIPServer_Start_Stop_Start_DoesntThrow()
        {
            LOG.Info($"Executing {nameof(TestWHIPServer_Start_Stop_Start_DoesntThrow)}");
            using (var server = new WHIPServer(
                       (req, respHandler, context) => { },
                       DEFAULT_ADDRESS,
                       DEFAULT_PORT,
                       DEFAULT_PASSWORD,
                       DEFAULT_BACKLOG_LENGTH
                       )) {
                using (var timeout = new System.Threading.Timer(
                           state => server.Stop(),
                           null,
                           TimeSpan.FromMilliseconds(200),
                           TimeSpan.FromMilliseconds(-1)              // No repeat
                           )) {
                    server.Start();
                }

                using (var timeout = new System.Threading.Timer(
                           state => server.Stop(),
                           null,
                           TimeSpan.FromMilliseconds(200),
                           TimeSpan.FromMilliseconds(-1)              // No repeat
                           )) {
                    Assert.DoesNotThrow(server.Start);
                }
            }
        }
Пример #2
0
        public static void TestWHIPServer_Ctor1Basic_DoesntThrow()
        {
            LOG.Info($"Executing {nameof(TestWHIPServer_Ctor1Basic_DoesntThrow)}");
            WHIPServer server = null;

            Assert.DoesNotThrow(() => {
                server = new WHIPServer((req, respHandler, context) => { });
            });
            server?.Dispose();
        }
Пример #3
0
 public static void TestWHIPServer_Stop_Fresh_DoesntThrow()
 {
     LOG.Info($"Executing {nameof(TestWHIPServer_Start_DoesntThrow)}");
     using (var server = new WHIPServer(
                (req, respHandler, context) => { },
                DEFAULT_ADDRESS,
                DEFAULT_PORT,
                DEFAULT_PASSWORD,
                DEFAULT_BACKLOG_LENGTH
                )) {
         Assert.DoesNotThrow(server.Stop);
     }
 }
Пример #4
0
 public static void TestWHIPServer_Stop_AfterStarted_DoesntThrow()
 {
     LOG.Info($"Executing {nameof(TestWHIPServer_Start_DoesntThrow)}");
     using (var server = new WHIPServer(
                (req, respHandler, context) => { },
                DEFAULT_ADDRESS,
                DEFAULT_PORT,
                DEFAULT_PASSWORD,
                DEFAULT_BACKLOG_LENGTH
                ))
         using (var task = new Task(server.Start)) {
             task.Start();
             System.Threading.Thread.Sleep(200);
             Assert.DoesNotThrow(server.Stop);
             System.Threading.Thread.Sleep(600);
         }
 }
Пример #5
0
        /// <summary>
        /// Stop the service and tells existing connections to finish off.
        /// </summary>
        public void Stop()
        {
            LOG.Debug($"{_address}:{_port} - Stopping service.");

            try {
                _server?.Stop();
                Thread.Sleep(100);
            }
            finally {
                _server?.Dispose();
                _server = null;
                Thread.Sleep(600);                 // Wait for the server to clear.
                _serviceTask?.Dispose();
                _serviceTask = null;
                _pidFileManager?.SetStatus(PIDFileManager.Status.Ready);
            }

            _requests?.CompleteAdding();
        }
Пример #6
0
        /// <summary>
        /// Starts up the service in a seperate thread.
        /// </summary>
        public void Start()
        {
            if (_server != null)
            {
                throw new InvalidOperationException("Cannot start a running service without stopping it first!");
            }
            LOG.Debug($"{_address}:{_port} - Starting service");

            _server      = new WHIPServer(RequestReceivedDelegate, _address, _port, _password, _listenBacklogLength);
            _serviceTask = new Task(_server.Start, TaskCreationOptions.LongRunning);
            _serviceTask.ContinueWith(ServerTaskExceptionHandler, TaskContinuationOptions.OnlyOnFaulted);

            _serviceTask.Start();
            _pidFileManager?.SetStatus(PIDFileManager.Status.Running);

            _requests = new BlockingCollection <Request>();

            Task.Run(() => { foreach (var request in _requests.GetConsumingEnumerable())
                             {
                                 ProcessRequest(request);
                             }
                     });
            Task.Run(() => { foreach (var request in _requests.GetConsumingEnumerable())
                             {
                                 ProcessRequest(request);
                             }
                     });
            Task.Run(() => { foreach (var request in _requests.GetConsumingEnumerable())
                             {
                                 ProcessRequest(request);
                             }
                     });
            Task.Run(() => { foreach (var request in _requests.GetConsumingEnumerable())
                             {
                                 ProcessRequest(request);
                             }
                     });
        }