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


CAsyncSocket Class Reference

#include <AsyncSocket.h>

Inheritance diagram for CAsyncSocket:
Collaboration diagram for CAsyncSocket:

List of all members.


Classes

class  CAsyncShutdown

Public Types

enum  _AsyncEvents { aeReceive = 1, aeSend = 2, aeOOB = 4, aeClose = 8 }
typedef enum
CAsyncSocket::_AsyncEvents 
AsyncEvents
typedef MapProc LPMapProc
typedef BOOL(* MapProc )()

Public Member Functions

BOOL HasTimeout () const
void DisableEvents (unsigned char ucEvents)
BOOL IsClosing () const
void ForceReceiveEvent ()
virtual void DeleteSocketFromThread ()
virtual void DeleteSocketFromThread (DWORD dwTimeToWait)
void AllowBlockedBuffer (BOOL bAllow)
virtual BOOL ReAsync ()
virtual BOOL ReBlock ()
void FreezeThread ()
BOOL DisableAsync ()
BOOL KillTimer ()
BOOL SetTimeout (int iMs)
 CAsyncSocket ()
virtual ~CAsyncSocket ()

Static Public Member Functions

static void SimpleMessageMap ()
static void SimpleMessageMap (DWORD dwRunTimeMS)
static void SimpleMessageMap (LPMapProc pProc, BOOL bStopWhenTRUE, DWORD dwSleep)
static char SimpleMessageMapKey (DWORD dwSleep)
static void Initialize ()
static void Shutdown ()
static void SetInstance (HINSTANCE hInst)

Protected Types

enum  _LogPriority { lpDebug, lpMessage, lpCritical, lpError }
typedef enum
CErrorHandler::_LogPriority 
LogPriority

Protected Member Functions

virtual BOOL OnSocketTimeout ()=0
virtual BOOL OnSocketConnect (int iErrorCode)=0
virtual BOOL OnSocketAccept (int iErrorCode)=0
virtual BOOL OnSocketClose (int iErrorCode)=0
virtual BOOL OnSocketOOB (int iErrorCode)=0
virtual BOOL OnSocketWrite (int iErrorCode)=0
virtual BOOL OnSocketReceive (int iErrorCode)=0
BOOL IsBlocking () const
int InternalWSAAsyncSelect (unsigned int wMsg, long lEvent)
void SocketClosing ()
int GetSocketID () const
HWND GetWindowHandle () const
virtual SOCKET GetAsyncHandle () const =0
virtual BOOL SetAsync ()=0
void RemoveSocketFromList ()
void AddSocketToList ()
BOOL IsTimeout () const
BOOL Block ()
virtual BOOL SendBlockedBuffer (const CBlockedBuffer::CBlockedData &rData)
CBlockedBufferGetBlockedBuffer () const
virtual BOOL SocketConnected (int iErrorCode)
virtual BOOL SocketClosed (int iErrorCode)
virtual BOOL SocketWrite (int iErrorCode)
virtual void SystemTimeout ()
BOOL SetSystemTimeout (int iMS)
BOOL KillSystemTimer ()
BOOL HasSystemTimer () const
virtual void OnSocketDelete ()
virtual void SocketCreated ()
int GetSystemLastError () const
int GetLastError () const
virtual void NotifyShutdown ()
void RegisterShutdown (CSpoofBase *pBase)
void SetLastError (const std::string &rMethod) const
void SetLastError (const std::string &, int iErrorCode) const
void SetLocalLog (CErrorLog *pLog)
const std::string & GetClassName () const
void WriteMessage (const std::string &rMethod, const std::string &rMessage, LogPriority aPriority=lpMessage)
void WriteMessage (const std::string &rMethod, const std::string &rMessage, DWORD dwAdditionalData, LogPriority aPriority=lpMessage)
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, 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 CSocketThreadManagerGetSocketThreadManager ()
static int GetErrorCode ()
static BOOL IsInitialized ()
static unsigned long StringToLong (const std::string &rAddress)
static char FAR * LongToString (unsigned long ulAddr)
static std::string LongToStdString (unsigned long ulAddr)
static BOOL InitializeSockets (BOOL bMultiThreaded=TRUE, unsigned long ulNumberOfThreads=10)
static BOOL InitializeSocketsNoMap (BOOL bMultiThreaded=TRUE, unsigned long ulNumberOfThreads=10)
static BOOL ShutdownSockets ()
static unsigned long GetNumberOfThreads ()
static BOOL IsMultiThreaded ()
static CGenericCriticalSectionGetGlobalCriticalSection ()
static std::string GetCurrentDateTime ()
static std::string ErrorCodeToString (DWORD dwErrorCode)
static void SetLog (CErrorLog *pLog)
static void WriteStaticMessage (const std::string &rClass, const std::string &rMethod, const std::string &rMessage, LogPriority aPriority=lpMessage)
static void WriteStaticMessage (const std::string &rClass, const std::string &rMethod, const std::string &rMessage, DWORD dwAdditionalData, LogPriority aPriority=lpMessage)
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)

Detailed Description

Definition at line 78 of file AsyncSocket.h.


Member Typedef Documentation

Definition at line 93 of file AsyncSocket.h.

typedef BOOL(* CAsyncSocket::MapProc)()


Member Enumeration Documentation

Enumerator:
aeReceive 
aeSend 
aeOOB 
aeClose 

Definition at line 83 of file AsyncSocket.h.

00084     {
00085         aeReceive=1,
00086         aeSend=2,
00087         aeOOB=4,
00088         aeClose=8
00089     } AsyncEvents;

enum CErrorHandler::_LogPriority [inherited]

Enumerator:
lpDebug 
lpMessage 
lpCritical 
lpError 

Definition at line 53 of file ErrorHandler.h.

00054     {
00055         lpDebug,
00056         lpMessage,
00057         lpCritical,
00058         lpError
00059     } LogPriority;


Constructor & Destructor Documentation

CAsyncSocket::CAsyncSocket (  ) 

Definition at line 78 of file AsyncSocket.cpp.

00078                            : CSpoofBase(),
00079                                m_bList(FALSE),
00080                                m_bTimeout(FALSE),
00081                                m_pLocalThreadManager(NULL),
00082                                m_hLocalWindowHandle(0),
00083                                m_bFreeze(FALSE),
00084                                m_bBlocking(FALSE),
00085                                m_iMsg(0),
00086                                m_lEvent(0),
00087                                m_iSocketID(0),
00088                                m_pBlockedBuffer(NULL),
00089                                m_bClosing(FALSE),
00090                                m_ucEvents(0)
00091 {
00092     try
00093     {
00094         //Initialize all data
00095         Initialize();
00096 
00097         //We are created
00098         SocketCreated();
00099     }
00100     ERROR_HANDLER("CAsyncSocket")
00101 }

CAsyncSocket::~CAsyncSocket (  )  [virtual]

Definition at line 103 of file AsyncSocket.cpp.

