Retail products


Traffic interception SDK

Control every TCP/IP network connection

  • Route connections via proxy
  • Redirect connections and modify the data
  • Block connections and applications
SSL interception SDK

View SSL in plaintext and modify it

  • View the SSL stream decrypted in plaintext
  • Redirect SSL connection and modify decrypted data
  • Browser shows "SSL lock" without warnings

Documentation


CSocketThreadManagerImp Class Reference

#include <SocketThreadManagerImp.h>

Inheritance diagram for CSocketThreadManagerImp:
Collaboration diagram for CSocketThreadManagerImp:

List of all members.


Classes

struct  _ExtensionData

Public Types

typedef TimeoutProc LPTimeoutProc
typedef struct
CSocketThreadManager::_TimerID 
TimerID
typedef void(* TimeoutProc )(LPVOID pParam)

Public Member Functions

HWND GetWindowHandle (CAsyncSocket *pSocket)
void RemoveSocket (CAsyncSocket *pSocket)
BOOL Initialize (unsigned long ulThreadCount)
 CSocketThreadManagerImp (HINSTANCE hInstance)
virtual ~CSocketThreadManagerImp ()
BOOL IsInitialized () const
unsigned long GetNumberOfThreads () const
const std::string & GetClassName () const
BOOL ReSetTimeout (const TimerID &rTimerID)
BOOL RemoveTimeout (TimerID &aTimerID, BOOL bInvokeDeleteProc=FALSE)
TimerID RegisterTimeout (int iMS, LPTimeoutProc pProc, LPVOID pData, BOOL bClearTimeout=FALSE, HWND hHandle=NULL, TimerID *pTimer=NULL, LPTimeoutProc pDeleteProc=NULL)
void DecreaseSocketCount (HWND hWindowHandle, BOOL bFreeze=FALSE)
void DecreaseTimeoutCount (HWND hWindowHandle, BOOL bFreeze=FALSE)
HWND GetWindowHandle (BOOL bTimeout=FALSE)
const CGenericThreadGetThreadByHWND (HWND hWindowHandle) const
BOOL Initialize (unsigned long ulThreadCount, LPCSTR lpClassName)
BOOL Uninitialize ()
void SetLocalLog (CErrorLog *pLog)
void WriteError (const std::string &rClass, const std::string &rMethod, const std::string &rError) const
void WriteMessage (const std::string &rClass, const std::string &rMethod, const std::string &rMessage) const

Static Public Member Functions

static std::string GetCurrentDateTime ()
static std::string ErrorCodeToString (DWORD dwErrorCode)
static void RegisterError (DWORD dwErrorCode, const std::string &rDescription)
static void SetLog (CErrorLog *pLog)
static void WriteStaticError (const std::string &rClass, const std::string &rMethod, const std::string &rError)
static std::string FormatData (const std::string &rClass, const std::string &rMethod, const std::string &rMsgOrError, bool bError=true)

Protected Types

typedef struct
CSocketThreadManager::_ThreadDataExtend 
ThreadDataExtend
typedef struct
CSocketThreadManager::_TimeoutData 
TimeoutData
typedef std::map< unsigned int,
TimeoutData
TOMap
typedef struct
CSocketThreadManager::_ThreadData 
ThreadData

Protected Member Functions

virtual void ParseDispatchMessage (const MSG &rMsg, ThreadData *pData)
virtual void CreateExtendedData (ThreadDataExtend &rData)
virtual void DeleteExtendedData (ThreadDataExtend &rData)
ThreadDataGetDataByHWND (HWND hHandle) const
virtual void ReportError (const std::string &rMethod) const
virtual void ReportError (const std::string &rMethod, const std::string &rMessage) const
virtual void ReportError (const std::string &rMethod, const std::string &rMessage, DWORD dwAdditionalData) const
virtual void ReportError (const std::string &rMethod, const std::string &rMessage, const std::string &rAdditionalData) const
virtual void ReportError (const std::string &rMethod, int iErrorCode) const
virtual void ReportError (const std::string &rMethod, const std::string &rMessage, int iErrorCode) const
virtual void ReportErrorOS (const std::string &rMethod, const std::string &rMessage) const
void SetName (const std::string &rName) const

Static Protected Member Functions

static void ReportStaticError (const std::string &rClass, const std::string &rMethod)
static void ReportStaticError (const std::string &rClass, const std::string &rMethod, const std::string &rMessage)
static void ReportStaticError (const std::string &rClass, const std::string &rMethod, const std::string &rMessage, DWORD dwAdditionalData)
static void ReportStaticErrorOS (const std::string &rClass, const std::string &rMethod, const std::string &rMessage)

Detailed Description

Definition at line 51 of file SocketThreadManagerImp.h.


Member Typedef Documentation

Definition at line 66 of file SocketThreadManager.h.

typedef void(* CSocketThreadManager::TimeoutProc)(LPVOID pParam) [inherited]

typedef std::map<unsigned int,TimeoutData> CSocketThreadManager::TOMap [protected, inherited]

Definition at line 165 of file SocketThreadManager.h.


Constructor & Destructor Documentation

CSocketThreadManagerImp::CSocketThreadManagerImp ( HINSTANCE  hInstance  ) 

Definition at line 78 of file SocketThreadManagerImp.cpp.

