예제 #1
0
int TestSynchTimerQueue(int argc, char* argv[])
{
	int index;
	HANDLE hTimerQueue;
	HANDLE hTimers[TIMER_COUNT];
	APC_DATA apcData[TIMER_COUNT];

	g_Event = CreateEvent(NULL, TRUE, FALSE, NULL);

	hTimerQueue = CreateTimerQueue();

	if (!hTimerQueue)
	{
		printf("CreateTimerQueue failed (%d)\n", (int) GetLastError());
		return -1;
	}

	for (index = 0; index < TIMER_COUNT; index++)
	{
		apcData[index].TimerId = index;
		apcData[index].StartTime = GetTickCount();
		apcData[index].DueTime = (index * 100) + 500;
		apcData[index].Period = 1000;
		apcData[index].FireCount = 0;

		if (!CreateTimerQueueTimer(&hTimers[index], hTimerQueue, (WAITORTIMERCALLBACK) TimerRoutine,
				&apcData[index], apcData[index].DueTime, apcData[index].Period, 0))
		{
			printf("CreateTimerQueueTimer failed (%d)\n", (int) GetLastError());
			return -1;
		}
	}

	if (WaitForSingleObject(g_Event, INFINITE) != WAIT_OBJECT_0)
	{
		printf("WaitForSingleObject failed (%d)\n", (int) GetLastError());
		return -1;
	}

	for (index = 0; index < TIMER_COUNT; index++)
	{
		if (!DeleteTimerQueueTimer(hTimerQueue, hTimers[index], NULL))
		{
			printf("DeleteTimerQueueTimer failed (%d)\n", (int) GetLastError());
			return -1;
		}
	}
	
	if (!DeleteTimerQueue(hTimerQueue))
	{
		printf("DeleteTimerQueue failed (%d)\n", (int) GetLastError());
		return -1;
	}

	CloseHandle(g_Event);

	return 0;
}
예제 #2
0
void DisposeHttpListener(PHTTP_LISTENER listener)
{	
	ULONG state = InterlockedCompareExchange(&listener->State, 
											HTTP_LISTENER_STATE_DISPOSING, 
											HTTP_LISTENER_STATE_STARTED);
	if(state = HTTP_LISTENER_STATE_STOPPED)
	{
		return;
	}

	// Thread responsible for disposing the listener.
	if(state = HTTP_LISTENER_STATE_STARTED)
	{		
		if(listener && listener->hRequestQueue)
		{
			for(int i=1; i<=listener->urlsCount; i++)
			{
				HttpRemoveUrlFromUrlGroup(
					  listener->UrlGroupId,     // Req Queue
					  listener->urls[i],        // Fully qualified URL
					  NULL);
			}

			//Close the request queue.
			CloseHandle(listener->hRequestQueue);
		}

		// 
		// Call HttpTerminate.
		//
		HttpTerminate(HTTP_INITIALIZE_SERVER, NULL);
		return;
	} 
	else if (state == HTTP_LISTENER_STATE_DISPOSING)
	{
		// Only one thread can dispose the listener	
		if(InterlockedCompareExchange(&listener->State, 
									HTTP_LISTENER_STATE_STOPPED, 
									HTTP_LISTENER_STATE_DISPOSING) == HTTP_LISTENER_STATE_DISPOSING)
		{		
			//
			// Cleanup threadpool 
			//
			HttpListenerCleanupThreadPool(listener);		
		
			//Delete timers and release the IOContexts
			DeleteTimerQueueTimer(listener->TimerQueue, listener->FlushTimer,NULL);
			DeleteTimerQueue(listener->TimerQueue);
			HttpListenerFlushLookasideThreadProc(listener,NULL);

			// Free the listener
			FREE_MEM(listener);
			printf("Http listener terminated...\n");
		}
	}
}
예제 #3
0
파일: Ipapp.cpp 프로젝트: bluesummer/demo
/*
 ÏìÓ¦°ü´¦Àíº¯Êý£¬½«ÏìÓ¦ÄÚÈÝÖ±½ÓÉÏËÍ ÔÚµ÷ÓÃÍê³Éºó»ØÊÕSOCKET
 Èë²Î: thisÖ¸Õë
 ·µ»ØÖµ ³É¹¦ VOS_OK  ʧ°Ü VOS_ERROR
 */
 UINT32 IpappDispatchResponse(PKT_HEAD_S* pThis)
 {
  //Èë²Î¼ì²é
   CHECK_PARAM(pThis);
   
   UINT32 uiRet = VOS_OK;
   map<UINT32, IPAPP_LOCAL_BUF_S>::iterator iter = g_PktMap.find(pThis->uiPktID);
   
  if ( iter != g_PktMap.end())// -->TEST_CODE;
  {
    //ÏÈÍ£Ö¹¶¨Ê±Æ÷
    DeleteTimerQueueTimer(iter->second.hTimerQueue, iter->second.hNewTimer, NULL);
    DeleteTimerQueue(iter->second.hTimerQueue);
    
    if(iter->second.callback_pfn != NULL)
    {
      pfn pfnKey = iter->second.callback_pfn;
      IPAPP_RESPONSE_PACKET_S* pPkt = (IPAPP_RESPONSE_PACKET_S* )(pThis + 1);
      
      /*
       if(FUNCTION_NOT_FOUND == pPkt->uiErrCode) //·þÎñÆ÷¶ËδÕÒµ½º¯Êý
       {
       no_function();
       return VOS_OK;
       }
       */
       
       size_t szPktLength = sizeof(IPAPP_RESPONSE_PACKET_S) + pPkt->stRetArgs.szLen;
       if(pPkt->stRetArgs.szLen != 0)
       {
        pPkt->stRetArgs.Buf = (char *)pPkt + sizeof(IPAPP_RESPONSE_PACKET_S);
      }
      else
      {
        pPkt->stRetArgs.Buf = NULL;
      }
      
      //µ÷ÓöÔÓ¦»Øµ÷º¯Êý
      //uiRet = UPLOADMSG(pMsg);
      CHAR *pArgList = (char *)pPkt->stRetArgs.Buf;
      pfnKey(pPkt->uiErrCode, pArgList, pPkt->stRetArgs.szLen, pPkt->context, (HANDLE)pThis->uiPktID);
    }
    
    IpappClearMap(pThis->uiPktID);
    
    //µ÷ÓÃÍê³É »ØÊÕÌ×½Ó×Ö
    if(SockCloseSocket((SOCKET)pThis->uiPktID))
    {
      printf("RESTORE SOCKET ERROR\n");
    }
    //printf("SOCKET IS ALREADY CLOSED\n");
    
  }
  
  return VOS_OK;
}
예제 #4
0
	CStressManager::~CStressManager()
	{
		m_mapCases.clear();

		if(m_hTimerQueue)
		{
			DeleteTimerQueue(m_hTimerQueue);
			m_hTimerQueue = NULL;
		}
		
		ASockIOFini();
		A_MUTEX_DESTROY(&m_mtxLocker);
	}