00104 {
00105     try
00106     {
00107         //Do we have any timers ?
00108         //Can't have
00109         if (m_aTimerID.iTimerID)
00110             m_pThreadManager->RemoveTimeout(m_aTimerID);
00111 
00112         if (m_aDeleteTimerID.iTimerID)
00113             m_pThreadManager->RemoveTimeout(m_aDeleteTimerID);
00114 
00115         //If we have a thread manager remove ourselves from it
00116         if (GetThreadManager())
00117             //Remove from the thread manager
00118             GetThreadManager()->DecreaseSocketCount(GetWindowHandle(),m_bFreeze);
00119 
00120         //Delete the blocked buffer
00121         delete m_pBlockedBuffer;
00122     }
00123     ERROR_HANDLER("~CAsyncSocket")
00124 }


Member Function Documentation

void CAsyncSocket::AddSocketToList (  )  [protected]

Definition at line 184 of file AsyncSocket.cpp.

00185 {
00186     try
00187     {
00188         //Allocate our window
00189         AllocateHandle();
00190 
00191         //Do we have a CS
00192         if (m_pCSection)
00193         {
00194             //Enter the CS
00195             CCriticalAutoRelease aRelease(m_pCSection);
00196 
00197             //Add socket to list
00198             m_iSocketID=GetAsyncHandle();
00199             m_aSocketMap.insert(SocketMap::value_type(m_iSocketID,this));
00200 
00201             //Added to list
00202             m_bList=TRUE;
00203         }
00204         else
00205             ReportError("AddSocketToList","Critical section not initialized");
00206     }
00207     ERROR_HANDLER("AddSocketToList")
00208 }

void CAsyncSocket::AllowBlockedBuffer ( BOOL  bAllow  ) 

Definition at line 865 of file AsyncSocket.cpp.

00866 {
00867     try
00868     {
00869         //Do we have a buffer
00870         if (bAllow && 
00871             !m_pBlockedBuffer)
00872             m_pBlockedBuffer=new CBlockedBuffer(this);
00873         else if (!bAllow && 
00874                  m_pBlockedBuffer)
00875         {
00876             //Delete and reset the blocked buffer
00877             delete m_pBlockedBuffer;
00878             m_pBlockedBuffer=NULL;
00879         }
00880     }
00881     ERROR_HANDLER("AllowBlockedBuffer")
00882 }

BOOL CAsyncSocket::Block (  )  [protected]

Definition at line 818 of file AsyncSocket.cpp.

00819 {
00820     try
00821     {
00822         //First disable the events
00823         int iResult;
00824         iResult=WSAAsyncSelect(GetAsyncHandle(),
00825                                GetWindowHandle(),
00826                                0,
00827                                0);
00828 
00829         if (iResult)
00830         {
00831             //Report it
00832             SetLastError("Block");
00833 
00834             //Exit
00835             return FALSE;
00836         }
00837 
00838         unsigned long ulBlocking;
00839         ulBlocking=0;
00840 
00841         //And return to non-blocking
00842         iResult=ioctlsocket(GetAsyncHandle(),
00843                             FIONBIO,
00844                             &ulBlocking);
00845 
00846         if (iResult)
00847         {
00848             //Report it
00849             SetLastError("Block");
00850 
00851             //Exit
00852             return FALSE;
00853         }
00854 
00855         return TRUE;
00856     }
00857     ERROR_HANDLER_RETURN("Block",FALSE)
00858 }

void CAsyncSocket::DeleteSocketFromThread ( DWORD  dwTimeToWait  )  [virtual]

Definition at line 1232 of file AsyncSocket.cpp.

01233 {
01234     try
01235     {
01236         if (!dwTimeToWait)
01237             DeleteSocketFromThread();
01238         else
01239         {
01240             //We are closing
01241             SocketClosing();
01242 
01243             //Are we valid ?
01244             //And do we have a window
01245             if (!m_bList)
01246                 OnSocketDelete();
01247             else
01248             {
01249                 //Create a timer
01250                 m_aDeleteTimerID=m_pThreadManager->RegisterTimeout(dwTimeToWait,
01251                                                                    DeleteTimerProc,
01252                                                                    (LPVOID)this,
01253                                                                    TRUE,
01254                                                                    GetWindowHandle(),
01255                                                                    &m_aDeleteTimerID);
01256 
01257                 //Do we have the timer ?
01258                 if (!m_aDeleteTimerID.iTimerID)
01259                 {
01260                     //Report it
01261                     ReportError("DeleteSocketFromThread","Failed to create timeout!");
01262 
01263                     //Run regular delete
01264                     DeleteSocketFromThread();
01265                 }
01266             }
01267         }
01268     }
01269     ERROR_HANDLER("OnSocketDelete")
01270 }

void CAsyncSocket::DeleteSocketFromThread (  )  [virtual]

Definition at line 1212 of file AsyncSocket.cpp.

01213 {
01214     try
01215     {
01216         //We are closing
01217         SocketClosing();
01218 
01219         //Are we valid ?
01220         //And do we have a window
01221         if (!m_bList)
01222             OnSocketDelete();
01223         else
01224             PostMessage(GetWindowHandle(),
01225                         WM_SOCKET_DELETE,
01226                         (WPARAM)GetAsyncHandle(),
01227                         0);
01228     }
01229     ERROR_HANDLER("OnSocketDelete")
01230 }

BOOL CAsyncSocket::DisableAsync (  ) 

Definition at line 630 of file AsyncSocket.cpp.

00631 {
00632     try
00633     {
00634         //Quit if not ok
00635         if (!CheckAsyncSocketValid())
00636             return FALSE;
00637 
00638         //Set event to read / write / close / oob
00639         int iResult;
00640 
00641         iResult=WSAAsyncSelect(GetAsyncHandle(),
00642                                GetWindowHandle(),
00643                                0,
00644                                0);
00645         if (iResult)
00646         {
00647             //Report it
00648             SetLastError("DisableAsync");
00649 
00650             //Exit
00651             return FALSE;
00652         }
00653         
00654         return TRUE;
00655     }
00656     ERROR_HANDLER_RETURN("DisableAsync",FALSE)
00657 }

void CAsyncSocket::DisableEvents ( unsigned char  ucEvents  ) 

Definition at line 1303 of file AsyncSocket.cpp.

01304 {
01305     try
01306     {
01307         //Save the events
01308         m_ucEvents=ucEvents;
01309     }
01310     ERROR_HANDLER("DisableEvents")
01311 }

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

Definition at line 122 of file ErrorHandler.cpp.

00123 {
00124     try
00125     {
00126         //Get the error string
00127         LPVOID lpMsgBuf;
00128         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
00129                       FORMAT_MESSAGE_FROM_SYSTEM | 
00130                       FORMAT_MESSAGE_IGNORE_INSERTS,
00131                       NULL,
00132                       dwErrorCode,
00133                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
00134                       (LPTSTR) &lpMsgBuf,
00135                       0,
00136                       NULL);
00137 
00138         //Save it
00139         std::string sMessage;
00140         sMessage+=(char*)lpMsgBuf;
00141         
00142         //Release the buffer
00143         LocalFree(lpMsgBuf);
00144 
00145         //Done
00146         return sMessage;
00147     }
00148     catch (...)
00149     {
00150         return "Unknown";
00151     }
00152 }

void CAsyncSocket::ForceReceiveEvent (  ) 

Definition at line 1195 of file AsyncSocket.cpp.

