Beispiel #1
0
int CServer::FindPending(UINT Item) const
{
	int	items = GetPendingCount();
	for (int i = 0; i < items; i++) {
		if (m_Pending[i] == Item)
			return(i);
	}
	return(-1);
}
Beispiel #2
0
// create a polling set
HRESULT CTestPolling::Test2()
{
    // simulate the following events in random order:
    //    socket added (did it succeed as expected)
    //    incoming data (write to a random pipe)
    //    WaitForNextEvent called (did it return an expected result/socket)
    //        Remove socket last notified about

    HRESULT hr = S_OK;
    HRESULT hrResult;
    PollEvent event;  
    const size_t c_maxSockets = 10;
    
    srand(100);

    ChkA(TestInit(c_maxSockets, 0));
    
   
    hrResult = _spPolling->WaitForNextEvent(&event, 0);
    ChkIfA(hrResult != S_FALSE, E_UNEXPECTED);    
    
    
    for (size_t index = 0; index < 1000; index++)
    {
        int randresult = ::rand() % 4;
        
        switch (randresult)
        {
            case 0:
            {
                // simulate a new socket being added
                if (_pipes.size() >= c_maxSockets)
                {
                    continue;
                }
                
                ChkA(CreateAndAddPipe());

                break;
            }
            
            case 1:
            {
                // simulate incoming data
                size_t size = _pipes.size();
                size_t itemindex;
                
                if (size == 0)
                {
                    continue;
                }
                
                itemindex = rand() % size;
                ChkA(WritePipe(&_pipes[itemindex]));
                
                break;
            }
            
            case 2:
            case 3:
            {
                int fd;
                size_t pending = GetPendingCount();
                if (pending == 0)
                {
                    continue;
                }
                
                ChkA(ConsumeEvent(&fd, NULL));
                
                if (randresult == 3)
                {
                    // simulate removing this pipe from the set
                    ChkA(RemovePipe(FindPipePairIndex(fd)));
                }
                break;
            } // case
        } // switch
    } // for

Cleanup:
    return hr;
}