예제 #1
0
파일: Daemon.cs 프로젝트: vmas/rsync.net
 public static int DaemonMain(Options options)
 {
     ServerOptions = options;
     config        = new Configuration(ServerOptions.configFile);
     if (config.LoadParm(options))
     {
         StartAcceptLoop(options.rsyncPort);
     }
     return(-1);
 }
예제 #2
0
파일: Daemon.cs 프로젝트: vmas/rsync.net
        public static void StartAcceptLoop(int port)
        {
            IPAddress localAddr = IPAddress.Parse(ServerOptions.bindAddress);

            Server = new TcpListener(localAddr, port); //Switched to this one because TcpListener(port) is obsolete
            //Server = new TcpListener(port);

            try
            {
                Server.Start();
            }
            catch (Exception)
            {
                MainClass.Exit("Can't listening address " + ServerOptions.bindAddress + " on port " + port, null);
                System.Environment.Exit(0);
            }
            Log.WriteLine("WinRSyncd starting, listening on port " + port);
            StopServer    = false;
            ClientSockets = new List <TCPSocketListener>();
            while (!StopServer)
            {
                try
                {
                    Socket soc = Server.AcceptSocket();
                    if (!config.LoadParm(ServerOptions))
                    {
                        continue;
                    }
                    TCPSocketListener socketListener = new TCPSocketListener(soc, ref ClientSockets);
                    lock (ClientSockets)
                    {
                        ClientSockets.Add(socketListener);
                    }
                    socketListener.StartSocketListener();
                    for (int i = 0; i < ClientSockets.Count; i++)
                    {
                        if (ClientSockets[i] == null)
                        {
                            ClientSockets.RemoveAt(i);
                        }
                    }
                }
                catch (SocketException)
                {
                    StopServer = true;
                }
            }
            if (ServerOptions.logFile != null)
            {
                ServerOptions.logFile.Close();
            }
        }
예제 #3
0
        public static void StartAcceptLoop(int port)
        {
            var localAddr = IPAddress.Parse(ServerOptions.BindAddress);

            _server = new TcpListener(localAddr, port); //Switched to this one because TcpListener(port) is obsolete
            //Server = new TcpListener(port);


            _server.Start();

            Log.WriteLine("WinRSyncd starting, listening on port " + port);
            _stopServer = false;
            lock (_clientSockets)
            {
                _clientSockets = new List <TcpSocketListener>();
            }
            while (!_stopServer)
            {
                try
                {
                    var soc = _server.AcceptSocket();
                    if (!Config.LoadParm(ServerOptions))
                    {
                        continue;
                    }
                    var socketListener = new TcpSocketListener(soc, ref _clientSockets);
                    lock (_clientSockets)
                    {
                        _clientSockets.Add(socketListener);
                    }
                    socketListener.StartSocketListener();
                    for (var i = 0; i < _clientSockets.Count; i++)
                    {
                        if (_clientSockets[i] == null)
                        {
                            _clientSockets.RemoveAt(i);
                        }
                    }
                }
                catch (SocketException)
                {
                    _stopServer = true;
                }
            }
            if (ServerOptions.LogFile != null)
            {
                ServerOptions.LogFile.Close();
            }
        }
예제 #4
0
 public static int DaemonMain(Options options)
 {
     ServerOptions = options;
     config = new Configuration(ServerOptions.configFile);
     if (config.LoadParm(options))
     {
         StartAcceptLoop(options.rsyncPort);
     }
     return -1;
 }