![]() |
RegisterTimeout() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| Public Function |
Declared in: SocketThreadManager.h |
DeclarationCSocketThreadManager::TimerID RegisterTimeout( int iMS, LPTimeoutProc pProc, LPVOID pData, BOOL bClearTimeout=FALSE, HWND hHandle=NULL, TimerID* pTimer=NULL);
DescriptionRegister a timeout iMS - Timeout interval pProc - Proc to run pData - Data to give the proc bClearTimeout - Autodelete the timeout
Function Body
TimerID aTimerID;
aTimerID.iIndex=0;
try
{
//Do we have a timer ?
if (pTimer)
memset(pTimer,0,sizeof(TimerID));
int iIndex;
//Create the data structure (to save time on the CS)
TimeoutData aData;
aData.pTimeoutProc=pProc;
aData.pData=pData;
aData.bClearTimeout=bClearTimeout;
aData.pTimer=pTimer;
//Enter the CS
CCriticalAutoRelease aRelease(m_pCSection);
//Do we have a handle
if (hHandle)
{
//Get it
iIndex=GetIndexByHWND(hHandle);
//Do we have it
if (!iIndex)
{
//Report it
ReportError("RegisterTimeout","Failed to find handle!");
//Exit
return aTimerID;
}
else
--iIndex;
}
else
{
//Get the handler
iIndex=GetMostAvailableThread();
//Check it's legal
if (!iIndex)
{
//Report the error
ReportError("RegisterTimeout","Failed to find thread!");
//Quit
return aTimerID;
}
//Reset the index
--iIndex;
}
//Our timer ID
unsigned int iTimerID;
iTimerID=0;
//Timer counter
static int sTimerCounter=1000000;
//Get the timerID
int iSetTimerID;
iSetTimerID=sTimerCounter++;
//Lock the thread data
CCriticalAutoRelease aRelease2(m_pThreadData[iIndex].pCSection);
//Increase the timeout count
++m_pThreadData[iIndex].iTimeoutCount;
//Register the data
m_pThreadData[iIndex].pMap.insert(TOMap::value_type(iSetTimerID,aData));
//Exit the CS
aRelease2.Exit();
aRelease.Exit();
//Register the timeout
iTimerID=SetTimer(m_pThreadData[iIndex].hWindowHandle,
iSetTimerID,
iMS,
NULL);
//Check we have the timer
if (!iTimerID)
{
{
//Remove it
//Lock the thread data
CCriticalAutoRelease aRelease2(m_pThreadData[iIndex].pCSection);
//Increase the timeout count
--m_pThreadData[iIndex].iTimeoutCount;
//Register the data
m_pThreadData[iIndex].pMap.erase(iSetTimerID);
}
//Write the error
ReportError("RegisterTimeout","Failed to create the timer!");
//Quit
return aTimerID;
}
//Create the data
aTimerID.iTimerID=iSetTimerID;
aTimerID.iIndex=iIndex+1;
aTimerID.iMS=iMS;
//Do we have a timer ?
if (pTimer)
memcpy(pTimer,&aTimerID,sizeof(aTimerID));
//Done
return aTimerID;
}
ERROR_HANDLER_RETURN("RegisterTimeout",aTimerID)
See Also
This web site was generated
using Surveyor V4.50.811.1. Click
here
for more information. |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |