Class CSocketThreadManager::
SocketThread()
Base ClassesData ItemsConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: ReSetTimeoutNext page: SpawnThreads    Show member index
Private Function Declared in:
SocketThreadManager.h

'Declaration' icon -- Shortcut to top of page. Declaration

static DWORD SocketThread(
    LPVOID lpParameter);

'Description' icon -- Shortcut to top of page. Description

Our thread function

'Function Body' icon -- Shortcut to top of page. Function Body

try
{
    //Get the address of our data
    ThreadData* pData;
    pData=(ThreadData*)lpParameter;

    //Initialize the random seed
    srand(GetTickCount()+(unsigned long)pData->pEvent+(unsigned long)pData->hWindowHandle);

    //Create the window
    pData->hWindowHandle=CreateWindowEx(0,
                                        pData->sClassName.c_str(),
                                        SOCKET_WINDOW_NAME,
                                        WS_OVERLAPPED,
                                        0,
                                        0,
                                        0,
                                        0,
                                        0,
                                        NULL,
                                        pData->hInstance,
                                        NULL);

    //Alert we are done
    pData->pEvent->Set();

    //Check we have this window
    if (pData->hWindowHandle)
    {
        //Run a message map
        MSG msg;

        while (GetMessage(&msg,NULL,0,0))
        {
            //Translate and dispatch
            TranslateMessage(&msg);

            //Check if it's a timer
            if (msg.message==WM_TIMER)
            {
                //Lock the CS
                CCriticalAutoRelease aRelease(pData->pCSection);

                //Check is it our timer
                TOMap::iterator aTheIterator;
                aTheIterator=pData->pMap.find(msg.wParam);

                //Check if we have it
                if (aTheIterator!=pData->pMap.end())
                {
                    //Found it
                    TimeoutData aData;
                    aData=aTheIterator->second;

                    //Do we need to delete it
                    if (aData.bClearTimeout)
                    {
                        //Delete it
                        KillTimer(pData->hWindowHandle,msg.wParam);

                        //Do we have the data to reset ?
                        if (aData.pTimer)
                            memset(aData.pTimer,0,sizeof(TimerID));

                        //Erase the timer
                        pData->pMap.erase(aTheIterator);

                        //Decrease the count
                        --pData->iTimeoutCount;
                    }

                    //Exit the CS
                    aRelease.Exit();

                    //Protect it
                    try
                    {
                        //Dispatch the data
                        (*(aData.pTimeoutProc))(aData.pData);
                    }
                    ERROR_HANDLER_STATIC(CSocketThreadManager_Class,"SocketThread - Proc")
                }
                else
                {
                    //Release the data
                    aRelease.Exit();

                    //Dispatch the message
                    DispatchMessage(&msg);
                }
            }
            else
                //Regular message
                DispatchMessage(&msg);
        }
    }
    else
        //Report the error
        ReportStaticError(CSocketThreadManager_Class,"SocketThread","Failed to create window!");

    //Set we are OK
    pData->pEvent->Set();

    //Exit
    return FALSE;
}
ERROR_HANDLER_STATIC_RETURN(CSocketThreadManager_Class,"SocketThread",TRUE)

'See Also' icon -- Shortcut to top of page. See Also

Class Overview Class Overview  |  Public base class CErrorHandler  |  Hierarchy Chart Hierarchy Chart


Get Surveyor!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.