01196 {
01197     try
01198     {
01199         //Are we valid ?
01200         //And do we have a window
01201         if (!m_bList)
01202             OnSocketDelete();
01203         else
01204             PostMessage(GetWindowHandle(),
01205                         WM_SOCKET_FORCED,
01206                         (WPARAM)GetAsyncHandle(),
01207                         0);
01208     }
01209     ERROR_HANDLER("ForceReceiveEvent")
01210 }

void CAsyncSocket::FreezeThread (  ) 

Definition at line 713 of file AsyncSocket.cpp.

00714 {
00715     m_bFreeze=TRUE;
00716 }

virtual SOCKET CAsyncSocket::GetAsyncHandle (  )  const [protected, pure virtual]

CBlockedBuffer * CAsyncSocket::GetBlockedBuffer (  )  const [protected]

Definition at line 884 of file AsyncSocket.cpp.

00885 {
00886     return m_pBlockedBuffer;
00887 }

const std::string & CErrorHandler::GetClassName (  )  const [protected, inherited]

Reimplemented in CSocketThreadManager.

Definition at line 516 of file ErrorHandler.cpp.

00517 {
00518     return m_sClassName;
00519 }

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

Definition at line 521 of file ErrorHandler.cpp.

00522 {
00523     try
00524     {
00525         //Our string
00526         std::string sDate;
00527 
00528         //Our tmp buf
00529         char cTmp[128];
00530 
00531         //Get date
00532         _strdate(cTmp);
00533         sDate=cTmp;
00534         sDate+=' ';
00535 
00536         //Get time
00537         _strtime(cTmp);
00538         sDate+=cTmp;
00539 
00540         //Done
00541         return sDate;
00542     }
00543     ERROR_HANDLER_STATIC_RETURN(CErrorHandler_Class,"GetCurrentDateTime","")
00544 }

int CSpoofBase::GetErrorCode (  )  [static, inherited]

Definition at line 488 of file SpoofBase.cpp.

00489 {
00490     return SOCKET_ERROR;
00491 }

CGenericCriticalSection * CSpoofBase::GetGlobalCriticalSection (  )  [static, inherited]

Definition at line 483 of file SpoofBase.cpp.

00484 {
00485     return m_pCSection;
00486 }

int CSpoofBase::GetLastError (  )  const [inherited]

Definition at line 138 of file SpoofBase.cpp.

00139 {
00140     return m_iLastError;
00141 }

unsigned long CSpoofBase::GetNumberOfThreads (  )  [static, inherited]

Definition at line 463 of file SpoofBase.cpp.

00464 {
00465     return m_ulNumberOfThreads;
00466 }

int CAsyncSocket::GetSocketID (  )  const [protected]

Definition at line 210 of file AsyncSocket.cpp.

00211 {
00212     return m_iSocketID;
00213 }

CSocketThreadManager * CAsyncSocket::GetSocketThreadManager (  )  [static, protected]

Definition at line 895 of file AsyncSocket.cpp.

00896 {
00897     return m_pThreadManager;
00898 }

int CSpoofBase::GetSystemLastError (  )  const [inherited]

Definition at line 478 of file SpoofBase.cpp.

00479 {
00480     return WSAGetLastError();
00481 }

HWND CAsyncSocket::GetWindowHandle (  )  const [protected]

Definition at line 297 of file AsyncSocket.cpp.

00298 {
00299     //Check if we are multithreaded ?
00300     return m_hLocalWindowHandle;
00301 }

BOOL CAsyncSocket::HasSystemTimer (  )  const [protected]

Definition at line 1180 of file AsyncSocket.cpp.

01181 {
01182     return m_aTimerID.iTimerID!=0;
01183 }

BOOL CAsyncSocket::HasTimeout (  )  const

Definition at line 1313 of file AsyncSocket.cpp.

01314 {
01315     return m_bTimeout;
01316 }

void CAsyncSocket::Initialize (  )  [static]

Definition at line 485 of file AsyncSocket.cpp.

00486 {
00487     try
00488     {
00489         //Initialize all data
00490         if (!m_bInitialized && 
00491             CSpoofBase::IsInitialized())
00492         {
00493             //Create the CS
00494             m_pCSection=COSManager::CreateCriticalSection();
00495 
00496             //Create handlers
00497             if (!SetHandlers())
00498             {
00499                 //Report it
00500                 ReportStaticError(CAsyncSocket_Class,"CAsyncSocket","Failed to init handlers!");
00501 
00502                 //Exit
00503                 return;
00504             }
00505 
00506             //Create a new socket to do the shutdown
00507             CAsyncShutdown* pShutdown;
00508             pShutdown=new CAsyncShutdown;
00509 
00510             //The class registers itself
00511             m_bInitialized=TRUE;
00512         }
00513     }
00514     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"Initialize")
00515 }

BOOL CSpoofBase::InitializeSockets ( BOOL  bMultiThreaded = TRUE,
unsigned long  ulNumberOfThreads = 10 
) [static, inherited]

Definition at line 279 of file SpoofBase.cpp.

00281 {
00282     //To avoid double initialize
00283     if (m_bInitialized)
00284     {
00285         //Report it
00286         ReportStaticError(CSpoofBase_Class,"InitializeSockets","Already initialized!");
00287 
00288         //Exit
00289         return TRUE;
00290     }
00291 
00292     //Check that the number of threads are OK?
00293     if (ulNumberOfThreads>CLibConfig::GetInstance().GetMaxThreads())
00294     {
00295         //Report it
00296         ReportStaticError(CSpoofBase_Class,"InitializeSockets","Too many threads!");
00297 
00298         //Exit
00299         return FALSE;
00300     }
00301 
00302     //Do we have threads at all
00303     if (bMultiThreaded &&
00304         !ulNumberOfThreads)
00305     {
00306         //Report it
00307         ReportStaticError(CSpoofBase_Class,"InitializeSockets","Didn't receive any threads!");
00308 
00309         //Exit
00310         return FALSE;
00311     }
00312 
00313     try
00314     {
00315         //Initialize the sockets
00316         WORD wVersionRequested;
00317         wVersionRequested=MAKEWORD(2,2);
00318  
00319         //Try to initialize
00320         WSADATA wsaData;
00321         int iErr;
00322         iErr=WSAStartup(wVersionRequested, 
00323                         &wsaData);
00324 
00325         //Did we succeed?
00326         if (iErr!=0)
00327             /* Tell the user that we could not find a usable */
00328             /* WinSock DLL.                                  */
00329             return FALSE;
00330  
00331         /* Confirm that the WinSock DLL supports 2.2.*/
00332         /* Note that if the DLL supports versions greater    */
00333         /* than 2.2 in addition to 2.2, it will still return */
00334         /* 2.2 in wVersion since that is the version we      */
00335         /* requested.                                        */
00336  
00337         if (LOBYTE(wsaData.wVersion)!=2 || 
00338             HIBYTE(wsaData.wVersion)!=2)
00339         {
00340             /* Tell the user that we could not find a usable */
00341             /* WinSock DLL.                                  */
00342             WSACleanup();
00343 
00344             //Exit
00345             return FALSE;
00346         }
00347 
00348         //Save the threading information
00349         m_bMultiThreaded=bMultiThreaded;
00350         m_ulNumberOfThreads=ulNumberOfThreads;
00351 
00352         //Create the critical section
00353         m_pCSection=COSManager::CreateCriticalSection();
00354 
00355         //And we are initialized
00356         m_bInitialized=TRUE;
00357 
00358         return TRUE;
00359     }
00360     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"InitializeSockets",FALSE)
00361 }