00078                                                                     : CSocketThreadManager(hInstance),
00079                                                                         m_hLocalInstance(hInstance),
00080                                                                         m_bStatic(FALSE)
00081 {
00082     try
00083     {
00084         //Set our name
00085         SetName(CSocketThreadManagerImp_Class);
00086     }
00087     ERROR_HANDLER("CSocketThreadManagerImp")
00088 }

CSocketThreadManagerImp::~CSocketThreadManagerImp (  )  [virtual]

Definition at line 90 of file SocketThreadManagerImp.cpp.

00091 {
00092     try
00093     {
00094         //Are we static version?
00095         if (m_bStatic)
00096             //Remove the window
00097             if (m_bWindow)
00098             {
00099                 //Unregister it
00100                 ::UnregisterClass(CSocketThreadManagerImp_Class,
00101                                   m_hInstance);
00102 
00103                 //No window
00104                 m_bWindow=FALSE;
00105             }
00106             else
00107                 ;
00108         else
00109             //Uninitialize 
00110             Uninitialize();
00111     }
00112     ERROR_HANDLER("~CSocketThreadManagerImp")
00113 }


Member Function Documentation

void CSocketThreadManagerImp::CreateExtendedData ( ThreadDataExtend rData  )  [protected, virtual]

Reimplemented from CSocketThreadManager.

Definition at line 149 of file SocketThreadManagerImp.cpp.

00150 {
00151     try
00152     {
00153         //Create the struct
00154         ExtensionData* pData;
00155         pData=new ExtensionData;
00156 
00157         //Populate it
00158         pData->pCSection=COSManager::CreateCriticalSection();
00159         
00160         //Put it in the data
00161         rData.lpData=(LPVOID)pData;
00162     }
00163     ERROR_HANDLER("CreateExtendedData")
00164 }

void CSocketThreadManager::DecreaseSocketCount ( HWND  hWindowHandle,
BOOL  bFreeze = FALSE 
) [inherited]

Definition at line 549 of file SocketThreadManager.cpp.

00551 {
00552     try
00553     {
00554         //First find the window handle
00555         int iIndex;
00556         iIndex=GetIndexByHWND(hWindowHandle);
00557 
00558         //Check it's valid
00559         if (!iIndex)
00560             return;
00561 
00562         //Enter the critical section
00563         CCriticalAutoRelease aRelease(m_pCSection);
00564 
00565         //Decrement the socket count
00566         if (m_pThreadData[iIndex-1].iSocketCount>0)
00567         {
00568             --m_pThreadData[iIndex-1].iSocketCount;
00569             m_pThreadData[iIndex-1].bFreeze=bFreeze;
00570         }
00571     }
00572     ERROR_HANDLER("DecreaseSocketCount")
00573 }

void CSocketThreadManager::DecreaseTimeoutCount ( HWND  hWindowHandle,
BOOL  bFreeze = FALSE 
) [inherited]

Definition at line 575 of file SocketThreadManager.cpp.

00577 {
00578     try
00579     {
00580         //First find the window handle
00581         int iIndex;
00582         iIndex=GetIndexByHWND(hWindowHandle);
00583 
00584         //Check it's valid
00585         if (!iIndex)
00586             return;
00587 
00588         //Enter the critical section
00589         CCriticalAutoRelease aRelease(m_pCSection);
00590 
00591         //Decrement the socket count
00592         if (m_pThreadData[iIndex-1].iTimeoutCount>0)
00593         {
00594             --m_pThreadData[iIndex-1].iTimeoutCount;
00595             m_pThreadData[iIndex-1].bFreeze=bFreeze;
00596         }
00597     }
00598     ERROR_HANDLER("DecreaseTimeoutCount")
00599 }

void CSocketThreadManagerImp::DeleteExtendedData ( ThreadDataExtend rData  )  [protected, virtual]

Reimplemented from CSocketThreadManager.

Definition at line 166 of file SocketThreadManagerImp.cpp.

00167 {
00168     try
00169     {
00170         //Take the data
00171         ExtensionData* pData;
00172         pData=(ExtensionData*)rData.lpData;
00173 
00174         //Is it legal?
00175         if (pData)
00176         {
00177             //Our delete vector
00178             typedef std::vector<CAsyncSocket*> DeleteVector;
00179 
00180             //Our vector
00181             DeleteVector aDeleteVector;
00182 
00183             {
00184                 //Lock the CS
00185                 CCriticalAutoRelease aRelease(pData->pCSection);
00186 
00187                 //Iterate to delete all the data
00188                 SocketMap::iterator aIterator;
00189                 aIterator=pData->aSocketsMap.begin();
00190                 while (aIterator!=pData->aSocketsMap.end())
00191                 {
00192                     //Add the socket
00193                     aDeleteVector.push_back(aIterator->second);
00194 
00195                     //Delete it
00196                     aIterator=pData->aSocketsMap.erase(aIterator);
00197                 }
00198             }
00199 
00200             //Delete the sockets
00201             for (int iCount=0;
00202                  iCount<aDeleteVector.size();
00203                  ++iCount)
00204                 try
00205                 {
00206                     //Set to delete
00207                     aDeleteVector[iCount]->SetDeleting();
00208 
00209                     //Delete the socket
00210                     delete aDeleteVector[iCount];
00211                 }
00212                 ERROR_HANDLER("DeleteExtendedData - Socket delete")
00213 
00214             //Delete the CS
00215             delete pData->pCSection;
00216 
00217             //Delete it
00218             delete pData;
00219 
00220             //Remove from data
00221             rData.lpData=NULL;
00222         }
00223     }
00224     ERROR_HANDLER("DeleteExtendedData")
00225 }

