コード例 #1
0
 /// <summary>
 /// Method responsible for disconnect client from server.
 /// </summary>
 public void Disconnect()
 {
     try
     {
         _networkListener.Stop();
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}.");
     }
 }
コード例 #2
0
        public void Stop()
        {
            running = false;

            listener.Stop();
            if (listenerThread == null)
            {
                return;
            }
            bool joined = listenerThread.Join(10000);

            if (!joined && listenerThread.ThreadState != ThreadState.Stopped)
            {
                logger.Warn("Failed to shut down ChannelListener.");
            }
        }
コード例 #3
0
ファイル: DicomServer.cs プロジェクト: fo-dicom/fo-dicom
        /// <summary>
        /// Listen indefinitely for network connections on the specified port.
        /// </summary>
        private async Task ListenForConnectionsAsync()
        {
            INetworkListener listener = null;

            try
            {
                var noDelay = Options?.TcpNoDelay ?? DicomServiceOptions.Default.TcpNoDelay;

                listener = NetworkManager.CreateNetworkListener(IPAddress, Port);
                await listener.StartAsync().ConfigureAwait(false);

                IsListening = true;

                while (!_cancellationSource.IsCancellationRequested)
                {
                    await _hasNonMaxServicesFlag.WaitAsync().ConfigureAwait(false);

                    var networkStream = await listener
                                        .AcceptNetworkStreamAsync(_certificateName, noDelay, _cancellationSource.Token)
                                        .ConfigureAwait(false);

                    if (networkStream != null)
                    {
                        var scp = CreateScp(networkStream);
                        if (Options != null)
                        {
                            scp.Options = Options;
                        }

                        var serviceTask = scp.RunAsync();
                        lock (_services)
                        {
                            _services.Add(new RunningDicomService(scp, serviceTask));
                        }

                        _hasServicesFlag.Set();
                        if (IsServicesAtMax)
                        {
                            _hasNonMaxServicesFlag.Reset();
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception e)
            {
                Logger.Error("Exception listening for DICOM services, {@error}", e);

                Stop();
                Exception = e;
            }
            finally
            {
                listener?.Stop();
                IsListening = false;
            }
        }
コード例 #4
0
 /// <summary>
 /// Stop the listener
 /// </summary>
 public void Stop()
 {
     _left.Stop();
     _right.Stop();
 }
コード例 #5
0
 public virtual async ValueTask UnbindAsync(CancellationToken cancellationToken = default)
 {
     _logger.UnbindListenSocket(_ipEndpoint);
     _listener.Stop();
 }
コード例 #6
0
        /// <summary>
        /// Stop the service, waiting for a period of time for before shutdown
        /// </summary>
        /// <param name="timeout">The number of milliseconds to wait, 0 for immediate shutdown, &lt; 0 for infinite wait</param>
        public void Stop(int timeout)
        {
            if ((Interlocked.CompareExchange(ref _state,
                                             (int)ServiceState.StopPending, (int)ServiceState.Running) ==
                 (int)ServiceState.Running))
            {
                try
                {
                    NewConnectionEvent = null;

                    lock (_subServices)
                    {
                        foreach (ProxyNetworkService subService in _subServices)
                        {
                            subService.Stop(timeout);
                        }
                    }

                    _listener.Stop();

                    // Only stop connections at the root
                    if (_parentService == null)
                    {
                        ConnectionEntry[] graphs;

                        lock (_connections)
                        {
                            graphs = _connections.ToArray();
                        }

                        if (graphs.Length > 0)
                        {
                            foreach (ConnectionEntry g in graphs)
                            {
                                if (timeout == 0)
                                {
                                    CloseConnection(g);
                                }
                                else
                                {
                                    g.SetTimeout(timeout, false);
                                }
                            }
                        }
                        else
                        {
                            CompleteStop();
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogException(ex);
                }
            }
            else if ((timeout == 0) && (_state == (int)ServiceState.StopPending) && (_parentService == null))
            {
                ConnectionEntry[] graphs;

                lock (_connections)
                {
                    graphs = _connections.ToArray();
                }

                foreach (ConnectionEntry g in graphs)
                {
                    CloseConnection(g);
                }
            }
        }