コード例 #1
0
 public void Stop()
 {
     if (_mgmtServer != null)
     {
         _mgmtServer.Stop();
         _mgmtServer = null;
     }
     if (_tcpForwarder != null)
     {
         _tcpForwarder.Stop();
         _tcpForwarder = null;
     }
     if (_udpForwarder != null)
     {
         _udpForwarder.Stop();
         _udpForwarder = null;
     }
     if (_mgmt != null)
     {
         _mgmt.OnClose -= _mgmt_OnClose;
         _mgmt.Close();
         _mgmt = null;
     }
 }
コード例 #2
0
        public void Reload()
        {
            MgmtListener oldMgmt = null;

            try
            {
                _config = Config.Load();
                if (_issvc)
                {
                    if (_tcpForwarder != null)
                    {
                        _tcpForwarder.Stop();
                    }
                    if (_udpForwarder != null)
                    {
                        _udpForwarder.Stop();
                    }
                    if (_mgmtServer != null && _mgmtServer.mgmtPort != _config.mgmtPort)
                    {
                        oldMgmt     = _mgmtServer;
                        _mgmtServer = null;
                    }
                    if (_mgmtServer == null)
                    {
                        _mgmtServer = new MgmtListener(this, _config.mgmtPort);
                        _mgmtServer.Start();
                    }
                    if (!_config.enabled)
                    {
                        return;
                    }
                    ServerInfo server = GetCurrentServer();
                    _tcpForwarder = new TcpForwarder(server);
                    _tcpForwarder.Start();
                    _udpForwarder = new UdpForwarder(server);
                    _udpForwarder.Start();
                }
                else
                {
                    if (_mgmt == null)
                    {
                        ReConnectMgmtPort();
                    }
                    else
                    {
                        _mgmt.ReloadService();
                    }
                }
            }
            catch (Exception e)
            {
                // translate Microsoft language into human language
                // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use
                if (e is SocketException)
                {
                    SocketException se = (SocketException)e;
                    if (se.SocketErrorCode == SocketError.AccessDenied)
                    {
                        e = new Exception("Port already in use", e);
                    }
                }
                Logging.LogUsefulException(e);
                ReportError(e);
            }
            finally
            {
                if (oldMgmt != null)
                {
                    oldMgmt.Stop();
                }
            }
        }