BOOL CSpoofBase::InitializeSocketsNoMap ( BOOL  bMultiThreaded = TRUE,
unsigned long  ulNumberOfThreads = 10 
) [static, inherited]

Definition at line 202 of file SpoofBase.cpp.

00204 {
00205     //To avoid double initialize
00206     if (m_bInitialized)
00207     {
00208         //Report it
00209         ReportStaticError(CSpoofBase_Class,"InitializeSocketsNoMap","Already initialized!");
00210 
00211         //Exit
00212         return TRUE;
00213     }
00214 
00215     //Check that the number of threads are OK?
00216     if (ulNumberOfThreads>CLibConfig::GetInstance().GetMaxThreads())
00217     {
00218         //Report it
00219         ReportStaticError(CSpoofBase_Class,"InitializeSocketsNoMap","Too many threads!");
00220 
00221         //Exit
00222         return FALSE;
00223     }
00224 
00225     //Do we have threads at all
00226     if (bMultiThreaded &&
00227         !ulNumberOfThreads)
00228     {
00229         //Report it
00230         ReportStaticError(CSpoofBase_Class,"InitializeSocketsNoMap","Didn't receive any threads!");
00231 
00232         //Exit
00233         return FALSE;
00234     }
00235 
00236     try
00237     {
00238         //Create the thread data
00239         ThreadData* pThreadData;
00240         pThreadData=new ThreadData;
00241 
00242         //Populate the data
00243         pThreadData->pEvent=COSManager::CreateEvent();
00244         pThreadData->bMultiThreaded=bMultiThreaded;
00245         pThreadData->ulNumberOfThreads=ulNumberOfThreads;
00246 
00247         //Create the thread
00248         m_pThread=new CManagedThread(InitProc);
00249         m_pThread->Start((LPVOID)pThreadData);
00250 
00251         //Wait on the event
00252         if (pThreadData->pEvent->Wait(THREAD_TIMEOUT))
00253         {
00254             //Report it
00255             ReportStaticError(CSpoofBase_Class,"InitializeSocketsNoMap","Timeout waiting for thread");
00256 
00257             //Delete the thread
00258             delete m_pThread;
00259             m_pThread=NULL;
00260 
00261             //Exit
00262             return FALSE;
00263         }
00264 
00265         //Are we initialized
00266         if (!IsInitialized())
00267         {
00268             //Delete the thread
00269             delete m_pThread;
00270             m_pThread=NULL;
00271         }
00272 
00273         //Done
00274         return IsInitialized();
00275     }
00276     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"InitializeSocketsNoMap",FALSE)
00277 }

int CAsyncSocket::InternalWSAAsyncSelect ( unsigned int  wMsg,
long  lEvent 
) [protected]

Definition at line 739 of file AsyncSocket.cpp.

00740 {
00741     try
00742     {
00743         //Cache the values
00744         m_iMsg=wMsg;
00745         m_lEvent=lEvent;
00746 
00747         //Message pairs
00748         typedef struct _MsgPair
00749         {
00750             unsigned int    uiMsg;
00751             AsyncEvents     aEvents;
00752         } MsgPair;
00753 
00754         //Our max events
00755         static const int iMaxEvents=4;
00756 
00757         //Our events data
00758         static const MsgPair aMsgPair[iMaxEvents]={{FD_READ,aeReceive},
00759                                                    {FD_WRITE,aeSend},
00760                                                    {FD_OOB,aeOOB},
00761                                                    {FD_CLOSE,aeClose}};
00762 
00763         //Check if the messages are allowed
00764         for (int iCounter=0;iCounter<iMaxEvents;++iCounter)
00765             if ((m_lEvent & aMsgPair[iCounter].uiMsg) &&
00766                 (m_ucEvents & ((unsigned char)aMsgPair[iCounter].aEvents)))
00767                 //Remove it
00768                 m_lEvent^=aMsgPair[iCounter].uiMsg;
00769 
00770         if (m_bBlocking)
00771             return 0;
00772         else
00773             //And call the async select
00774             return WSAAsyncSelect(GetAsyncHandle(),
00775                                   GetWindowHandle(),
00776                                   wMsg,
00777                                   lEvent);
00778     }
00779     ERROR_HANDLER_RETURN("InternalWSAAsyncSelect",GetErrorCode())
00780 }

BOOL CAsyncSocket::IsBlocking (  )  const [protected]

Definition at line 860 of file AsyncSocket.cpp.

00861 {
00862     return m_bBlocking;
00863 }

BOOL CAsyncSocket::IsClosing (  )  const

Definition at line 1298 of file AsyncSocket.cpp.

01299 {
01300     return m_bClosing;
01301 }

BOOL CSpoofBase::IsInitialized (  )  [static, inherited]

Definition at line 468 of file SpoofBase.cpp.

00469 {
00470     return m_bInitialized;
00471 }

BOOL CSpoofBase::IsMultiThreaded (  )  [static, inherited]

Definition at line 458 of file SpoofBase.cpp.

00459 {
00460     return m_bMultiThreaded;
00461 }

BOOL CAsyncSocket::IsTimeout (  )  const [protected]

Reimplemented in CPingSocket.

Definition at line 480 of file AsyncSocket.cpp.

00481 {
00482     return m_bTimeout;
00483 }

BOOL CAsyncSocket::KillSystemTimer (  )  [protected]

Definition at line 1129 of file AsyncSocket.cpp.

01130 {
01131     try
01132     {
01133         //Only if we have one
01134         if (!m_aTimerID.iTimerID)
01135             return TRUE;
01136 
01137         return GetThreadManager()->RemoveTimeout(m_aTimerID);
01138     }
01139     ERROR_HANDLER_RETURN("KillSystemTimer",FALSE)
01140 }

BOOL CAsyncSocket::KillTimer (  ) 

Definition at line 344 of file AsyncSocket.cpp.

00345 {
00346     try
00347     {
00348         HWND hWindowHandle;
00349         hWindowHandle=GetWindowHandle();
00350 
00351         if (!hWindowHandle || 
00352             !m_bTimeout)
00353             return FALSE;
00354 
00355         //No timer in any case
00356         m_bTimeout=FALSE;
00357 
00358         BOOL bResult;
00359         bResult=::KillTimer(hWindowHandle,
00360                             GetAsyncHandle());
00361 
00362         if (!bResult)
00363             //Fire an error
00364             ReportError("KillTimer");
00365 
00366         return bResult;
00367     }
00368     ERROR_HANDLER_RETURN("KillTimer",FALSE)
00369 }

std::string CSpoofBase::LongToStdString ( unsigned long  ulAddr  )  [static, inherited]

Definition at line 420 of file SpoofBase.cpp.

00421 {
00422     try
00423     {
00424         //First create the address
00425         in_addr addr;
00426 
00427         //Assign it
00428         addr.S_un.S_addr=ulAddr;
00429 
00430         //Enter the critical section
00431         CCriticalAutoRelease aRelease(m_pCSection);
00432 
00433         //Return the value
00434         return inet_ntoa(addr);
00435     }
00436     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"LongToStdString","0.0.0.0")
00437 }

char FAR * CSpoofBase::LongToString ( unsigned long  ulAddr  )  [static, inherited]

Definition at line 439 of file SpoofBase.cpp.

00440 {
00441     try
00442     {
00443         //First create the address
00444         in_addr addr;
00445 
00446         //Assign it
00447         addr.S_un.S_addr=ulAddr;
00448 
00449         //Enter the critical section
00450         CCriticalAutoRelease aRelease(m_pCSection);
00451 
00452         //Return the value
00453         return inet_ntoa(addr);
00454     }
00455     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"LongToString",NULL)
00456 }

void CSpoofBase::NotifyShutdown (  )  [protected, virtual, inherited]

Definition at line 402 of file SpoofBase.cpp.

00403 {
00404 }

virtual BOOL CAsyncSocket::OnSocketAccept ( int  iErrorCode  )  [protected, pure virtual]

virtual BOOL CAsyncSocket::OnSocketClose ( int  iErrorCode  )  [protected, pure virtual]

virtual BOOL CAsyncSocket::OnSocketConnect ( int  iErrorCode  )  [protected, pure virtual]

void CAsyncSocket::OnSocketDelete (  )  [protected, virtual]

Definition at line 1185 of file AsyncSocket.cpp.

01186 {
01187     try
01188     {
01189         //Delete ourselves
01190         delete this;
01191     }
01192     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"OnSocketDelete")
01193 }

virtual BOOL CAsyncSocket::OnSocketOOB ( int  iErrorCode  )  [protected, pure virtual]

virtual BOOL CAsyncSocket::OnSocketReceive ( int  iErrorCode  )  [protected, pure virtual]

virtual BOOL CAsyncSocket::OnSocketTimeout (  )  [protected, pure virtual]

virtual BOOL CAsyncSocket::OnSocketWrite ( int  iErrorCode  )  [protected, pure virtual]

BOOL CAsyncSocket::ReAsync (  )  [virtual]

Definition at line 782 of file AsyncSocket.cpp.

00783 {
00784     if (!m_bBlocking)
00785         return TRUE;
00786 
00787     try
00788     {
00789         //Quit if not ok
00790         if (!CheckAsyncSocketValid())
00791             return FALSE;
00792 
00793         //First disable the events
00794         int iResult;
00795         iResult=WSAAsyncSelect(GetAsyncHandle(),
00796                                GetWindowHandle(),
00797                                m_iMsg,
00798                                m_lEvent);
00799 
00800         if (iResult)
00801         {
00802             //Report it
00803             SetLastError("ReAsync");
00804 
00805             //Exit
00806             return FALSE;
00807         }
00808 
00809         //Set to async
00810         m_bBlocking=FALSE;
00811 
00812         //And quit
00813         return TRUE;
00814     }
00815     ERROR_HANDLER_RETURN("ReAsync",FALSE)
00816 }

BOOL CAsyncSocket::ReBlock (  )  [virtual]

Definition at line 718 of file AsyncSocket.cpp.

00719 {
00720     if (m_bBlocking)
00721         return TRUE;
00722 
00723     try
00724     {
00725         //Quit if not ok
00726         if (!CheckAsyncSocketValid())
00727             return FALSE;
00728 
00729         if (Block())
00730             //Set to reblock
00731             m_bBlocking=TRUE;
00732 
00733         //And quit
00734         return TRUE;
00735     }
00736     ERROR_HANDLER_RETURN("ReBlock",FALSE)
00737 }

void CSpoofBase::RegisterShutdown ( CSpoofBase pBase  )  [protected, inherited]

Definition at line 406 of file SpoofBase.cpp.

00407 {
00408     try
00409     {
00410         //Check if we already have a class
00411         if (m_pShutdownClass)
00412             delete m_pShutdownClass;
00413 
00414         //Take it
00415         m_pShutdownClass=pBase;
00416     }
00417     ERROR_HANDLER("RegisterShutdown")
00418 }

void CAsyncSocket::RemoveSocketFromList (  )  [protected]

Definition at line 303 of file AsyncSocket.cpp.

00304 {
00305     try
00306     {
00307         if (m_bList)
00308             if (m_pCSection)
00309             {
00310                 //Enter the CS
00311                 CCriticalAutoRelease aRelease(m_pCSection);
00312 
00313                 //Erase it
00314                 m_aSocketMap.erase(GetSocketID());
00315             }
00316             else
00317                 ReportError("RemoveSocketFromList","Critical section not initialized");
00318     }
00319     ERROR_HANDLER("RemoveSocketFromList")
00320 }

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

Definition at line 154 of file ErrorHandler.cpp.

00157 {
00158     if (!GetLog())
00159         return;
00160 
00161     try
00162     {
00163         //Get the log
00164         CErrorLog* pLog;
00165         pLog=GetLog();
00166 
00167         //Convert the error code
00168         char aTmp[11];
00169         sprintf(aTmp,"%d",iErrorCode);
00170 
00171         //Get the string for it
00172         std::string sError;
00173         sError=rMessage;
00174         sError+=", and Socket error: ";
00175         sError+=aTmp;
00176         sError+=", ";
00177         sError+=ErrorCodeToString(iErrorCode);
00178 
00179         //Report to the log
00180         pLog->ReportError(m_sClassName,
00181                           rMethod,
00182                           sError);
00183     }
00184     ERROR_UNKNOWN("ReportError")
00185 }

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

Definition at line 187 of file ErrorHandler.cpp.

00189 {
00190     if (!GetLog())
00191         return;
00192 
00193     try
00194     {
00195         //Get the log
00196         CErrorLog* pLog;
00197         pLog=GetLog();
00198 
00199         //Convert the error code
00200         char aTmp[11];
00201         sprintf(aTmp,"%d",iErrorCode);
00202 
00203         //Get the string for it
00204         std::string sError;
00205         sError="Socket error: ";
00206         sError+=aTmp;
00207         sError+=", ";
00208         sError+=ErrorCodeToString(iErrorCode);
00209 
00210         //Report to the log
00211         pLog->ReportError(m_sClassName,
00212                           rMethod,
00213                           sError);
00214     }
00215     ERROR_UNKNOWN("ReportError")
00216 }

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

Definition at line 275 of file ErrorHandler.cpp.

00278 {
00279     if (!GetLog())
00280         return;
00281 
00282     try
00283     {
00284         //Get the log
00285         CErrorLog* pLog;
00286         pLog=GetLog();
00287 
00288         //Convert the number
00289         char aTmp[11];
00290         ltoa(dwAdditionalData,aTmp,10);
00291 
00292         //Create the new message
00293         std::string sNewMessage(rMessage);
00294         sNewMessage+="Additional data: ";
00295         sNewMessage+=aTmp;
00296 
00297         //Report to the log
00298         pLog->ReportError(m_sClassName,
00299                           rMethod,
00300                           sNewMessage);
00301     }
00302     ERROR_UNKNOWN("ReportError")
00303 }

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

Definition at line 218 of file ErrorHandler.cpp.

00220 {
00221     if (!GetLog())
00222         return;
00223 
00224     try
00225     {
00226         CErrorLog* pLog;
00227         pLog=GetLog();
00228 
00229         //Report to the log
00230         pLog->ReportError(m_sClassName,
00231                           rMethod,
00232                           rMessage);
00233     }
00234     ERROR_UNKNOWN("ReportError")
00235 }

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

Definition at line 311 of file ErrorHandler.cpp.

00312 {
00313     if (!GetLog())
00314         return;
00315 
00316     try
00317     {
00318 #ifdef WIN32
00319         //Get the last error
00320         DWORD dwLastError;
00321         dwLastError=GetLastError();
00322 
00323         //Report the error
00324         GetLog()->ReportError(m_sClassName,
00325                               rMethod,
00326                               ErrorCodeToString(dwLastError));
00327 
00328 #else
00329         GetLog()->ReportCatchError(m_sClassName,
00330                                    rMethod,
00331                                    "Unknown error!");
00332 #endif
00333     }
00334     ERROR_UNKNOWN("ReportError")
00335 }

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

Definition at line 237 of file ErrorHandler.cpp.

00239 {
00240     if (!GetLog())
00241         return;
00242 
00243     try
00244     {
00245         //Get the last error
00246         DWORD dwLastError;
00247         dwLastError=GetLastError();
00248 
00249         //Format the message
00250         std::string sMessage;
00251         sMessage=rMessage;
00252         sMessage+=", with error code: ";
00253 
00254         //Convert the error code
00255         char aTmp[11];
00256         itoa(dwLastError,aTmp,10);
00257 
00258         //Add it again
00259         sMessage+=aTmp;
00260         sMessage+=" ";
00261         sMessage+=ErrorCodeToString(dwLastError);
00262         
00263         //Get the log
00264         CErrorLog* pLog;
00265         pLog=GetLog();
00266 
00267         //Report to the log
00268         pLog->ReportError(m_sClassName,
00269                           rMethod,
00270                           sMessage);
00271     }
00272     ERROR_UNKNOWN("ReportErrorOS")
00273 }

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

Definition at line 489 of file ErrorHandler.cpp.

00493 {
00494     if (!m_pLog)
00495         return;
00496 
00497     try
00498     {
00499         //Convert the number
00500         char aTmp[11];
00501         ltoa(dwAdditionalData,aTmp,10);
00502 
00503         //Create the new message
00504         std::string sNewMessage(rMessage);
00505         sNewMessage+="Additional data: ";
00506         sNewMessage+=aTmp;
00507 
00508         //Report to the log
00509         m_pLog->ReportError(rClass,
00510                             rMethod,
00511                             sNewMessage);
00512     }
00513     ERROR_UNKNOWN("ReportStaticError")
00514 }

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

Definition at line 472 of file ErrorHandler.cpp.

00475 {
00476     if (!m_pLog)
00477         return;
00478 
00479     try
00480     {
00481         //Report to the log
00482         m_pLog->ReportError(rClass,
00483                             rMethod,
00484                             rMessage);
00485     }
00486     ERROR_UNKNOWN("ReportStaticError")
00487 }

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

Definition at line 446 of file ErrorHandler.cpp.

00448 {
00449     if (!m_pLog)
00450         return;
00451 
00452     try
00453     {
00454 #ifdef WIN32
00455         //Get the last error
00456         DWORD dwLastError;
00457         dwLastError=GetLastError();
00458 
00459         //Report the error
00460         m_pLog->ReportError(rClass,
00461                             rMethod,
00462                             ErrorCodeToString(dwLastError));
00463 #else
00464         m_pLog->ReportError(rClass,
00465                             rMethod,
00466                             "Unknown error!");
00467 #endif
00468     }
00469     ERROR_UNKNOWN("ReportStaticError")
00470 }

BOOL CAsyncSocket::SendBlockedBuffer ( const CBlockedBuffer::CBlockedData rData  )  [protected, virtual]

Reimplemented in CTCPSocketAsync.

Definition at line 889 of file AsyncSocket.cpp.

00890 {
00891     //No implemented at this level
00892     return FALSE;
00893 }

virtual BOOL CAsyncSocket::SetAsync (  )  [protected, pure virtual]

void CAsyncSocket::SetInstance ( HINSTANCE  hInst  )  [static]

Definition at line 275 of file AsyncSocket.cpp.

00276 {
00277     m_hInstance=hInst;
00278 }

void CSpoofBase::SetLastError ( const std::string &  rMethod,
int  iErrorCode 
) const [protected, inherited]

Definition at line 122 of file SpoofBase.cpp.

00124 {
00125     try
00126     {
00127         //First set the error
00128         m_iLastError=iErrorCode;
00129 
00130         //Check if there is an error
00131         if (m_iLastError)
00132             ReportError(rMethod,
00133                         m_iLastError);
00134     }
00135     ERROR_HANDLER("SetLastError")
00136 }

void CSpoofBase::SetLastError ( const std::string &  rMethod  )  const [protected, inherited]

Definition at line 103 of file SpoofBase.cpp.

00104 {
00105     try
00106     {
00107 #ifdef WIN32
00108         //First set the error
00109         m_iLastError=WSAGetLastError();
00110 #else
00111         m_iLastError=errno();
00112 #endif
00113 
00114         //Check if there is an error
00115         if (m_iLastError)
00116             ReportError(rMethod,
00117                         m_iLastError);
00118     }
00119     ERROR_HANDLER("SetLastError")
00120 }

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

Definition at line 441 of file ErrorHandler.cpp.

00442 {
00443     m_pLocalLog=pLog;
00444 }

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

Definition at line 305 of file ErrorHandler.cpp.

00306 {
00307     //Save the new log
00308     m_pLog=pLog;
00309 }

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

Definition at line 116 of file ErrorHandler.cpp.

00117 {
00118     //Save the class name
00119     m_sClassName=rName;
00120 }

BOOL CAsyncSocket::SetSystemTimeout ( int  iMS  )  [protected]

Definition at line 1092 of file AsyncSocket.cpp.

01093 {
01094     try
01095     {
01096         //Do we have a timeout
01097         if (m_aTimerID.iTimerID)
01098         {
01099             //Report it
01100             ReportError("SetSystemTimeout","Please kill previous timer!");
01101 
01102             //Exit
01103             return FALSE;
01104         }
01105 
01106         //Create the timer
01107         m_aTimerID=GetThreadManager()->RegisterTimeout(iMS,
01108                                                        SystemTimerProc,
01109                                                        this,
01110                                                        TRUE,
01111                                                        GetWindowHandle(),
01112                                                        &m_aTimerID);
01113 
01114         //Do we have it
01115         if (!m_aTimerID.iTimerID)
01116         {
01117             //Report it
01118             ReportError("SetSystemTimeout","Failed creating the timer!");
01119 
01120             //Exit
01121             return FALSE;
01122         }
01123         else
01124             return TRUE;
01125     }
01126     ERROR_HANDLER_RETURN("SetSystemTimeout",FALSE)
01127 }

BOOL CAsyncSocket::SetTimeout ( int  iMs  ) 

Definition at line 322 of file AsyncSocket.cpp.

00323 {
00324     try
00325     {
00326         //Get the window handle
00327         HWND hWindowHandle;
00328         hWindowHandle=GetWindowHandle();
00329 
00330         if (!hWindowHandle)
00331             return FALSE;
00332 
00333         //Set the timer
00334         m_bTimeout=SetTimer(hWindowHandle,
00335                             GetAsyncHandle(),
00336                             iMs,
00337                             NULL);
00338 
00339         return m_bTimeout;
00340     }
00341     ERROR_HANDLER_RETURN("SetTimeout",FALSE)
00342 }