std::string CErrorHandler::ErrorCodeToString ( DWORD  dwErrorCode  )  [static, inherited]

Definition at line 218 of file ErrorHandler.cpp.

00219 {
00220     try
00221     {
00222         //Try to look it in the errors
00223         if (!CErrorsRepository::GetInstance().GetErrorsMap().empty())
00224         {
00225             //Search
00226             CErrorsRepository::ErrorMap::const_iterator aIterator;
00227             aIterator=CErrorsRepository::GetInstance().GetErrorsMap().find(dwErrorCode);
00228 
00229             //Do we have it
00230             if (aIterator!=CErrorsRepository::GetInstance().GetErrorsMap().end())
00231                 return aIterator->second;
00232         }
00233 
00234         //Get the error string
00235         LPVOID lpMsgBuf;
00236         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
00237                       FORMAT_MESSAGE_FROM_SYSTEM | 
00238                       FORMAT_MESSAGE_IGNORE_INSERTS,
00239                       NULL,
00240                       dwErrorCode,
00241                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
00242                       (LPTSTR) &lpMsgBuf,
00243                       0,
00244                       NULL);
00245 
00246         //Save it
00247         std::string sMessage;
00248 
00249         //Do we have the message?
00250         if (lpMsgBuf)
00251         {
00252             //Save it
00253             sMessage=(char*)lpMsgBuf;
00254             
00255             //Release the buffer
00256             LocalFree(lpMsgBuf);
00257         }
00258         else
00259             //Failed to find
00260             sMessage="No error description found!";
00261 
00262         //Done
00263         return sMessage;
00264     }
00265     catch (...)
00266     {
00267         return "Unknown";
00268     }
00269 }

std::string CErrorHandler::FormatData ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMsgOrError,
bool  bError = true 
) [static, inherited]

Definition at line 140 of file ErrorHandler.cpp.

00144 {
00145     //Our message
00146     std::string sMsg;
00147 
00148     //Is it an error?
00149     if (bError)
00150         sMsg="*** Error *** ";
00151     else
00152         sMsg="###  Msg  ### ";
00153 
00154     //Add the data now
00155     sMsg+="in "+rClass;
00156     sMsg+=":"+rMethod;
00157     sMsg+=" - " + rMsgOrError;
00158 
00159     //Done
00160     return sMsg;
00161 }

const std::string & CSocketThreadManager::GetClassName (  )  const [inherited]

Reimplemented from CErrorHandler.

Definition at line 995 of file SocketThreadManager.cpp.

00996 {
00997     return m_sClassName;
00998 }

std::string CErrorHandler::GetCurrentDateTime (  )  [static, inherited]

Definition at line 572 of file ErrorHandler.cpp.

00573 {
00574     try
00575     {
00576         //Our string
00577         std::string sDate;
00578 
00579         //Our tmp buf
00580         char cTmp[128];
00581 
00582         //Get date
00583         _strdate(cTmp);
00584         sDate=cTmp;
00585         sDate+=' ';
00586 
00587         //Get time
00588         _strtime(cTmp);
00589         sDate+=cTmp;
00590 
00591         //Done
00592         return sDate;
00593     }
00594     ERROR_HANDLER_STATIC_RETURN(CErrorHandler_Class,"GetCurrentDateTime","")
00595 }

CSocketThreadManager::ThreadData * CSocketThreadManager::GetDataByHWND ( HWND  hHandle  )  const [protected, inherited]

Definition at line 601 of file SocketThreadManager.cpp.

00602 {
00603     try
00604     {
00605         //Get the index
00606         int iIndex;
00607         iIndex=GetIndexByHWND(hHandle);
00608 
00609         //Do we have it?
00610         if (iIndex)
00611             return &m_pThreadData[iIndex-1];
00612         else
00613             return NULL;
00614     }
00615     ERROR_HANDLER_RETURN("GetDataByHWND",NULL)
00616 }

unsigned long CSocketThreadManager::GetNumberOfThreads (  )  const [inherited]

Definition at line 1005 of file SocketThreadManager.cpp.

01006 {
01007     return m_ulThreadCount;
01008 }

const CGenericThread * CSocketThreadManager::GetThreadByHWND ( HWND  hWindowHandle  )  const [inherited]

Definition at line 528 of file SocketThreadManager.cpp.

00529 {
00530     try
00531     {
00532         //First find the window handle
00533         int iIndex;
00534         iIndex=GetIndexByHWND(hWindowHandle);
00535 
00536         //Check it's valid
00537         if (!iIndex)
00538             return NULL;
00539 
00540         //Enter the critical section
00541         CCriticalAutoRelease aRelease(m_pCSection);
00542 
00543         //Return the thread
00544         return m_pThreadData[iIndex-1].pThread;
00545     }
00546     ERROR_HANDLER_RETURN("GetThreadByHWND",NULL)
00547 }

