/// <summary>
        /// Closes the listener.
        /// </summary>
        private void InternalClose(object state)
        {
            TcpAsyncOperation <int> operation = (TcpAsyncOperation <int>)state;

            try
            {
                lock (m_lock)
                {
                    while (m_channelQueue.Count > 0)
                    {
                        UaTcpReplyChannel channel = m_channelQueue.Dequeue();
                        channel.Abort();
                    }

                    while (m_acceptQueue.Count > 0)
                    {
                        TcpAsyncOperation <IReplySessionChannel> waitingAccept = m_acceptQueue.Dequeue();
                        waitingAccept.Fault(StatusCodes.BadServerHalted);
                    }

                    Stop();
                }

                operation.Complete(0);
            }
            catch (Exception e)
            {
                operation.Fault(e, StatusCodes.BadInternalError, "Could not close UA TCP listener.");
            }
        }
        /// <summary cref="ChannelListenerBase{T}.OnBeginAcceptChannel" />
        protected override IAsyncResult OnBeginAcceptChannel(TimeSpan timeout, AsyncCallback callback, object state)
        {
            TcpAsyncOperation <IReplySessionChannel> operation = new TcpAsyncOperation <IReplySessionChannel>(Utils.GetTimeout(timeout), callback, state);

            lock (m_lock)
            {
                if (m_channelQueue.Count > 0)
                {
                    UaTcpReplyChannel channel = m_channelQueue.Dequeue();
                    Utils.Trace("Channel Accepted: Id={0}", channel.Id);
                    operation.Complete(channel);
                    return(operation);
                }

                m_acceptQueue.Enqueue(operation);
            }

            return(operation);
        }