Пример #1
0
        /// <summary>
        /// Releases the resources used by this instance.
        /// </summary>
        /// <param name="disposing">
        /// True to release both managed and unmanaged resources; false to release only unmanaged resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    if (!(connectPool is null))
                    {
                        connectPool.Dispose();
                    }
                    connectPool = null;

                    peers = null;
                }

                isDisposed = true;
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeConnector"/> using the given parameters.
        /// </summary>
        /// <param name="peerList">List of peers (is used to add the connected node to)</param>
        /// <param name="bc">Blockchain database to use</param>
        /// <param name="cs">Client settings</param>
        public NodeConnector(ICollection <Node> peerList, IBlockchain bc, IClientSettings cs)
        {
            peers      = peerList;
            blockchain = bc;
            settings   = cs;

            int MaxConnections = 3;

            maxConnectionEnforcer = new Semaphore(MaxConnections, MaxConnections);

            int MaxConnectOps = 10;

            connectPool = new SocketAsyncEventArgsPool(MaxConnectOps);
            for (int i = 0; i < MaxConnectOps; i++)
            {
                var connectEventArg = new SocketAsyncEventArgs();
                connectEventArg.Completed += new EventHandler <SocketAsyncEventArgs>((sender, e) => ProcessConnect(e));
                connectPool.Push(connectEventArg);
            }
        }
Пример #3
0
        /// <summary>
        /// Releases the resources used by this instance.
        /// </summary>
        /// <param name="disposing">
        /// True to release both managed and unmanaged resources; false to release only unmanaged resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    if (!(maxConnectionEnforcer is null))
                    {
                        maxConnectionEnforcer.Dispose();
                    }
                    maxConnectionEnforcer = null;

                    if (!(connectPool is null))
                    {
                        connectPool.Dispose();
                    }
                    connectPool = null;

                    peers = null;
                }

                isDisposed = true;
            }
        }
Пример #4
0
        /// <summary>
        /// Releases the resources used by this class.
        /// </summary>
        /// <param name="disposing">
        /// True to release both managed and unmanaged resources; false to release only unmanaged resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    if (!(listenSocket is null))
                    {
                        listenSocket.Dispose();
                    }
                    listenSocket = null;

                    if (!(acceptPool is null))
                    {
                        acceptPool.Dispose();
                    }
                    acceptPool = null;

                    peers = null;
                }

                isDisposed = true;
            }
        }