HWND CSocketThreadManager::GetWindowHandle ( BOOL  bTimeout = FALSE  )  [inherited]

Definition at line 499 of file SocketThreadManager.cpp.

00500 {   
00501     try
00502     {
00503         //Shared resource
00504         CCriticalAutoRelease aRelease(m_pCSection);
00505     
00506         //Get the freeiest index
00507         int iIndex;
00508         iIndex=GetMostAvailableThread();
00509 
00510         //Check it's valid
00511         if (!iIndex)
00512             //Quit
00513             return 0;
00514     
00515         //Check what to increase
00516         if (bTimeout)
00517             ++m_pThreadData[iIndex-1].iTimeoutCount;
00518         else
00519             //Increase the socket count
00520             ++m_pThreadData[iIndex-1].iSocketCount;
00521 
00522         //Done
00523         return m_pThreadData[iIndex-1].hWindowHandle;
00524     }
00525     ERROR_HANDLER_RETURN("GetWindowHandle",0)
00526 }

HWND CSocketThreadManagerImp::GetWindowHandle ( CAsyncSocket pSocket  ) 

Definition at line 280 of file SocketThreadManagerImp.cpp.

00281 {
00282     try
00283     {
00284         //Allocate a handle
00285         HWND hHandle;
00286         hHandle=CSocketThreadManager::GetWindowHandle();
00287 
00288         //Do we have it?
00289         if (hHandle)
00290             //Add the socket
00291             AddSocketToList(pSocket,
00292                             hHandle);
00293 
00294         //Done
00295         return hHandle;
00296     }
00297     ERROR_HANDLER_RETURN("GetWindowHandle",NULL)
00298 }

BOOL CSocketThreadManager::Initialize ( unsigned long  ulThreadCount,
LPCSTR  lpClassName 
) [inherited]

Definition at line 112 of file SocketThreadManager.cpp.

00114 {
00115     try
00116     {
00117         //Are we initialized?
00118         if (m_bInitialized)
00119         {
00120             //Report it
00121             ReportError("Initialize","Already initialized!");
00122 
00123             //Exit
00124             return FALSE;
00125         }
00126 
00127         //Check the number of threads
00128         if (ulThreadCount>MAX_THREADS)
00129         {
00130             //Report it
00131             ReportError("Initialize","Too many threads to spawn!");
00132 
00133             //Exit
00134             return FALSE;
00135         }
00136 
00137         //Check the number of threads
00138         if (!ulThreadCount)
00139         {
00140             //Report it
00141             ReportError("Initialize","Can't have zero threads!");
00142 
00143             //Exit
00144             return FALSE;
00145         }
00146 
00147         //Save the count
00148         m_ulThreadCount=ulThreadCount;
00149 
00150         //Try to spawn the threads
00151         return SpawnThreads(lpClassName);
00152     }
00153     ERROR_HANDLER_RETURN("Initialize",FALSE)
00154 }

BOOL CSocketThreadManagerImp::Initialize ( unsigned long  ulThreadCount  ) 

Definition at line 227 of file SocketThreadManagerImp.cpp.

00228 {
00229     try
00230     {
00231         //First create the window class
00232         if (!m_bWindow)
00233         {
00234             //Save the instance
00235             m_hInstance=m_hLocalInstance;
00236 
00237             if (!RegisterWindow(m_hInstance))
00238             {
00239                 //Report it
00240                 ReportErrorOS("SetHandlers","Error registering the window, please check API error!");
00241 
00242                 //Exit
00243                 return FALSE;
00244             }
00245             else
00246                 //Window is OK
00247                 m_bWindow=TRUE;
00248         }
00249 
00250         //Initialize our father
00251         return CSocketThreadManager::Initialize(ulThreadCount,
00252                                                 CSocketThreadManagerImp_Class);
00253     }
00254     ERROR_HANDLER_RETURN("Initialize",FALSE)
00255 }

BOOL CSocketThreadManager::IsInitialized (  )  const [inherited]

Definition at line 1000 of file SocketThreadManager.cpp.

01001 {
01002     return m_bInitialized;
01003 }

void CSocketThreadManagerImp::ParseDispatchMessage ( const MSG &  rMsg,
ThreadData pData 
) [protected, virtual]

Reimplemented from CSocketThreadManager.

Definition at line 115 of file SocketThreadManagerImp.cpp.

00117 {
00118     //Get the extension data
00119     ExtensionData* pExtension;
00120     pExtension=(ExtensionData*)pData->aExtension.lpData;
00121 
00122     //Our new msg
00123     MSG aNewMsg(rMsg);
00124 
00125     //Do we have param?
00126     if (rMsg.wParam &&
00127         IsSocketMessage(aNewMsg.message))
00128     {
00129         //Lock the CS
00130         CCriticalAutoRelease aRelease(pExtension->pCSection);
00131 
00132         //Try to get the socket
00133         SocketMap::iterator aIterator;
00134         aIterator=pExtension->aSocketsMap.find((int)rMsg.wParam);
00135 
00136         //Do we have it?
00137         if (aIterator!=pExtension->aSocketsMap.end())
00138             //Modify the message
00139             aNewMsg.wParam=(WPARAM)aIterator->second;
00140         else
00141             aNewMsg.wParam=0;
00142     }
00143 
00144     //Dispatch it
00145     CSocketThreadManager::ParseDispatchMessage(aNewMsg,
00146                                                pData);
00147 }

