Exemple #1
0
        // is blocking call!
        protected void Destroy()
        {
            if (this.Address == null)
            {
                return;
            }

            this.isRunning = false;
            this.waitGroup.Wait();

            this.connectionsMutex.EnterWriteLock();
            foreach (Connection conn in this.connections.Values)
            {
                this.DisconnectClient(conn, DisconnectType.SHUTDOWN, null);
            }
            this.connections.Clear();
            this.connectionsMutex.ExitWriteLock();

            this.Socket.Close();
            Background.Stop();

            this.Address   = null;
            this.Socket    = null;
            this.listeners = null;

            this.connectGuard = null;
            this.connections  = null;
            this.listeners    = null;
        }
Exemple #2
0
        protected void Init(string address)
        {
            if (!address.Contains(":"))
            {
                throw new Exception("Port has to be specified");
            }

            string[] data = address.Split(':');
            this.Address = new IPEndPoint(IPAddress.Parse(data[0]), int.Parse(data[1]));

            this.listeners    = new List <Thread>();
            this.connectGuard = new ExecGuard();
            this.connections  = new Dictionary <uint, Connection>();

            this.bufferPool           = new Pool <byte[]>();
            this.bufferPool.Allocator = () => { return(new byte[Config.CfgMTU]); };

            this.connectionPool           = new Pool <Connection>();
            this.connectionPool.Allocator = () => { return(new Connection()); };

            Background.Start();
        }