예제 #5
0
void ArtWindow::OnDestroy()
{
	delete renderer;
	//KillTimer(TIMER_REPAINT);

	if (RepaintTimer)
		DeleteTimerQueueTimer(TimerQueue, RepaintTimer, INVALID_HANDLE_VALUE);
	if (TimerQueue)
		DeleteTimerQueue(TimerQueue);

	// Does this do anything?
	RepaintTimer = NULL;
	TimerQueue = NULL;
}
예제 #6
0
LRESULT ArtWindow::OnCreate(LPCREATESTRUCT)
{
	RECT rc;
	GetClientRect(&rc);
	renderer = new RendererGL(GetDC(), rc);

	//KillTimer(TIMER_REPAINT);
	//SetTimer(TIMER_REPAINT, 15);

	if (RepaintTimer)
		DeleteTimerQueueTimer(TimerQueue, RepaintTimer, INVALID_HANDLE_VALUE);
	if (TimerQueue)
		DeleteTimerQueue(TimerQueue);

	TimerQueue = CreateTimerQueue();
	CreateTimerQueueTimer(&RepaintTimer, TimerQueue, (WAITORTIMERCALLBACK)TimerCallback, this, 10, 15, WT_EXECUTEDEFAULT);

	return 0;
}
예제 #7
0
NeoTimer::~NeoTimer()
{
#ifdef WIN32
    if (!DeleteTimerQueue(m_hTimerQueue))
        printf("DeleteTimerQueue failed (%d)\n", GetLastError());
#else
    if (m_myEpoll)
    {
    	delete(m_myEpoll);
    	m_myEpoll = NULL;
    }

    map<string, int>::iterator iter;
	for(iter=m_hTimers.begin();iter!=m_hTimers.end();++iter)
	{
		if(iter->second!=0)
			close(iter->second);
	}
#endif
    if(!m_hTimers.empty())
    {
        m_hTimers.clear();
    }
}