void CErrorHandler::RegisterError ( DWORD  dwErrorCode,
const std::string &  rDescription 
) [static, inherited]

Definition at line 597 of file ErrorHandler.cpp.

00599 {
00600     try
00601     {
00602         //Add the error
00603         CErrorsRepository::GetInstance().GetErrorsMap().insert(CErrorsRepository::ErrorMap::value_type(dwErrorCode,rDescription));
00604     }
00605     ERROR_HANDLER_STATIC(CErrorHandler_Class,"RegisterError")
00606 }

CSocketThreadManager::TimerID CSocketThreadManager::RegisterTimeout ( int  iMS,
LPTimeoutProc  pProc,
LPVOID  pData,
BOOL  bClearTimeout = FALSE,
HWND  hHandle = NULL,
TimerID pTimer = NULL,
LPTimeoutProc  pDeleteProc = NULL 
) [inherited]

Definition at line 713 of file SocketThreadManager.cpp.

00720 {
00721     TimerID aTimerID;
00722     aTimerID.iIndex=0;
00723 
00724     try
00725     {
00726         //Do we have a timer ?
00727         if (pTimer)
00728             memset(pTimer,0,sizeof(TimerID));
00729 
00730         int iIndex;
00731 
00732         //Create the data structure (to save time on the CS)
00733         TimeoutData aData;
00734         aData.pTimeoutProc=pProc;
00735         aData.pData=pData;
00736         aData.bClearTimeout=bClearTimeout;
00737         aData.pTimer=pTimer;
00738         aData.pDeleteProc=pDeleteProc;
00739 
00740         //Enter the CS
00741         CCriticalAutoRelease aRelease(m_pCSection);
00742 
00743         //Do we have a handle
00744         if (hHandle)
00745         {
00746             //Get it
00747             iIndex=GetIndexByHWND(hHandle);
00748 
00749             //Do we have it
00750             if (!iIndex)
00751             {
00752                 //Report it
00753                 ReportError("RegisterTimeout","Failed to find handle!");
00754 
00755                 //Exit
00756                 return aTimerID;
00757             }
00758             else
00759                 --iIndex;           
00760         }
00761         else
00762         {
00763             //Get the handler
00764             iIndex=GetMostAvailableThread();
00765 
00766             //Check it's legal
00767             if (!iIndex)
00768             {
00769                 //Report the error
00770                 ReportError("RegisterTimeout","Failed to find thread!");
00771 
00772                 //Quit
00773                 return aTimerID;
00774             }
00775 
00776             //Reset the index
00777             --iIndex;
00778         }
00779 
00780         //Our timer ID
00781         unsigned int iTimerID;
00782         iTimerID=0;
00783 
00784         //Timer counter
00785         static int sTimerCounter=1000000;
00786 
00787         //Get the timerID
00788         int iSetTimerID;
00789         iSetTimerID=sTimerCounter++;
00790 
00791         //Lock the thread data
00792         CCriticalAutoRelease aRelease2(m_pThreadData[iIndex].pCSection);
00793 
00794         //Increase the timeout count
00795         ++m_pThreadData[iIndex].iTimeoutCount;
00796 
00797         //Register the data
00798         m_pThreadData[iIndex].pMap.insert(TOMap::value_type(iSetTimerID,aData));
00799 
00800         //Exit the CS
00801         aRelease2.Exit();
00802         aRelease.Exit();
00803 
00804         //Register the timeout
00805         iTimerID=SetTimer(m_pThreadData[iIndex].hWindowHandle,
00806                           iSetTimerID,
00807                           iMS,
00808                           NULL);
00809 
00810         //Check we have the timer
00811         if (!iTimerID)
00812         {
00813             {
00814                 //Remove it
00815                 //Lock the thread data
00816                 CCriticalAutoRelease aRelease2(m_pThreadData[iIndex].pCSection);
00817 
00818                 //Increase the timeout count
00819                 --m_pThreadData[iIndex].iTimeoutCount;
00820 
00821                 //Register the data
00822                 m_pThreadData[iIndex].pMap.erase(iSetTimerID);
00823             }
00824 
00825             //Write the error
00826             ReportError("RegisterTimeout","Failed to create the timer!");
00827 
00828             //Quit
00829             return aTimerID;
00830         }
00831 
00832         //Create the data
00833         aTimerID.iTimerID=iSetTimerID;
00834         aTimerID.iIndex=iIndex+1;
00835         aTimerID.iMS=iMS;
00836 
00837         //Do we have a timer ?
00838         if (pTimer)
00839             memcpy(pTimer,&aTimerID,sizeof(aTimerID));
00840 
00841         //Done
00842         return aTimerID;
00843     }
00844     ERROR_HANDLER_RETURN("RegisterTimeout",aTimerID)
00845 }

void CSocketThreadManagerImp::RemoveSocket ( CAsyncSocket pSocket  ) 

Definition at line 330 of file SocketThreadManagerImp.cpp.

