示例#1
0
        public void Pop()
        {
            // Create a new heap.
            ConcurrentBinaryMinHeap <int> heap = new ConcurrentBinaryMinHeap <int>();

            // Ensure that the heap is empty.
            Assert.That(heap.Count, Is.EqualTo(0));

            // Expect Pop() to return null for an empty heap.
            Assert.That(heap.Pop(), Is.EqualTo(null));

            // Ensure that the heap is empty.
            Assert.That(heap.Count, Is.EqualTo(0));

            // Ensure that the heap is empty.
            Assert.That(heap.Count, Is.EqualTo(0));

            // Store an element and insert it into the heap.
            PriorityValuePair <int> elem = new PriorityValuePair <int>(1f, 2);

            heap.Push(elem);

            // Ensure that the element was inserted into the heap.
            Assert.That(heap.Count, Is.EqualTo(1));
            Assert.That(heap.Peek(), Is.EqualTo(elem));

            // Ensure that the returned element points to the same object we stored earlier.
            Assert.That(heap.Pop(), Is.EqualTo(elem));

            // Ensure that the element was removed from the heap.
            Assert.That(heap.Count, Is.EqualTo(0));
        }
示例#2
0
        void AceptNewClient(SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success)
            {
                m_MaxConnectionSemaphore.Release();
                m_TcpClientConnected.Set();
                return;
            }

            var client = e.AcceptSocket;

            m_TcpClientConnected.Set();

            var session = RegisterSession(client, new AsyncSocketSession <TAppSession, TCommandInfo>(client, Protocol.CreateCommandReader(AppServer)));

            if (session != null)
            {
                //Get the socket for the accepted client connection and put it into the
                //ReadEventArg object user token
                //////SocketAsyncEventArgsProxy socketEventArgsProxy;
                //////if (m_ReadWritePool.TryPop(out socketEventArgsProxy))
                //////{
                //////    session.SocketAsyncProxy = socketEventArgsProxy;
                //////    session.Closed += new EventHandler<SocketSessionClosedEventArgs>(session_Closed);
                //////    session.Start();
                //////    return;
                //////}
                SocketAsyncEventArgsProxy socketEventArgsProxy = m_ReadWritePool.Pop().Value;
                session.SocketAsyncProxy = socketEventArgsProxy;
                session.Closed          += new EventHandler <SocketSessionClosedEventArgs>(session_Closed);
                session.Start();
                return;

                AppServer.Logger.LogError("There is no enough buffer block to arrange to new accepted client!");
            }

            Async.Run(() => client.SafeCloseClientSocket(AppServer.Logger));
            ////////SmartThreadPool smartThreadPool = new SmartThreadPool();
            ////////IWorkItemResult wir1 = smartThreadPool.QueueWorkItem(() => {
            ////////    client.SafeCloseClientSocket(AppServer.Logger);
            ////////});
            ////////bool success = SmartThreadPool.WaitAll(new IWorkItemResult[] { wir1 });
            //////////if (success)  result1 = (int)wir1.Result;
            ////////smartThreadPool.Shutdown();

            m_MaxConnectionSemaphore.Release();
        }