void CAsyncSocket::Shutdown (  )  [static]

Definition at line 371 of file AsyncSocket.cpp.

00372 {
00373     try
00374     {
00375         //Only if initialized
00376         if (!m_bInitialized)
00377             return;
00378 
00379         if (!m_pCSection)
00380         {
00381             //Report it
00382             ReportStaticError(CAsyncSocket_Class,"Shutdown","Critical section not initialized");
00383 
00384             //Exit
00385             return;
00386         }
00387 
00388         //Enter the CS
00389         CCriticalAutoRelease aRelease(m_pCSection);
00390 
00391         //Indicate we're shutting down
00392         m_bShuttingDown=TRUE;
00393 
00394         //Our vector of sockets
00395         typedef std::vector<CAsyncSocket*> SocketVector;
00396         SocketVector aVector;
00397 
00398         //Clear the map
00399         SocketMap::iterator aIterator;
00400         aIterator=m_aSocketMap.begin();
00401 
00402         //While not end of the map
00403         while (aIterator!=m_aSocketMap.end())
00404         {
00405             //Add the socket
00406             aVector.push_back(aIterator->second);
00407 
00408             //Next data
00409             ++aIterator;
00410         }
00411 
00412         //Exit the CS
00413         aRelease.Exit();
00414 
00415         //Iterate the vector
00416         while (!aVector.empty())
00417         {
00418             //Get the socket
00419             CAsyncSocket* pSocket;
00420             pSocket=aVector.back();
00421 
00422             //Remove the socket
00423             aVector.pop_back();
00424 
00425             //Try to delete it
00426             try
00427             {
00428                 delete pSocket;
00429             }
00430             ERROR_HANDLER_STATIC(CAsyncSocket_Class,"Shutdown - Deletion")
00431         }
00432 
00433         //Wait for clean up
00434         Sleep(1000);
00435 
00436         //Delete the thread manager
00437         if (m_pThreadManager)
00438         {
00439             delete m_pThreadManager;
00440             m_pThreadManager=NULL;
00441         }
00442 
00443         //Remove the handlers
00444         RemoveHandlers();
00445 
00446         //Delete the CS
00447         delete m_pCSection;
00448         m_pCSection=NULL;
00449     }
00450     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"Shutdown")
00451 }

BOOL CSpoofBase::ShutdownSockets (  )  [static, inherited]

Definition at line 363 of file SpoofBase.cpp.

00364 {
00365     //Only if initialized
00366     if (!m_bInitialized)
00367         return TRUE;
00368 
00369     try
00370     {
00371         //Do we have a thread?
00372         if (m_pThread)
00373         {
00374             //Delete it
00375             delete m_pThread;
00376             m_pThread=NULL;
00377         }
00378 
00379         //Delete the CS
00380         delete m_pCSection;
00381         m_pCSection=NULL;
00382 
00383         //Notify shutdown class
00384         if (m_pShutdownClass)
00385         {
00386             m_pShutdownClass->NotifyShutdown();
00387             delete m_pShutdownClass;
00388         }
00389 
00390         if (WSACleanup()==GetErrorCode())
00391             return FALSE;
00392 
00393         //Not initialized anymore
00394         m_bInitialized=FALSE;
00395 
00396         //Done
00397         return TRUE;
00398     }
00399     ERROR_HANDLER_STATIC_RETURN(CSpoofBase_Class,"ShutdownSockets",FALSE)
00400 }

void CAsyncSocket::SimpleMessageMap ( LPMapProc  pProc,
BOOL  bStopWhenTRUE,
DWORD  dwSleep 
) [static]

Definition at line 1002 of file AsyncSocket.cpp.

01005 {
01006     try
01007     {
01008         //Check if we have the proc
01009         if (!pProc)
01010         {
01011             //Report it
01012             ReportStaticError(CAsyncSocket_Class,"SimpleMessageMap","Recieved null proc!");
01013 
01014             //Exit
01015             return;
01016         }
01017 
01018         //If there is no message map, then receive won't work
01019         MSG msg;
01020 
01021         //Set the message map to zeros
01022         memset(&msg,
01023                0,
01024                sizeof(msg));
01025 
01026         //Stop flag
01027         BOOL bStop;
01028         bStop=FALSE;
01029 
01030         //Start the loop
01031         while (!bStop &&
01032                (*pProc)()!=bStopWhenTRUE)
01033         {
01034             while (!(bStop=(*pProc)()==bStopWhenTRUE) &&
01035                    PeekMessage(&msg, 
01036                                NULL, 
01037                                0, 
01038                                0, 
01039                                PM_REMOVE))
01040             {
01041                 TranslateMessage(&msg);
01042                 DispatchMessage(&msg); 
01043             }
01044 
01045             //Do we need to sleep?
01046             if (!bStop)
01047                 //No messages
01048                 Sleep(dwSleep);
01049         }
01050     }
01051     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap")
01052 }

void CAsyncSocket::SimpleMessageMap ( DWORD  dwRunTimeMS  )  [static]

Definition at line 966 of file AsyncSocket.cpp.

00967 {
00968     try
00969     {
00970         //If there is no message map, then receive won't work
00971         MSG msg;
00972 
00973         //Set the message map to zeros
00974         memset(&msg,
00975                0,
00976                sizeof(msg));
00977 
00978         //Start loop
00979         DWORD dwLoopStart;
00980         dwLoopStart=GetTickCount();
00981 
00982         //Until a key was hit
00983         while (GetTickCount()-dwLoopStart<dwRunTimeMS)
00984         {
00985             while (PeekMessage(&msg, 
00986                                NULL, 
00987                                0, 
00988                                0, 
00989                                PM_REMOVE))
00990             {
00991                 TranslateMessage(&msg);
00992                 DispatchMessage(&msg); 
00993             }
00994 
00995             //Sleep so wont be hanged
00996             Sleep(1);
00997         }
00998     }
00999     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap")
01000 }

void CAsyncSocket::SimpleMessageMap (  )  [static]

Definition at line 941 of file AsyncSocket.cpp.

00942 {
00943     try
00944     {
00945         //If there is no message map, then receive won't work
00946         MSG msg;
00947 
00948         //Set the message map to zeros
00949         memset(&msg,
00950                0,
00951                sizeof(msg));
00952 
00953         while (GetMessage(&msg,
00954                           NULL,
00955                           0,
00956                           0))
00957         {
00958             //Dispatch the message
00959             TranslateMessage(&msg);
00960             DispatchMessage(&msg);
00961         }
00962     }
00963     ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap")
00964 }

char CAsyncSocket::SimpleMessageMapKey ( DWORD  dwSleep  )  [static]

Definition at line 1054 of file AsyncSocket.cpp.