00331 {
00332     try
00333     {
00334         //Get the handle
00335         HWND hHandle;
00336         hHandle=pSocket->GetWindowHandle();
00337 
00338         //Do we have it
00339         if (!hHandle)
00340         {
00341             //Report it
00342             ReportError("RemoveSocket","Received socket without a handle!");
00343 
00344             //Exit
00345             return;
00346         }
00347 
00348         //Find the thread data
00349         ThreadData* pData;
00350         pData=GetDataByHWND(hHandle);
00351 
00352         //Do we have it
00353         if (!pData)
00354             //Report it
00355             ReportError("RemoveSocket","Failed to find thread data!");
00356         else
00357         {
00358             //Get our extension
00359             ExtensionData* pExtension;
00360             pExtension=(ExtensionData*)pData->aExtension.lpData;
00361 
00362             {
00363                 //Lock the CS
00364                 CCriticalAutoRelease aRelease(pExtension->pCSection);
00365 
00366                 //Remove from the map
00367                 pExtension->aSocketsMap.erase(pSocket->GetAsyncHandle());
00368             }
00369 
00370             //Decrease socket count
00371             DecreaseSocketCount(hHandle,
00372                                 TRUE);
00373         }
00374     }
00375     ERROR_HANDLER("RemoveSocket")
00376 }

BOOL CSocketThreadManager::RemoveTimeout ( TimerID aTimerID,
BOOL  bInvokeDeleteProc = FALSE 
) [inherited]

Definition at line 847 of file SocketThreadManager.cpp.

00849 {
00850     //Check it's a valid timeout
00851     if (!aTimerID.iIndex)
00852     {
00853         //Write the error
00854         ReportError("RemoveTimeout","Received invalid TimerID");
00855 
00856         //Quit
00857         return FALSE;
00858     }
00859 
00860     try
00861     {
00862         //First unregister the timer
00863         if (!KillTimer(m_pThreadData[aTimerID.iIndex-1].hWindowHandle,
00864                        aTimerID.iTimerID))
00865             //Report it
00866             ReportErrorOS("RemoveTimeout","Failed to delete timer!");
00867 
00868         {
00869             //Lock the timeout manager
00870             CCriticalAutoRelease aRelease(m_pThreadData[aTimerID.iIndex-1].pCSection);
00871 
00872             //Do we need to invoke the delete proc?
00873             if (!bInvokeDeleteProc)
00874                 //No remove from the map
00875                 m_pThreadData[aTimerID.iIndex-1].pMap.erase(aTimerID.iTimerID);
00876             else
00877             {
00878                 //We need to look for the data
00879                 TOMap::iterator aIterator;
00880                 aIterator=m_pThreadData[aTimerID.iIndex-1].pMap.find(aTimerID.iTimerID);
00881 
00882                 //Do we have it?
00883                 if (aIterator!=m_pThreadData[aTimerID.iIndex-1].pMap.end())
00884                 {
00885                     //Do we have the delete proc?
00886                     if (aIterator->second.pDeleteProc)
00887                         //Invoke it
00888                         (*aIterator->second.pDeleteProc)(aIterator->second.pData);
00889 
00890                     //Remove the entry
00891                     m_pThreadData[aTimerID.iIndex-1].pMap.erase(aIterator);
00892                 }
00893                 else
00894                     //Report it
00895                     ReportError("RemoveTimeout","Failed to find data!");
00896             }
00897                     
00898             //Decrease the count
00899             --m_pThreadData[aTimerID.iIndex-1].iTimeoutCount;
00900 
00901             //Set the old timer ID
00902             aTimerID.iIndex=0;
00903             aTimerID.iMS=0;
00904             aTimerID.iTimerID=0;
00905         }
00906 
00907         //Done 
00908         return TRUE;
00909     }
00910     ERROR_HANDLER_RETURN("RemoveTimeout",FALSE)
00911 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
const std::string &  rMessage,
int  iErrorCode 
) const [protected, virtual, inherited]

Definition at line 271 of file ErrorHandler.cpp.

00274 {
00275     if (!GetLog())
00276         return;
00277 
00278     try
00279     {
00280         //Convert the error code
00281         char aTmp[11];
00282         sprintf(aTmp,"%d",iErrorCode);
00283 
00284         //Get the string for it
00285         std::string sError;
00286         sError=rMessage;
00287         sError+=", and Socket error: ";
00288         sError+=aTmp;
00289         sError+=", ";
00290         sError+=ErrorCodeToString(iErrorCode);
00291 
00292         //Report to the log
00293         WriteError(m_sClassName,
00294                    rMethod,
00295                    sError);
00296     }
00297     ERROR_UNKNOWN("ReportError")
00298 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
int  iErrorCode 
) const [protected, virtual, inherited]

Definition at line 300 of file ErrorHandler.cpp.

00302 {
00303     if (!GetLog())
00304         return;
00305 
00306     try
00307     {
00308         //Convert the error code
00309         char aTmp[11];
00310         sprintf(aTmp,"%d",iErrorCode);
00311 
00312         //Get the string for it
00313         std::string sError;
00314         sError="Socket error: ";
00315         sError+=aTmp;
00316         sError+=", ";
00317         sError+=ErrorCodeToString(iErrorCode);
00318 
00319         //Report to the log
00320         WriteError(m_sClassName,
00321                    rMethod,
00322                    sError);
00323     }
00324     ERROR_UNKNOWN("ReportError")
00325 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
const std::string &  rMessage,
const std::string &  rAdditionalData 
) const [protected, virtual, inherited]

