CAsyncSocket Class Reference#include <AsyncSocket.h>
Inheritance diagram for CAsyncSocket:
![]()
Collaboration diagram for CAsyncSocket:
![]()
Detailed DescriptionDefinition at line 77 of file AsyncSocket.h. Member Typedef Documentation
Definition at line 93 of file AsyncSocket.h.
Member Enumeration Documentation
Definition at line 83 of file AsyncSocket.h. 00084 { 00085 aeReceive=1, 00086 aeSend=2, 00087 aeOOB=4, 00088 aeClose=8 00089 } AsyncEvents;
Constructor & Destructor Documentation
Definition at line 101 of file AsyncSocket.cpp. 00101 : CSocketBase(), 00102 m_bList(FALSE), 00103 m_bTimeout(FALSE), 00104 m_pLocalThreadManager(NULL), 00105 m_hLocalWindowHandle(0), 00106 m_bFreeze(FALSE), 00107 m_bBlocking(FALSE), 00108 m_iMsg(0), 00109 m_lEvent(0), 00110 m_iSocketID(0), 00111 m_pBlockedBuffer(NULL), 00112 m_bClosing(FALSE), 00113 m_ucEvents(0), 00114 m_pSendEvent(NULL), 00115 m_bBlockSend(TRUE), 00116 m_pThread(NULL), 00117 m_bDeleting(FALSE), 00118 m_bDetached(FALSE) 00119 { 00120 try 00121 { 00122 //Create the event 00123 m_pSendEvent=COSManager::CreateEvent(); 00124 00125 //Initialize all data 00126 Initialize(); 00127 00128 //We are created 00129 SocketCreated(); 00130 } 00131 ERROR_HANDLER("CAsyncSocket") 00132 }
Definition at line 134 of file AsyncSocket.cpp. 00135 { 00136 try 00137 { 00138 //Do we have any timers ? 00139 //Can't have 00140 if (m_aTimerID.iTimerID) 00141 GetThreadManager()->RemoveTimeout(m_aTimerID); 00142 00143 if (m_aDeleteTimerID.iTimerID) 00144 GetThreadManager()->RemoveTimeout(m_aDeleteTimerID); 00145 00146 //If we have a thread manager remove ourselves from it 00147 if (GetThreadManager()) 00148 //Remove from the thread manager 00149 GetThreadManager()->DecreaseSocketCount(GetWindowHandle(), 00150 m_bFreeze); 00151 00152 //Are we a detached socket? 00153 if (m_bDetached) 00154 delete GetThreadManager(); 00155 00156 //Delete the blocked buffer 00157 delete m_pBlockedBuffer; 00158 00159 //Delete the event 00160 delete m_pSendEvent; 00161 } 00162 ERROR_HANDLER("~CAsyncSocket") 00163 }
Member Function Documentation
Definition at line 233 of file AsyncSocket.cpp. 00234 { 00235 try 00236 { 00237 //Allocate our window 00238 AllocateHandle(); 00239 00240 //We are in the list 00241 m_bList=TRUE; 00242 } 00243 ERROR_HANDLER("AddSocketToList") 00244 }
Definition at line 681 of file AsyncSocket.cpp. 00682 { 00683 try 00684 { 00685 //Do we have a buffer 00686 if (bAllow && 00687 !m_pBlockedBuffer) 00688 m_pBlockedBuffer=new CBlockedBuffer(this); 00689 else if (!bAllow && 00690 m_pBlockedBuffer) 00691 { 00692 //Delete and reset the blocked buffer 00693 delete m_pBlockedBuffer; 00694 m_pBlockedBuffer=NULL; 00695 } 00696 } 00697 ERROR_HANDLER("AllowBlockedBuffer") 00698 }
Definition at line 634 of file AsyncSocket.cpp. 00635 { 00636 try 00637 { 00638 //First disable the events 00639 int iResult; 00640 iResult=WSAAsyncSelect(GetAsyncHandle(), 00641 GetWindowHandle(), 00642 0, 00643 0); 00644 00645 if (iResult) 00646 { 00647 //Report it 00648 SetLastError("Block"); 00649 00650 //Exit 00651 return FALSE; 00652 } 00653 00654 unsigned long ulBlocking; 00655 ulBlocking=0; 00656 00657 //And return to non-blocking 00658 iResult=ioctlsocket(GetAsyncHandle(), 00659 FIONBIO, 00660 &ulBlocking); 00661 00662 if (iResult) 00663 { 00664 //Report it 00665 SetLastError("Block"); 00666 00667 //Exit 00668 return FALSE; 00669 } 00670 00671 return TRUE; 00672 } 00673 ERROR_HANDLER_RETURN("Block",FALSE) 00674 }
Definition at line 584 of file AsyncSocket.cpp. 00585 { 00586 try 00587 { 00588 //Quit if not ok 00589 if (!CheckAsyncSocketValid()) 00590 return FALSE; 00591 00592 //Do it 00593 return !InternalWSAAsyncSelect(0,0); 00594 } 00595 ERROR_HANDLER_RETURN("ClearEvents",FALSE) 00596 }
Definition at line 1269 of file AsyncSocket.cpp. 01270 { 01271 try 01272 { 01273 //Do we have a thread manager? 01274 if (!m_pThreadManager || 01275 !m_pThreadManager->IsInitialized()) 01276 { 01277 //Report it 01278 ReportStaticError(CAsyncSocket_Class,"SetLocalThreadManager","Manager is either null or not initialized!"); 01279 01280 //Exit 01281 return NULL; 01282 } 01283 01284 //Which thread count 01285 unsigned long ulThreadCount; 01286 if (!ulThreads) 01287 ulThreadCount=m_pThreadManager->GetNumberOfThreads(); 01288 else 01289 ulThreadCount=ulThreads; 01290 01291 //Clone it 01292 CSocketThreadManagerImp* pManager; 01293 pManager=new CSocketThreadManagerImp(m_hInstance); 01294 if (!pManager->Initialize(ulThreads)) 01295 { 01296 //Report it 01297 ReportStaticError(CAsyncSocket_Class,"CloneThreadManager","Failed to initialize the thread manager!"); 01298 01299 //Delete it 01300 delete pManager; 01301 01302 //Exit 01303 return NULL; 01304 } 01305 else 01306 return pManager; 01307 } 01308 ERROR_HANDLER_STATIC_RETURN(CAsyncSocket_Class,"CloneThreadManager",NULL) 01309 }
Definition at line 1100 of file AsyncSocket.cpp. 01101 { 01102 try 01103 { 01104 if (!dwTimeToWait) 01105 DeleteSocketFromThread(); 01106 else 01107 { 01108 //We are closing 01109 SocketClosing(); 01110 01111 //Are we valid ? 01112 //And do we have a window 01113 if (!m_bList) 01114 OnSocketDelete(); 01115 else 01116 { 01117 //Create a timer 01118 m_aDeleteTimerID=GetThreadManager()->RegisterTimeout(dwTimeToWait, 01119 DeleteTimerProc, 01120 (LPVOID)this, 01121 TRUE, 01122 GetWindowHandle(), 01123 &m_aDeleteTimerID); 01124 01125 //Do we have the timer ? 01126 if (!m_aDeleteTimerID.iTimerID) 01127 { 01128 //Report it 01129 ReportError("DeleteSocketFromThread","Failed to create timeout!"); 01130 01131 //Run regular delete 01132 DeleteSocketFromThread(); 01133 } 01134 } 01135 } 01136 } 01137 ERROR_HANDLER("OnSocketDelete") 01138 }
Definition at line 1080 of file AsyncSocket.cpp. 01081 { 01082 try 01083 { 01084 //We are closing 01085 SocketClosing(); 01086 01087 //Are we valid ? 01088 //And do we have a window 01089 if (!m_bList) 01090 OnSocketDelete(); 01091 else 01092 PostMessage(GetWindowHandle(), 01093 WM_SOCKET_DELETE, 01094 (WPARAM)GetAsyncHandle(), 01095 0); 01096 } 01097 ERROR_HANDLER("OnSocketDelete") 01098 }
Definition at line 1140 of file AsyncSocket.cpp. 01141 { 01142 try 01143 { 01144 //We are closing 01145 SocketClosing(); 01146 01147 //Are we valid ? 01148 //And do we have a window 01149 if (!m_bList) 01150 OnSocketDelete(); 01151 else 01152 { 01153 //Create the event 01154 CGenericEvent* pEvent; 01155 pEvent=COSManager::CreateEvent(); 01156 01157 //Post the message 01158 PostMessage(GetWindowHandle(), 01159 WM_SOCKET_DELETE, 01160 (WPARAM)GetAsyncHandle(), 01161 (LPARAM)pEvent); 01162 01163 //Wait for the event 01164 if (pEvent->Wait(15000)) 01165 //Report it 01166 ReportStaticError(CAsyncSocket_Class,"DeleteSocketFromThreadWait","Timeout waiting for event!"); 01167 else 01168 delete pEvent; 01169 } 01170 } 01171 ERROR_HANDLER("OnSocketDelete") 01172 }
Definition at line 165 of file AsyncSocket.cpp. 00166 { 00167 try 00168 { 00169 //Create a new socket imp 00170 CSocketThreadManagerImp* pClone; 00171 pClone=CloneThreadManager(1); 00172 00173 //Do we have it? 00174 if (!pClone) 00175 //Report it 00176 ReportError("DetachedSocketThread","Failed to create detach manager, will resume as normal!"); 00177 else 00178 { 00179 //Set it as local 00180 if (!SetLocalThreadManager(pClone)) 00181 ReportError("DetachedSocketThread","Failed to set manager!"); 00182 else 00183 //Set we are detahced 00184 m_bDetached=TRUE; 00185 } 00186 } 00187 ERROR_HANDLER("DetachedSocketThread") 00188 }
Definition at line 426 of file AsyncSocket.cpp. 00427 { 00428 try 00429 { 00430 //Quit if not ok 00431 if (!CheckAsyncSocketValid()) 00432 return FALSE; 00433 00434 //Set event to read / write / close / oob 00435 int iResult; 00436 00437 iResult=WSAAsyncSelect(GetAsyncHandle(), 00438 GetWindowHandle(), 00439 0, 00440 0); 00441 if (iResult) 00442 { 00443 //Report it 00444 SetLastError("DisableAsync"); 00445 00446 //Exit 00447 return FALSE; 00448 } 00449 00450 return TRUE; 00451 } 00452 ERROR_HANDLER_RETURN("DisableAsync",FALSE) 00453 }
Definition at line 1205 of file AsyncSocket.cpp. 01206 { 01207 try 01208 { 01209 //Save the events 01210 m_ucEvents=ucEvents; 01211 } 01212 ERROR_HANDLER("DisableEvents") 01213 }
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 }
Definition at line 1063 of file AsyncSocket.cpp. 01064 { 01065 try 01066 { 01067 //Are we valid ? 01068 //And do we have a window 01069 if (!m_bList) 01070 OnSocketDelete(); 01071 else 01072 PostMessage(GetWindowHandle(), 01073 WM_SOCKET_FORCED, 01074 (WPARAM)GetAsyncHandle(), 01075 0); 01076 } 01077 ERROR_HANDLER("ForceReceiveEvent") 01078 }
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 }
Implemented in CTCPSocketAsync, and CUDPSocketAsync.
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 }
Definition at line 393 of file AsyncSocket.cpp. 00394 { 00395 if (!m_pLocalThreadManager) 00396 return m_pThreadManager; 00397 else 00398 return m_pLocalThreadManager; 00399 }
Definition at line 1044 of file AsyncSocket.cpp. 01045 { 01046 return m_aTimerID.iTimerID!=0; 01047 }
Definition at line 361 of file AsyncSocket.cpp. 00362 { 00363 try 00364 { 00365 //Initialize all data 00366 if (!m_bInitialized && 00367 CSocketBase::IsInitialized()) 00368 { 00369 //Create the CS 00370 m_pCSection=COSManager::CreateCriticalSection(); 00371 00372 //Create handlers 00373 if (!SetHandlers()) 00374 { 00375 //Report it 00376 ReportStaticError(CAsyncSocket_Class,"CAsyncSocket","Failed to init handlers!"); 00377 00378 //Exit 00379 return; 00380 } 00381 00382 //Create a new socket to do the shutdown 00383 CAsyncShutdown* pShutdown; 00384 pShutdown=new CAsyncShutdown; 00385 00386 //The class registers itself 00387 m_bInitialized=TRUE; 00388 } 00389 } 00390 ERROR_HANDLER_STATIC(CAsyncSocket_Class,"Initialize") 00391 }
Definition at line 146 of file SocketBase.cpp. 00148 { 00149 //To avoid double initialize 00150 if (m_bInitialized) 00151 { 00152 //Report it 00153 ReportStaticError(CSocketBase_Class,"InitializeSockets","Already initialized!"); 00154 00155 //Exit 00156 return TRUE; 00157 } 00158 00159 //Check that the number of threads are OK? 00160 if (ulNumberOfThreads>CLibConfig::GetInstance().GetMaxThreads()) 00161 { 00162 //Report it 00163 ReportStaticError(CSocketBase_Class,"InitializeSockets","Too many threads!"); 00164 00165 //Exit 00166 return FALSE; 00167 } 00168 00169 //Do we have threads at all 00170 if (bMultiThreaded && 00171 !ulNumberOfThreads) 00172 { 00173 //Report it 00174 ReportStaticError(CSocketBase_Class,"InitializeSockets","Didn't receive any threads!"); 00175 00176 //Exit 00177 return FALSE; 00178 } 00179 00180 try 00181 { 00182 //Initialize the sockets 00183 WORD wVersionRequested; 00184 wVersionRequested=MAKEWORD(2,2); 00185 00186 //Try to initialize 00187 WSADATA wsaData; 00188 int iErr; 00189 iErr=WSAStartup(wVersionRequested, 00190 &wsaData); 00191 00192 //Did we succeed? 00193 if (iErr!=0) 00194 /* Tell the user that we could not find a usable */ 00195 /* WinSock DLL. */ 00196 return FALSE; 00197 00198 /* Confirm that the WinSock DLL supports 2.2.*/ 00199 /* Note that if the DLL supports versions greater */ 00200 /* than 2.2 in addition to 2.2, it will still return */ 00201 /* 2.2 in wVersion since that is the version we */ 00202 /* requested. */ 00203 00204 if (LOBYTE(wsaData.wVersion)!=2 || 00205 HIBYTE(wsaData.wVersion)!=2) 00206 { 00207 /* Tell the user that we could not find a usable */ 00208 /* WinSock DLL. */ 00209 WSACleanup(); 00210 00211 //Exit 00212 return FALSE; 00213 } 00214 00215 //Save the threading information 00216 m_bMultiThreaded=bMultiThreaded; 00217 m_ulNumberOfThreads=ulNumberOfThreads; 00218 00219 //Create the critical section 00220 m_pCSection=COSManager::CreateCriticalSection(); 00221 m_pCSectionDNS=COSManager::CreateCriticalSection(); 00222 00223 //And we are initialized 00224 m_bInitialized=TRUE; 00225 00226 return TRUE; 00227 } 00228 ERROR_HANDLER_STATIC_RETURN(CSocketBase_Class,"InitializeSockets",FALSE) 00229 }
Definition at line 538 of file AsyncSocket.cpp. 00540 { 00541 try 00542 { 00543 //Cache the values 00544 m_iMsg=wMsg; 00545 m_lEvent=lEvent; 00546 00547 //Message pairs 00548 typedef struct _MsgPair 00549 { 00550 unsigned int uiMsg; 00551 AsyncEvents aEvents; 00552 } MsgPair; 00553 00554 //Our max events 00555 static const int iMaxEvents=4; 00556 00557 //Our events data 00558 static const MsgPair aMsgPair[iMaxEvents]={{FD_READ,aeReceive}, 00559 {FD_WRITE,aeSend}, 00560 {FD_OOB,aeOOB}, 00561 {FD_CLOSE,aeClose}}; 00562 00563 //Check if the messages are allowed 00564 for (int iCounter=0; 00565 iCounter<iMaxEvents; 00566 ++iCounter) 00567 if ((m_lEvent & aMsgPair[iCounter].uiMsg) && 00568 (m_ucEvents & ((unsigned char)aMsgPair[iCounter].aEvents))) 00569 //Remove it 00570 m_lEvent^=aMsgPair[iCounter].uiMsg; 00571 00572 if (m_bBlocking) 00573 return 0; 00574 else 00575 //And call the async select 00576 return WSAAsyncSelect(GetAsyncHandle(), 00577 GetWindowHandle(), 00578 wMsg, 00579 lEvent); 00580 } 00581 ERROR_HANDLER_RETURN("InternalWSAAsyncSelect",GetErrorCode()) 00582 }
Definition at line 1316 of file AsyncSocket.cpp. 01317 { 01318 try 01319 { 01320 //Do we have the thread? 01321 if (m_pThread) 01322 return m_pThread->IsInThread(); 01323 else 01324 return FALSE; 01325 } 01326 ERROR_HANDLER_RETURN("IsInThread",FALSE) 01327 }
Definition at line 993 of file AsyncSocket.cpp. 00994 { 00995 try 00996 { 00997 //Only if we have one 00998 if (!m_aTimerID.iTimerID) 00999 return TRUE; 01000 01001 return GetThreadManager()->RemoveTimeout(m_aTimerID); 01002 } 01003 ERROR_HANDLER_RETURN("KillSystemTimer",FALSE) 01004 }
Definition at line 303 of file AsyncSocket.cpp. 00304 { 00305 try 00306 { 00307 //Get the handle 00308 HWND hWindowHandle; 00309 hWindowHandle=GetWindowHandle(); 00310 00311 if (!hWindowHandle || 00312 !m_bTimeout) 00313 return FALSE; 00314 00315 //No timer in any case 00316 m_bTimeout=FALSE; 00317 00318 //Try to kill the timer 00319 BOOL bResult; 00320 bResult=::KillTimer(hWindowHandle, 00321 GetAsyncHandle()); 00322 00323 if (!bResult) 00324 //Fire an error 00325 ReportError("KillTimer"); 00326 00327 return bResult; 00328 } 00329 ERROR_HANDLER_RETURN("KillTimer",FALSE) 00330 }
Definition at line 291 of file SocketBase.cpp. 00292 { 00293 try 00294 { 00295 //First create the address 00296 in_addr addr; 00297 00298 //Assign it 00299 addr.S_un.S_addr=ulAddr; 00300 00301 //Enter the critical section 00302 CCriticalAutoRelease aRelease(m_pCSection); 00303 00304 //Return the value 00305 return inet_ntoa(addr); 00306 } 00307 ERROR_HANDLER_STATIC_RETURN(CSocketBase_Class,"LongToStdString","0.0.0.0") 00308 }
Definition at line 310 of file SocketBase.cpp. 00311 { 00312 try 00313 { 00314 //First create the address 00315 in_addr addr; 00316 00317 //Assign it 00318 addr.S_un.S_addr=ulAddr; 00319 00320 //Enter the critical section 00321 CCriticalAutoRelease aRelease(m_pCSection); 00322 00323 //Return the value 00324 return inet_ntoa(addr); 00325 } 00326 ERROR_HANDLER_STATIC_RETURN(CSocketBase_Class,"LongToString",NULL) 00327 }
Implemented in CWhoisSocket, and CSocketPoolSocket.
Implemented in CWhoisSocket, CSocketPoolSocket, and CUDPSocketAsync.
Definition at line 1049 of file AsyncSocket.cpp. 01050 { 01051 try 01052 { 01053 //Delete ourselves 01054 delete this; 01055 01056 //Do we have an event? 01057 if (pEvent) 01058 pEvent->Set(); 01059 } 01060 ERROR_HANDLER_STATIC(CAsyncSocket_Class,"OnSocketDelete") 01061 }
Implemented in CWhoisSocket.
Implemented in CWhoisSocket.
Definition at line 598 of file AsyncSocket.cpp. 00599 { 00600 if (!m_bBlocking) 00601 return TRUE; 00602 00603 try 00604 { 00605 //Quit if not ok 00606 if (!CheckAsyncSocketValid()) 00607 return FALSE; 00608 00609 //First disable the events 00610 int iResult; 00611 iResult=WSAAsyncSelect(GetAsyncHandle(), 00612 GetWindowHandle(), 00613 m_iMsg, 00614 m_lEvent); 00615 00616 if (iResult) 00617 { 00618 //Report it 00619 SetLastError("ReAsync"); 00620 00621 //Exit 00622 return FALSE; 00623 } 00624 00625 //Set to async 00626 m_bBlocking=FALSE; 00627 00628 //And quit 00629 return TRUE; 00630 } 00631 ERROR_HANDLER_RETURN("ReAsync",FALSE) 00632 }
Definition at line 517 of file AsyncSocket.cpp. 00518 { 00519 if (m_bBlocking) 00520 return TRUE; 00521 00522 try 00523 { 00524 //Quit if not ok 00525 if (!CheckAsyncSocketValid()) 00526 return FALSE; 00527 00528 if (Block()) 00529 //Set to reblock 00530 m_bBlocking=TRUE; 00531 00532 //And quit 00533 return TRUE; 00534 } 00535 ERROR_HANDLER_RETURN("ReBlock",FALSE) 00536 }
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 }
Definition at line 277 of file SocketBase.cpp. 00278 { 00279 try 00280 { 00281 //Check if we already have a class 00282 if (m_pShutdownClass) 00283 delete m_pShutdownClass; 00284 00285 //Take it 00286 m_pShutdownClass=pBase; 00287 } 00288 ERROR_HANDLER("RegisterShutdown") 00289 }
Definition at line 1220 of file AsyncSocket.cpp. 01225 { 01226 //Delegate the call 01227 return GetThreadManager()->RegisterTimeout(iMS, 01228 pProc, 01229 pData, 01230 bClearTimeout, 01231 GetWindowHandle(), 01232 pTimer); 01233 }
Definition at line 262 of file AsyncSocket.cpp. 00263 { 00264 try 00265 { 00266 if (m_bList) 00267 { 00268 //Remove from thread manager 00269 GetThreadManager()->RemoveSocket(this); 00270 00271 //Not in list 00272 m_bList=FALSE; 00273 00274 //Deallocate the handle 00275 DeAllocateHandle(); 00276 } 00277 } 00278 ERROR_HANDLER("RemoveSocketFromList") 00279 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
Definition at line 431 of file SocketBase.cpp. 00432 { 00433 try 00434 { 00435 //Resolve the DNS 00436 sockaddr_in aAddr; 00437 aAddr=InternalResolveDNS(rAddress.c_str()); 00438 00439 //Check if valid 00440 if (aAddr.sin_addr.S_un.S_addr==0) 00441 //Error 00442 return 0; 00443 else 00444 return aAddr.sin_addr.S_un.S_addr; 00445 } 00446 ERROR_HANDLER_STATIC_RETURN(CSocketBase_Class,"ResolveDNS",0) 00447 }
Reimplemented in CTCPSocketAsync. Definition at line 705 of file AsyncSocket.cpp. 00706 { 00707 //No implemented at this level 00708 return FALSE; 00709 }
Implemented in CTCPSocketAsync, and CUDPSocketAsync.
Definition at line 124 of file SocketBase.cpp. 00126 { 00127 try 00128 { 00129 //First set the error 00130 m_iLastError=iErrorCode; 00131 00132 //Check if there is an error 00133 if (m_iLastError) 00134 ReportError(rMethod, 00135 "Through SetLastError", 00136 m_iLastError); 00137 } 00138 ERROR_HANDLER("SetLastError") 00139 }
Definition at line 104 of file SocketBase.cpp. 00105 { 00106 try 00107 { 00108 #ifdef WIN32 00109 //First set the error 00110 m_iLastError=WSAGetLastError(); 00111 #else 00112 m_iLastError=errno(); 00113 #endif 00114 00115 //Check if there is an error 00116 if (m_iLastError) 00117 ReportError(rMethod, 00118 "Through SetLastError", 00119 m_iLastError); 00120 } 00121 ERROR_HANDLER("SetLastError") 00122 }
Definition at line 1235 of file AsyncSocket.cpp. 01236 { 01237 try 01238 { 01239 //We can do it only if we are not created 01240 if (GetAsyncHandle()!=INVALID_SOCKET) 01241 { 01242 //Report it 01243 ReportError("SetLocalThreadManager","Can't switch after socket is created!"); 01244 01245 //Exit 01246 return FALSE; 01247 } 01248 01249 //Is it a legal manager 01250 if (!pManager || 01251 !pManager->IsInitialized()) 01252 { 01253 //Report it 01254 ReportError("SetLocalThreadManager","Manager is either null or not initialized!"); 01255 01256 //Exit 01257 return FALSE; 01258 } 01259 01260 //Save the new manager 01261 m_pLocalThreadManager=pManager; 01262 01263 //Done 01264 return TRUE; 01265 } 01266 ERROR_HANDLER_RETURN("SetLocalThreadManager",FALSE) 01267 }
Definition at line 956 of file AsyncSocket.cpp. 00957 { 00958 try 00959 { 00960 //Do we have a timeout 00961 if (m_aTimerID.iTimerID) 00962 { 00963 //Report it 00964 ReportError("SetSystemTimeout","Please kill previous timer!"); 00965 00966 //Exit 00967 return FALSE; 00968 } 00969 00970 //Create the timer 00971 m_aTimerID=GetThreadManager()->RegisterTimeout(iMS, 00972 SystemTimerProc, 00973 this, 00974 TRUE, 00975 GetWindowHandle(), 00976 &m_aTimerID); 00977 00978 //Do we have it 00979 if (!m_aTimerID.iTimerID) 00980 { 00981 //Report it 00982 ReportError("SetSystemTimeout","Failed creating the timer!"); 00983 00984 //Exit 00985 return FALSE; 00986 } 00987 else 00988 return TRUE; 00989 } 00990 ERROR_HANDLER_RETURN("SetSystemTimeout",FALSE) 00991 }
Definition at line 281 of file AsyncSocket.cpp. 00282 { 00283 try 00284 { 00285 //Get the window handle 00286 HWND hWindowHandle; 00287 hWindowHandle=GetWindowHandle(); 00288 00289 if (!hWindowHandle) 00290 return FALSE; 00291 00292 //Set the timer 00293 m_bTimeout=SetTimer(hWindowHandle, 00294 GetAsyncHandle(), 00295 iMs, 00296 NULL); 00297 00298 return m_bTimeout; 00299 } 00300 ERROR_HANDLER_RETURN("SetTimeout",FALSE) 00301 }
Definition at line 332 of file AsyncSocket.cpp. 00333 { 00334 try 00335 { 00336 //Only if initialized 00337 if (!m_bInitialized) 00338 return; 00339 00340 //Indicate we're shutting down 00341 m_bShuttingDown=TRUE; 00342 00343 //Delete the thread manager 00344 if (m_pThreadManager) 00345 { 00346 delete m_pThreadManager; 00347 m_pThreadManager=NULL; 00348 } 00349 00350 //Not initialized anymore 00351 m_bInitialized=FALSE; 00352 } 00353 ERROR_HANDLER_STATIC(CAsyncSocket_Class,"Shutdown") 00354 }
Definition at line 231 of file SocketBase.cpp. 00232 { 00233 //Only if initialized 00234 if (!m_bInitialized) 00235 return TRUE; 00236 00237 try 00238 { 00239 //Delete the CS 00240 delete m_pCSection; 00241 m_pCSection=NULL; 00242 00243 //Delete the DNS CS 00244 delete m_pCSectionDNS; 00245 m_pCSectionDNS=NULL; 00246 00247 //Clear the DNS map 00248 m_aDNSMap.clear(); 00249 00250 //Notify shutdown class 00251 if (m_pShutdownClass) 00252 { 00253 //Notify we are shuting down 00254 m_pShutdownClass->NotifyShutdown(); 00255 00256 //Delete it 00257 delete m_pShutdownClass; 00258 m_pShutdownClass=NULL; 00259 } 00260 00261 //Not initialized anymore 00262 m_bInitialized=FALSE; 00263 00264 if (WSACleanup()==GetErrorCode()) 00265 return FALSE; 00266 00267 //Done 00268 return TRUE; 00269 } 00270 ERROR_HANDLER_STATIC_RETURN(CSocketBase_Class,"ShutdownSockets",FALSE) 00271 }
Definition at line 866 of file AsyncSocket.cpp. 00869 { 00870 try 00871 { 00872 //Check if we have the proc 00873 if (!pProc) 00874 { 00875 //Report it 00876 ReportStaticError(CAsyncSocket_Class,"SimpleMessageMap","Recieved null proc!"); 00877 00878 //Exit 00879 return; 00880 } 00881 00882 //If there is no message map, then receive won't work 00883 MSG msg; 00884 00885 //Set the message map to zeros 00886 memset(&msg, 00887 0, 00888 sizeof(msg)); 00889 00890 //Stop flag 00891 BOOL bStop; 00892 bStop=FALSE; 00893 00894 //Start the loop 00895 while (!bStop && 00896 (*pProc)()!=bStopWhenTRUE) 00897 { 00898 while (!(bStop=(*pProc)()==bStopWhenTRUE) && 00899 PeekMessage(&msg, 00900 NULL, 00901 0, 00902 0, 00903 PM_REMOVE)) 00904 { 00905 TranslateMessage(&msg); 00906 DispatchMessage(&msg); 00907 } 00908 00909 //Do we need to sleep? 00910 if (!bStop) 00911 //No messages 00912 Sleep(dwSleep); 00913 } 00914 } 00915 ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap") 00916 }
Definition at line 830 of file AsyncSocket.cpp. 00831 { 00832 try 00833 { 00834 //If there is no message map, then receive won't work 00835 MSG msg; 00836 00837 //Set the message map to zeros 00838 memset(&msg, 00839 0, 00840 sizeof(msg)); 00841 00842 //Start loop 00843 DWORD dwLoopStart; 00844 dwLoopStart=GetTickCount(); 00845 00846 //Until a key was hit 00847 while (GetTickCount()-dwLoopStart<dwRunTimeMS) 00848 { 00849 while (PeekMessage(&msg, 00850 NULL, 00851 0, 00852 0, 00853 PM_REMOVE)) 00854 { 00855 TranslateMessage(&msg); 00856 DispatchMessage(&msg); 00857 } 00858 00859 //Sleep so wont be hanged 00860 Sleep(1); 00861 } 00862 } 00863 ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap") 00864 }
Definition at line 805 of file AsyncSocket.cpp. 00806 { 00807 try 00808 { 00809 //If there is no message map, then receive won't work 00810 MSG msg; 00811 00812 //Set the message map to zeros 00813 memset(&msg, 00814 0, 00815 sizeof(msg)); 00816 00817 while (GetMessage(&msg, 00818 NULL, 00819 0, 00820 0)) 00821 { 00822 //Dispatch the message 00823 TranslateMessage(&msg); 00824 DispatchMessage(&msg); 00825 } 00826 } 00827 ERROR_HANDLER_STATIC(CAsyncSocket_Class,"SimpleMessageMap") 00828 }
Definition at line 918 of file AsyncSocket.cpp. 00919 { 00920 try 00921 { 00922 //If there is no message map, then receive won't work 00923 MSG msg; 00924 00925 //Set the message map to zeros 00926 memset(&msg, 00927 0, 00928 sizeof(msg)); 00929 00930 //Until a key was hit 00931 while (!kbhit()) 00932 { 00933 while (!kbhit() && 00934 PeekMessage(&msg, 00935 NULL, 00936 0, 00937 0, 00938 PM_REMOVE)) 00939 { 00940 TranslateMessage(&msg); 00941 DispatchMessage(&msg); 00942 } 00943 00944 //Do we need to sleep 00945 if (!kbhit()) 00946 //Sleep so wont be hanged 00947 Sleep(dwSleep); 00948 } 00949 00950 //Return the char 00951 return getch(); 00952 } 00953 ERROR_HANDLER_STATIC_RETURN(CAsyncSocket_Class,"SimpleMessageMapKey",0) 00954 }
Definition at line 758 of file AsyncSocket.cpp. 00760 { 00761 try 00762 { 00763 //Do we need to call event? 00764 if (!bNoEvent) 00765 return OnSocketAccept(iErrorCode); 00766 else 00767 return FALSE; 00768 } 00769 ERROR_HANDLER_RETURN("SocketConnected",FALSE) 00770 }
Definition at line 772 of file AsyncSocket.cpp. 00774 { 00775 try 00776 { 00777 //Kill the timer 00778 CAsyncSocket::SocketClosing(); 00779 00780 //Remove from socket list 00781 RemoveSocketFromList(); 00782 00783 //Call user data 00784 if (!bNoEvent) 00785 return OnSocketClose(iErrorCode); 00786 else 00787 return TRUE; 00788 } 00789 ERROR_HANDLER_RETURN("SocketClosed",FALSE) 00790 }
Definition at line 475 of file AsyncSocket.cpp. 00476 { 00477 try 00478 { 00479 //Are we valid 00480 if (m_bClosing || 00481 GetAsyncHandle()==INVALID_SOCKET) 00482 return; 00483 00484 //Indicate we are closing 00485 m_bClosing=TRUE; 00486 00487 //Signal the event 00488 m_pSendEvent->Set(); 00489 00490 //Do we have a regular timer 00491 if (m_bTimeout) 00492 KillTimer(); 00493 00494 //Do we have a system timer ? 00495 if (m_aTimerID.iTimerID) 00496 KillSystemTimer(); 00497 00498 //Kill all the messages 00499 m_iMsg=0; 00500 m_lEvent=0; 00501 00502 //Set it 00503 if (WSAAsyncSelect(GetAsyncHandle(), 00504 GetWindowHandle(), 00505 0, 00506 0)) 00507 SetLastError("SocketClosing"); 00508 } 00509 ERROR_HANDLER("SocketClosing") 00510 }
Reimplemented in CTCPSocketAsync. Definition at line 716 of file AsyncSocket.cpp. 00718 { 00719 try 00720 { 00721 //Did we have an error 00722 if (iErrorCode) 00723 if (!bNoEvent) 00724 return OnSocketConnect(iErrorCode); 00725 else 00726 return FALSE; 00727 00728 //Save the connect value 00729 BOOL bConnectValue; 00730 if (!bNoEvent) 00731 bConnectValue=OnSocketConnect(0); 00732 else 00733 bConnectValue=TRUE; 00734 00735 //Try to set it to async 00736 if (!SetAsync()) 00737 return FALSE; 00738 else 00739 return bConnectValue; 00740 } 00741 ERROR_HANDLER_RETURN("SocketConnected",FALSE) 00742 }
Definition at line 1174 of file AsyncSocket.cpp. 01175 { 01176 try 01177 { 01178 //No timer 01179 memset(&m_aTimerID, 01180 0, 01181 sizeof(m_aTimerID)); 01182 01183 //No delete timer 01184 memset(&m_aDeleteTimerID, 01185 0, 01186 sizeof(m_aDeleteTimerID)); 01187 01188 //Set values for new socket 01189 m_iSocketID=0; 01190 m_bBlocking=FALSE; 01191 m_bFreeze=FALSE; 01192 m_lEvent=0; 01193 m_hLocalWindowHandle=0; 01194 m_bList=FALSE; 01195 m_bClosing=FALSE; 01196 } 01197 ERROR_HANDLER("SocketCreated") 01198 }
Reimplemented in CTCPSocketAsync. Definition at line 744 of file AsyncSocket.cpp. 00746 { 00747 try 00748 { 00749 //Do we need to call event? 00750 if (!bNoEvent) 00751 return OnSocketReceive(iErrorCode); 00752 else 00753 return FALSE; 00754 } 00755 ERROR_HANDLER_RETURN("SocketConnected",FALSE) 00756 }
Definition at line 792 of file AsyncSocket.cpp. 00793 { 00794 try 00795 { 00796 //Notify the event 00797 m_pSendEvent->Set(); 00798 00799 //Call user data 00800 return OnSocketWrite(iErrorCode); 00801 } 00802 ERROR_HANDLER_RETURN("SocketWrite",FALSE) 00803 }
Definition at line 344 of file SocketBase.cpp. 00345 { 00346 //Try to convert it 00347 unsigned long ulAddress; 00348 ulAddress=inet_addr(rAddress.c_str()); 00349 00350 //Is it valid 00351 if (ulAddress!=INADDR_NONE) 00352 return ulAddress; 00353 else 00354 //Try to resolve it 00355 return ResolveDNS(rAddress); 00356 }
Definition at line 373 of file SocketBase.cpp. 00374 { 00375 try 00376 { 00377 return inet_addr(rAddress.c_str())!=INADDR_NONE; 00378 } 00379 ERROR_HANDLER_STATIC_RETURN(CSocketBase_Class,"ValidAddress",FALSE) 00380 }
Definition at line 1329 of file AsyncSocket.cpp. 01330 { 01331 //Wait for the event 01332 if (m_pSendEvent->Wait(5000)) 01333 return TRUE; 01334 else 01335 return IsClosing(); 01336 }
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 }
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 }
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 }
Member Data Documentation
Definition at line 122 of file SocketBase.h.
The documentation for this class was generated from the following files: |