01055 {
01056     try
01057     {
01058         //If there is no message map, then receive won't work
01059         MSG msg;
01060 
01061         //Set the message map to zeros
01062         memset(&msg,
01063                0,
01064                sizeof(msg));
01065 
01066         //Until a key was hit
01067         while (!kbhit())
01068         {
01069             while (!kbhit() &&
01070                    PeekMessage(&msg, 
01071                                NULL, 
01072                                0, 
01073                                0, 
01074                                PM_REMOVE))
01075             {
01076                 TranslateMessage(&msg);
01077                 DispatchMessage(&msg); 
01078             }
01079 
01080             //Do we need to sleep
01081             if (!kbhit())
01082                 //Sleep so wont be hanged
01083                 Sleep(dwSleep);
01084         }
01085         
01086         //Return the char
01087         return getch();
01088     }
01089     ERROR_HANDLER_STATIC_RETURN(CAsyncSocket_Class,"SimpleMessageMapKey",0)
01090 }

BOOL CAsyncSocket::SocketClosed ( int  iErrorCode  )  [protected, virtual]

Definition at line 921 of file AsyncSocket.cpp.

00922 {
00923     try
00924     {
00925         //Call user data
00926         return OnSocketClose(iErrorCode);
00927     }
00928     ERROR_HANDLER_RETURN("SocketClosed",FALSE)
00929 }

void CAsyncSocket::SocketClosing (  )  [protected]

Definition at line 679 of file AsyncSocket.cpp.

00680 {
00681     try
00682     {
00683         //Are we valid
00684         if (m_bClosing ||
00685             GetAsyncHandle()==INVALID_SOCKET)
00686             return;
00687 
00688         //Indicate we are closing
00689         m_bClosing=TRUE;
00690 
00691         //Do we have a regular timer
00692         if (m_bTimeout)
00693             KillTimer();
00694 
00695         //Do we have a system timer ?
00696         if (m_aTimerID.iTimerID)
00697             KillSystemTimer();
00698 
00699         //Kill all the messages
00700         m_iMsg=0;
00701         m_lEvent=0;
00702 
00703         //Set it
00704         if (WSAAsyncSelect(GetAsyncHandle(),
00705                            GetWindowHandle(),
00706                            0,
00707                            0))
00708             SetLastError("SocketClosing");
00709     }
00710     ERROR_HANDLER("SocketClosing")
00711 }

BOOL CAsyncSocket::SocketConnected ( int  iErrorCode  )  [protected, virtual]

Definition at line 900 of file AsyncSocket.cpp.

00901 {
00902     try
00903     {
00904         //Did we have an error
00905         if (iErrorCode)
00906             return OnSocketConnect(iErrorCode);
00907 
00908         //Save the connect value
00909         BOOL bConnectValue;
00910         bConnectValue=OnSocketConnect(0);
00911 
00912         //Try to set it to async
00913         if (!SetAsync())
00914             return FALSE;
00915         else
00916             return bConnectValue;
00917     }
00918     ERROR_HANDLER_RETURN("SocketConnected",FALSE)
00919 }

void CAsyncSocket::SocketCreated (  )  [protected, virtual]

Definition at line 1272 of file AsyncSocket.cpp.

01273 {
01274     try
01275     {
01276         //No timer
01277         memset(&m_aTimerID,
01278                0,
01279                sizeof(m_aTimerID));
01280 
01281         //No delete timer
01282         memset(&m_aDeleteTimerID,
01283                0,
01284                sizeof(m_aDeleteTimerID));
01285 
01286         //Set values for new socket
01287         m_iSocketID=0;
01288         m_bBlocking=FALSE;
01289         m_bFreeze=FALSE;
01290         m_lEvent=0;
01291         m_hLocalWindowHandle=0;
01292         m_bList=FALSE;
01293         m_bClosing=FALSE;
01294     }
01295     ERROR_HANDLER("SocketCreated")
01296 }

BOOL CAsyncSocket::SocketWrite ( int  iErrorCode  )  [protected, virtual]

Definition at line 931 of file AsyncSocket.cpp.

00932 {
00933     try
00934     {
00935         //Call user data
00936         return OnSocketWrite(iErrorCode);
00937     }
00938     ERROR_HANDLER_RETURN("SocketWrite",FALSE)
00939 }

unsigned long CSpoofBase::StringToLong ( const std::string &  rAddress  )  [static, inherited]

Definition at line 473 of file SpoofBase.cpp.

00474 {
00475     return inet_addr(rAddress.c_str());
00476 }

void CAsyncSocket::SystemTimeout (  )  [protected, virtual]

Definition at line 1142 of file AsyncSocket.cpp.

01143 {
01144     //Nothing to do
01145 }

void CErrorHandler::WriteMessage ( const std::string &  rMethod,
const std::string &  rMessage,
DWORD  dwAdditionalData,
LogPriority  aPriority = lpMessage 
) [protected, inherited]

Definition at line 355 of file ErrorHandler.cpp.

00359 {
00360     if (!GetLog())
00361         return;
00362 
00363     try
00364     {
00365         //Convert the number
00366         char aTmp[11];
00367         ltoa(dwAdditionalData,aTmp,10);
00368 
00369         //Create the new message
00370         std::string sNewMessage(rMessage);
00371         sNewMessage+="Additional data: ";
00372         sNewMessage+=aTmp;
00373 
00374         //Delegate the call
00375         GetLog()->WriteMessage(m_sClassName,
00376                                rMethod,
00377                                sNewMessage,
00378                                aPriority);
00379     }
00380     ERROR_UNKNOWN("WriteMessage")
00381 }

void CErrorHandler::WriteMessage ( const std::string &  rMethod,
const std::string &  rMessage,
LogPriority  aPriority = lpMessage 
) [protected, inherited]

Definition at line 337 of file ErrorHandler.cpp.

00340 {
00341     if (!GetLog())
00342         return;
00343 
00344     try
00345     {
00346         //Delegate the call
00347         GetLog()->WriteMessage(m_sClassName,
00348                                rMethod,
00349                                rMessage,
00350                                aPriority);
00351     }
00352     ERROR_UNKNOWN("WriteMessage")
00353 }

void CErrorHandler::WriteStaticMessage ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage,
DWORD  dwAdditionalData,
LogPriority  aPriority = lpMessage 
) [static, protected, inherited]

Definition at line 403 of file ErrorHandler.cpp.

00408 {
00409     if (!m_pLog)
00410         return;
00411 
00412     try
00413     {
00414         //Convert the number
00415         char aTmp[11];
00416         ltoa(dwAdditionalData,aTmp,10);
00417 
00418         //Create the new message
00419         std::string sNewMessage(rMessage);
00420         sNewMessage+="Additional data: ";
00421         sNewMessage+=aTmp;
00422 
00423         //Delegate the call
00424         m_pLog->WriteMessage(rClass,
00425                              rMethod,
00426                              sNewMessage,
00427                              aPriority);
00428     }
00429     ERROR_UNKNOWN("WriteStaticMessage")
00430 }

void CErrorHandler::WriteStaticMessage ( const std::string &  rClass,
const std::string &  rMethod,
const std::string &  rMessage,
LogPriority  aPriority = lpMessage 
) [static, protected, inherited]

Definition at line 383 of file ErrorHandler.cpp.

00388 {
00389     if (!m_pLog)
00390         return;
00391 
00392     try
00393     {
00394         //Delegate the call
00395         m_pLog->WriteMessage(rClass,
00396                              rMethod,
00397                              rMessage,
00398                              aPriority);
00399     }
00400     ERROR_UNKNOWN("WriteStaticMessage")
00401 }


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