Definition at line 416 of file ErrorHandler.cpp.

00419 {
00420     if (!GetLog())
00421         return;
00422 
00423     try
00424     {
00425         //Create the new message
00426         std::string sNewMessage(rMessage);
00427         sNewMessage+=", Additional data: ";
00428         sNewMessage+=rAdditionalData;
00429 
00430         //Report to the log
00431         WriteError(m_sClassName,
00432                    rMethod,
00433                    sNewMessage);
00434     }
00435     ERROR_UNKNOWN("ReportError")
00436 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
const std::string &  rMessage,
DWORD  dwAdditionalData 
) const [protected, virtual, inherited]

Definition at line 438 of file ErrorHandler.cpp.

00441 {
00442     if (!GetLog())
00443         return;
00444 
00445     try
00446     {
00447         //Convert the number
00448         char aTmp[11];
00449         ltoa(dwAdditionalData,aTmp,10);
00450 
00451         //Create the new message
00452         std::string sNewMessage(rMessage);
00453         sNewMessage+=", Additional data: ";
00454         sNewMessage+=aTmp;
00455 
00456         //Report to the log
00457         WriteError(m_sClassName,
00458                    rMethod,
00459                    sNewMessage);
00460     }
00461     ERROR_UNKNOWN("ReportError")
00462 }

void CErrorHandler::ReportError ( const std::string &  rMethod,
const std::string &  rMessage 
) const [protected, virtual, inherited]

Definition at line 327 of file ErrorHandler.cpp.

00329 {
00330     if (!GetLog())
00331         return;
00332 
00333     try
00334     {
00335         //Report to the log
00336         WriteError(m_sClassName,
00337                    rMethod,
00338                    rMessage);
00339     }
00340     ERROR_UNKNOWN("ReportError")
00341 }

void CErrorHandler::ReportError ( const std::string &  rMethod  )  const [protected, virtual, inherited]

Definition at line 470 of file ErrorHandler.cpp.

00471 {
00472     if (!GetLog())
00473         return;
00474 
00475     try
00476     {
00477         //Get the last error
00478         DWORD dwLastError;
00479         dwLastError=GetLastError();
00480 
00481         //Report the error
00482         WriteError(m_sClassName,
00483                    rMethod,
00484                    ErrorCodeToString(dwLastError));
00485     }
00486     ERROR_UNKNOWN("ReportError")
00487 }

void CErrorHandler::ReportErrorOS ( const std::string &  rMethod,
const std::string &  rMessage 
) const [protected, virtual, inherited]

Definition at line 378 of file ErrorHandler.cpp.

00380 {
00381     if (!GetLog())
00382         return;
00383 
00384     try
00385     {
00386         //Get the last error
00387         DWORD dwLastError;
00388         dwLastError=GetLastError();
00389 
00390         //Format the message
00391         std::string sMessage;
00392         sMessage=rMessage;
00393         sMessage+=", with error code: ";
00394 
00395         //Convert the error code
00396         char aTmp[11];
00397         itoa(dwLastError,aTmp,10);
00398 
00399         //Add it again
00400         sMessage+=aTmp;
00401         sMessage+=" ";
00402         sMessage+=ErrorCodeToString(dwLastError);
00403         
00404         //Get the log
00405         CErrorLog* pLog;
00406         pLog=GetLog();
00407 
00408         //Report to the log
00409         WriteError(m_sClassName,
00410                    rMethod,
00411                    sMessage);
00412     }
00413     ERROR_UNKNOWN("ReportErrorOS")
00414 }

void CErrorHandler::ReportStaticError ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage,
DWORD  dwAdditionalData 
) [static, protected, inherited]

Definition at line 540 of file ErrorHandler.cpp.

00544 {
00545     if (!m_pLog)
00546         return;
00547 
00548     try
00549     {
00550         //Convert the number
00551         char aTmp[11];
00552         ltoa(dwAdditionalData,aTmp,10);
00553 
00554         //Create the new message
00555         std::string sNewMessage(rMessage);
00556         sNewMessage+=", Additional data: ";
00557         sNewMessage+=aTmp;
00558 
00559         //Report to the log
00560         WriteStaticError(rClass,
00561                          rMethod,
00562                          sNewMessage);
00563     }
00564     ERROR_UNKNOWN("ReportStaticError")
00565 }

void CErrorHandler::ReportStaticError ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage 
) [static, protected, inherited]

Definition at line 523 of file ErrorHandler.cpp.

00526 {
00527     if (!m_pLog)
00528         return;
00529 
00530     try
00531     {
00532         //Report to the log
00533         WriteStaticError(rClass,
00534                          rMethod,
00535                          rMessage);
00536     }
00537     ERROR_UNKNOWN("ReportStaticError")
00538 }

void CErrorHandler::ReportStaticError ( const std::string &  rClass,
const std::string &  rMethod 
) [static, protected, inherited]

Definition at line 503 of file ErrorHandler.cpp.

