Exemplo n.º 1
0
        public virtual bool StartNetwork(string bindIp, int port, int threadCount = 1)
        {
            Assert(threadCount > 0);

            var acceptor = new AsyncAcceptor(bindIp, port);

            if (!acceptor.Bind())
            {
                FEL_LOG_ERROR("network", "StartNetwork failed to bind socket acceptor");
                return(false);
            }

            _acceptor    = acceptor;
            _threadCount = threadCount;
            _threads     = CreateThreads();

            if (_threads == null)
            {
                Assert(false);
                return(false);
            }

            for (int i = 0; i < _threadCount; ++i)
            {
                _threads[i].Start();
            }

            _acceptor.SetThreadIndexFactory(() => {
                return(SelectThreadWithMinConnections());
            });

            return(true);
        }
Exemplo n.º 2
0
        public virtual void StopNetwork()
        {
            if (_acceptor == null || _threads == null)
            {
                Assert(false);
                return;
            }

            _acceptor.Close();

            if (_threadCount != 0)
            {
                for (int i = 0; i < _threadCount; ++i)
                {
                    _threads[i].Stop();
                }
            }

            Wait();

            _acceptor    = null;
            _threads     = null;
            _threadCount = 0;
        }