00505 {
00506     if (!m_pLog)
00507         return;
00508 
00509     try
00510     {
00511         //Get the last error
00512         DWORD dwLastError;
00513         dwLastError=GetLastError();
00514 
00515         //Report the error
00516         WriteStaticError(rClass,
00517                           rMethod,
00518                           ErrorCodeToString(dwLastError));
00519     }
00520     ERROR_UNKNOWN("ReportStaticError")
00521 }

void CErrorHandler::ReportStaticErrorOS ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage 
) [static, protected, inherited]

Definition at line 343 of file ErrorHandler.cpp.

00346 {
00347     if (!m_pLog)
00348         return;
00349 
00350     try
00351     {
00352         //Get the last error
00353         DWORD dwLastError;
00354         dwLastError=GetLastError();
00355 
00356         //Format the message
00357         std::string sMessage;
00358         sMessage=rMessage;
00359         sMessage+=", with error code: ";
00360 
00361         //Convert the error code
00362         char aTmp[11];
00363         itoa(dwLastError,aTmp,10);
00364 
00365         //Add it again
00366         sMessage+=aTmp;
00367         sMessage+=" ";
00368         sMessage+=ErrorCodeToString(dwLastError);
00369         
00370         //Report to the log
00371         WriteStaticError(rClass,
00372                          rMethod,
00373                          sMessage);
00374     }
00375     ERROR_UNKNOWN("ReportStaticError")
00376 }

BOOL CSocketThreadManager::ReSetTimeout ( const TimerID rTimerID  )  [inherited]

Definition at line 964 of file SocketThreadManager.cpp.

00965 {
00966     //Check if anyone is smartass
00967     if (!rTimerID.iTimerID)
00968     {
00969         //Report it
00970         ReportError("ReSetTimeout","Someone send an empty TimerID!");
00971 
00972         //And exit
00973         return FALSE;
00974     }
00975 
00976     try
00977     {
00978         //Reset the timer
00979         int iResult;
00980         iResult=SetTimer(m_pThreadData[rTimerID.iIndex-1].hWindowHandle,
00981                          rTimerID.iTimerID,
00982                          rTimerID.iMS,
00983                          NULL);
00984 
00985         //Check the result
00986         if (!iResult)
00987             ReportError("ReSetTimeout","Failed to reset the timeout!");
00988 
00989         //Done
00990         return iResult!=0;
00991     }
00992     ERROR_HANDLER_RETURN("ReSetTimeout",FALSE)
00993 }

void CErrorHandler::SetLocalLog ( CErrorLog pLog  )  [inherited]

Definition at line 498 of file ErrorHandler.cpp.

00499 {
00500     m_pLocalLog=pLog;
00501 }

void CErrorHandler::SetLog ( CErrorLog pLog  )  [static, inherited]

Definition at line 464 of file ErrorHandler.cpp.

00465 {
00466     //Save the new log
00467     m_pLog=pLog;
00468 }

void CErrorHandler::SetName ( const std::string &  rName  )  const [protected, inherited]

Definition at line 134 of file ErrorHandler.cpp.

00135 {
00136     //Save the class name
00137     m_sClassName=rName;
00138 }

BOOL CSocketThreadManager::Uninitialize (  )  [inherited]

Definition at line 156 of file SocketThreadManager.cpp.

00157 {
00158     try
00159     {
00160         //Are we initialized?
00161         if (!m_bInitialized)
00162             return TRUE;
00163 
00164         //Are we a static class
00165         if (m_bStaticClass)
00166             //Deallocate the class
00167             UnregisterClass();
00168         else
00169             //Delete the thread data
00170             CleanThreads(FALSE);
00171 
00172         //Unitialized
00173         m_bInitialized=FALSE;
00174 
00175         //Done
00176         return TRUE;
00177     }
00178     ERROR_HANDLER_RETURN("Uninitialize",FALSE)
00179 }

void CErrorHandler::WriteError ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rError 
) const [inherited]

Definition at line 163 of file ErrorHandler.cpp.

00166 {
00167     //Do we have a log?
00168     if (!GetLog())
00169         return;
00170 
00171     //Format the msg
00172     std::string sError;
00173     sError=FormatData(rClass,
00174                       rMethod,
00175                       rError);
00176 
00177     //Write it
00178     GetLog()->WriteError(sError);
00179 }

void CErrorHandler::WriteMessage ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage 
) const [inherited]

Definition at line 199 of file ErrorHandler.cpp.

00202 {
00203     //Do we have a log?
00204     if (!GetLog())
00205         return;
00206 
00207     //Format the msg
00208     std::string sMsg;
00209     sMsg=FormatData(rClass,
00210                     rMethod,
00211                     rMessage,
00212                     true);
00213 
00214     //Write it
00215     GetLog()->WriteMessage(sMsg);
00216 }

void CErrorHandler::WriteStaticError ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rError 
) [static, inherited]

Definition at line 181 of file ErrorHandler.cpp.

00184 {
00185     //Do we have a log?
00186     if (!m_pLog)
00187         return;
00188 
00189     //Format the msg
00190     std::string sError;
00191     sError=FormatData(rClass,
00192                       rMethod,
00193                       rError);
00194 
00195     //Write it
00196     m_pLog->WriteError(sError);
00197 }


The documentation for this class was generated from the following files: