CSocket Class Reference#include <Socket.h>
Inheritance diagram for CSocket:
![]()
Collaboration diagram for CSocket:
![]()
Detailed DescriptionDefinition at line 47 of file Socket.h. Member Typedef Documentation
Member Enumeration Documentation
Constructor & Destructor Documentation
Definition at line 54 of file Socket.cpp. 00054 : CSocketBase(), 00055 m_bRaw(bRawSocket) 00056 { 00057 try 00058 { 00059 //Set our name 00060 SetName(CSocket_LOGNAME); 00061 00062 //Initialize the data 00063 InitializeIP(); 00064 } 00065 ERROR_HANDLER("CSocket") 00066 }
Definition at line 88 of file Socket.cpp. 00089 { 00090 try 00091 { 00092 //Close the socket 00093 Close(); 00094 } 00095 ERROR_HANDLER("~CSocket") 00096 }
Definition at line 68 of file Socket.cpp. 00068 : CSocketBase() 00069 { 00070 //Check it's a valid socket 00071 if (aSocket!=INVALID_SOCKET) 00072 ReportError("CSocket","Received invalid socket!"); 00073 else 00074 try 00075 { 00076 //Set our name 00077 SetName(CSocket_LOGNAME); 00078 00079 //Initialize the data 00080 InitializeIP(); 00081 00082 //Save the handle 00083 AssignSocket(aSocket); 00084 } 00085 ERROR_HANDLER("CSocket") 00086 }
Member Function Documentation
Definition at line 500 of file Socket.cpp. 00502 { 00503 try 00504 { 00505 //Sets the protocol 00506 m_ucProtocol=ucProtocol; 00507 00508 //Binds to a socket 00509 m_aSocket=aNewSocket; 00510 } 00511 ERROR_HANDLER("AssignSocket") 00512 }
Reimplemented in CTCPSocketAsync. Definition at line 269 of file Socket.cpp. 00271 { 00272 try 00273 { 00274 //Quit if not ok 00275 if (!CheckSocketValid()) 00276 return FALSE; 00277 00278 //Create the local address 00279 sockaddr_in soSrc; 00280 00281 //Set to 0 00282 memset(&soSrc,0,sizeof(soSrc)); 00283 soSrc.sin_family=AF_INET; 00284 00285 //Populate the connection data 00286 if (aSourceAddress) 00287 soSrc.sin_addr.s_addr=aSourceAddress; 00288 else 00289 soSrc.sin_addr.s_addr=ADDR_ANY ; 00290 00291 soSrc.sin_port=htons(usPort); 00292 00293 //Now we need to bind it 00294 if (bind(GetHandle(), 00295 (sockaddr*)&soSrc, 00296 sizeof(soSrc))) 00297 { 00298 //Error 00299 SetLastError("Bind"); 00300 00301 //Exit 00302 return FALSE; 00303 } 00304 else 00305 //Save the address 00306 m_aConnectedTo=soSrc; 00307 00308 //Save new addresses 00309 if (aSourceAddress && 00310 !m_ulSourceAddress) 00311 m_ulSourceAddress=aSourceAddress; 00312 00313 return TRUE; 00314 } 00315 ERROR_HANDLER_RETURN("Bind",FALSE) 00316 }
Definition at line 318 of file Socket.cpp. 00320 { 00321 try 00322 { 00323 //Quit if not ok 00324 if (!CheckSocketValid()) 00325 return FALSE; 00326 00327 if (rSourceAddress.empty()) 00328 return Bind((IP)0, 00329 usPort); 00330 else 00331 return Bind(inet_addr(rSourceAddress.c_str()), 00332 usPort); 00333 } 00334 ERROR_HANDLER_RETURN("Bind",FALSE) 00335 }
Definition at line 721 of file Socket.cpp. 00722 { 00723 try 00724 { 00725 //Quit if not ok 00726 if (!CheckSocketValid()) 00727 return FALSE; 00728 00729 //Create our structure 00730 fd_set aDescriptor; 00731 FD_ZERO(&aDescriptor); 00732 00733 //Add our socket 00734 FD_SET(GetHandle(), 00735 &aDescriptor); 00736 00737 //And create the timeval 00738 timeval aTime; 00739 aTime.tv_sec=0; 00740 aTime.tv_usec=0; 00741 00742 //And run the select 00743 int iRetVal; 00744 iRetVal=select(NULL, 00745 &aDescriptor, 00746 NULL, 00747 NULL, 00748 &aTime); 00749 00750 //Check if we had an error 00751 if (iRetVal==GetErrorCode()) 00752 { 00753 //Report it 00754 SetLastError("CanRead"); 00755 00756 //Exit 00757 return FALSE; 00758 } 00759 else 00760 //Check is our socket set 00761 return FD_ISSET(GetHandle(), 00762 &aDescriptor); 00763 } 00764 ERROR_HANDLER_RETURN("CanRead",FALSE) 00765 }
Definition at line 767 of file Socket.cpp. 00768 { 00769 try 00770 { 00771 //Quit if not ok 00772 if (!CheckSocketValid()) 00773 return FALSE; 00774 00775 //Create our structure 00776 fd_set aDescriptor; 00777 FD_ZERO(&aDescriptor); 00778 00779 //Add our socket 00780 FD_SET(GetHandle(), 00781 &aDescriptor); 00782 00783 //And create the timeval 00784 timeval aTime; 00785 aTime.tv_sec=0; 00786 aTime.tv_usec=0; 00787 00788 //And run the select 00789 int iRetVal; 00790 iRetVal=select(NULL, 00791 NULL, 00792 &aDescriptor, 00793 NULL, 00794 &aTime); 00795 00796 //Check if we had an error 00797 if (iRetVal==GetErrorCode()) 00798 { 00799 //Report it 00800 SetLastError("CanWrite"); 00801 00802 //Exit 00803 return FALSE; 00804 } 00805 else 00806 //Check is our socket set 00807 return FD_ISSET(GetHandle(), 00808 &aDescriptor); 00809 } 00810 ERROR_HANDLER_RETURN("CanWrite",FALSE) 00811 }
Definition at line 387 of file Socket.cpp. 00388 { 00389 try 00390 { 00391 //Check if socket is invalid 00392 if (!ValidSocket()) 00393 { 00394 //Report it 00395 ReportError("CheckSocketValid","Operation made on non existant socket!"); 00396 00397 //Exit 00398 return FALSE; 00399 } 00400 00401 //OK 00402 return TRUE; 00403 } 00404 ERROR_HANDLER_RETURN("CheckSocketValid",FALSE) 00405 }
Definition at line 680 of file ErrorHandler.cpp. 00681 { 00682 //Delete the logs 00683 delete m_pSecondLevelLog; 00684 m_pSecondLevelLog=NULL; 00685 00686 delete m_pThirdLevelLog; 00687 m_pThirdLevelLog=NULL; 00688 }
Reimplemented in CTCPSocket, CTCPSocketAsync, and CUDPSocketAsync. Definition at line 407 of file Socket.cpp. 00408 { 00409 try 00410 { 00411 //Close the socket 00412 //Quit if not ok 00413 if (!ValidSocket()) 00414 return FALSE; 00415 00416 //Close it 00417 if (closesocket(GetHandle())==GetErrorCode()) 00418 { 00419 //Error in closing ? 00420 SetLastError("Close"); 00421 00422 //Exit 00423 return FALSE; 00424 } 00425 00426 //Set the socket to invalid 00427 m_aSocket=INVALID_SOCKET; 00428 00429 //Done 00430 return TRUE; 00431 } 00432 ERROR_HANDLER_RETURN("Close",FALSE) 00433 }
Definition at line 98 of file Socket.cpp. 00099 { 00100 //Close the socket if open 00101 if (ValidSocket()) 00102 Close(); 00103 00104 try 00105 { 00106 //Are we overlapped 00107 if (!m_bOverlapped) 00108 { 00109 //Here we create the raw socket 00110 if (m_bRaw || iProtocol==IPPROTO_ICMP) 00111 m_aSocket=socket(AF_INET, 00112 SOCK_RAW, 00113 iProtocol); 00114 else 00115 if (iProtocol==IPPROTO_TCP) 00116 m_aSocket=socket(AF_INET, 00117 SOCK_STREAM, 00118 iProtocol); 00119 else if (iProtocol==IPPROTO_UDP) 00120 m_aSocket=socket(AF_INET, 00121 SOCK_DGRAM, 00122 iProtocol); 00123 } 00124 else 00125 { 00126 //Here we create the raw socket 00127 if (m_bRaw || iProtocol==IPPROTO_ICMP) 00128 m_aSocket=WSASocket(AF_INET, 00129 SOCK_RAW, 00130 iProtocol, 00131 NULL, 00132 NULL, 00133 WSA_FLAG_OVERLAPPED); 00134 else 00135 if (iProtocol==IPPROTO_TCP) 00136 m_aSocket=WSASocket(AF_INET, 00137 SOCK_STREAM, 00138 iProtocol, 00139 NULL, 00140 NULL, 00141 WSA_FLAG_OVERLAPPED); 00142 else if (iProtocol==IPPROTO_UDP) 00143 m_aSocket=WSASocket(AF_INET, 00144 SOCK_DGRAM, 00145 iProtocol, 00146 NULL, 00147 NULL, 00148 WSA_FLAG_OVERLAPPED); 00149 } 00150 00151 //Check for socket validity 00152 if (m_aSocket==INVALID_SOCKET) 00153 { 00154 //Error 00155 SetLastError("Create"); 00156 00157 //Done 00158 return FALSE; 00159 } 00160 00161 if (m_bRaw) 00162 { 00163 //Set that the application will send the IP header 00164 unsigned int iTrue=1; 00165 00166 if(setsockopt(m_aSocket, 00167 IPPROTO_IP, 00168 IP_HDRINCL, 00169 (char*)&iTrue, 00170 sizeof(iTrue))==GetErrorCode()) 00171 { 00172 //Check for options error 00173 SetLastError("Create"); 00174 00175 //Exit 00176 return FALSE; 00177 } 00178 } 00179 00180 //Done 00181 return TRUE; 00182 } 00183 ERROR_HANDLER_RETURN("Create",FALSE) 00184 }
Reimplemented in CTCPSocketAsync. Definition at line 374 of file Socket.cpp. 00375 { 00376 //Save the socket 00377 SOCKET aTmp; 00378 aTmp=m_aSocket; 00379 00380 //Erase it 00381 m_aSocket=INVALID_SOCKET; 00382 00383 //Return the original 00384 return aTmp; 00385 }
Definition at line 251 of file ErrorHandler.cpp. 00252 { 00253 try 00254 { 00255 //Try to look it in the errors 00256 if (!CErrorsRepository::GetInstance().GetErrorsMap().empty()) 00257 { 00258 //Search 00259 CErrorsRepository::ErrorMap::const_iterator aIterator; 00260 aIterator=CErrorsRepository::GetInstance().GetErrorsMap().find(dwErrorCode); 00261 00262 //Do we have it 00263 if (aIterator!=CErrorsRepository::GetInstance().GetErrorsMap().end()) 00264 return aIterator->second; 00265 } 00266 00267 //Get the error string 00268 LPVOID lpMsgBuf; 00269 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 00270 FORMAT_MESSAGE_FROM_SYSTEM | 00271 FORMAT_MESSAGE_IGNORE_INSERTS, 00272 NULL, 00273 dwErrorCode, 00274 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 00275 (LPTSTR) &lpMsgBuf, 00276 0, 00277 NULL); 00278 00279 //Save it 00280 std::string sMessage; 00281 00282 //Do we have the message? 00283 if (lpMsgBuf) 00284 { 00285 //Save it 00286 sMessage=(char*)lpMsgBuf; 00287 00288 //Release the buffer 00289 LocalFree(lpMsgBuf); 00290 } 00291 else 00292 //Failed to find 00293 sMessage="No error description found!"; 00294 00295 //Done 00296 return sMessage; 00297 } 00298 catch (...) 00299 { 00300 return "Unknown"; 00301 } 00302 }
Definition at line 145 of file ErrorHandler.cpp. 00149 { 00150 //Our message 00151 std::string sMsg; 00152 00153 //Is it an error? 00154 if (bError) 00155 sMsg="*** Error *** "; 00156 else 00157 sMsg="### Msg ### "; 00158 00159 //Add the data now 00160 sMsg+="in "+rClass; 00161 sMsg+="::"+rMethod; 00162 sMsg+=" - " + rMsgOrError; 00163 00164 //Done 00165 return sMsg; 00166 }
Reimplemented in CTCPSocketAsync. Definition at line 337 of file Socket.cpp. 00338 { 00339 try 00340 { 00341 //Quit if not ok 00342 if (!CheckSocketValid()) 00343 return FALSE; 00344 00345 //Create the local address 00346 sockaddr_in soSrc; 00347 00348 //Buffer size 00349 int iSize; 00350 iSize=sizeof(soSrc); 00351 00352 //Try to get it 00353 if (getsockname(GetHandle(), 00354 (sockaddr*)&soSrc, 00355 &iSize)) 00356 { 00357 //Error 00358 SetLastError("Bind"); 00359 00360 //Exit 00361 return 0; 00362 } 00363 else 00364 return htons(soSrc.sin_port); 00365 } 00366 ERROR_HANDLER_RETURN("GetBindPort",0) 00367 }
Definition at line 622 of file ErrorHandler.cpp. 00623 { 00624 try 00625 { 00626 //Our string 00627 std::string sDate; 00628 00629 //Our tmp buf 00630 char cTmp[128]; 00631 00632 //Get date 00633 _strdate(cTmp); 00634 sDate=cTmp; 00635 sDate+=' '; 00636 00637 //Get time 00638 _strtime(cTmp); 00639 sDate+=cTmp; 00640 00641 //Done 00642 return sDate; 00643 } 00644 ERROR_HANDLER_STATIC_RETURN(CErrorHandler_Class,"GetCurrentDateTime","") 00645 }
Definition at line 677 of file Socket.cpp. 00678 { 00679 //Get the address we are connected to 00680 return m_aConnectedTo.sin_addr.S_un.S_addr; 00681 }
Definition at line 658 of file ErrorHandler.cpp. 00659 { 00660 //Do we have log 00661 if (!m_pSecondLevelLog) 00662 //Create it 00663 m_pSecondLevelLog=new CErrorHandler; 00664 00665 //Return it 00666 return m_pSecondLevelLog; 00667 }
Definition at line 669 of file ErrorHandler.cpp. 00670 { 00671 //Do we have log 00672 if (!m_pThirdLevelLog) 00673 //Create it 00674 m_pThirdLevelLog=new CErrorHandler; 00675 00676 //Return it 00677 return m_pThirdLevelLog; 00678 }
Definition at line 476 of file Socket.cpp. 00477 { 00478 try 00479 { 00480 //Invalid the socket 00481 m_aSocket=INVALID_SOCKET; 00482 00483 //More invalids 00484 m_ulSourceAddress=0; 00485 00486 //Some defaults 00487 m_ucTTL=64; 00488 00489 //We are not overlapped 00490 m_bOverlapped=FALSE; 00491 00492 //Not connected 00493 memset(&m_aConnectedTo, 00494 0, 00495 sizeof(m_aConnectedTo)); 00496 } 00497 ERROR_HANDLER("InitializeIP") 00498 }
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 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 }
Definition at line 892 of file Socket.cpp. 00893 { 00894 return m_aSocket<rSocket.m_aSocket; 00895 }
Definition at line 887 of file Socket.cpp. 00888 { 00889 return m_aSocket==rSocket.m_aSocket; 00890 }
Reimplemented in CTCPSocketAsyncSSL, and CTCPSocketAsync. Definition at line 665 of file Socket.cpp. 00667 { 00668 try 00669 { 00670 return LocalReceive(pBuffer, 00671 ulBufferLength, 00672 TRUE); 00673 } 00674 ERROR_HANDLER_RETURN("Peek",GetErrorCode()) 00675 }
Reimplemented in CTCPSocketAsyncSSL, CTCPSocketAsync, and CUDPSocket. Definition at line 653 of file Socket.cpp. 00655 { 00656 try 00657 { 00658 return LocalReceive(pBuffer, 00659 ulBufferLength, 00660 FALSE); 00661 } 00662 ERROR_HANDLER_RETURN("Receive",GetErrorCode()) 00663 }
Definition at line 514 of file Socket.cpp. 00518 { 00519 try 00520 { 00521 if (!ValidSocket() || 00522 !pBuffer || 00523 !ulBufferLength) 00524 return GetErrorCode(); 00525 00526 //Receive data 00527 int iResult; 00528 00529 //Receive 00530 if (m_ucProtocol!=IPPROTO_TCP) 00531 { 00532 //Get the remote address 00533 sockaddr saConnected; 00534 00535 int iTmp; 00536 iTmp=sizeof(saConnected); 00537 00538 //Accept it 00539 iResult=recvfrom(GetHandle(), 00540 pBuffer, 00541 ulBufferLength, 00542 NULL, 00543 &saConnected, 00544 &iTmp); 00545 00546 //If OK set it 00547 if (iResult!=GetErrorCode()) 00548 { 00549 //Address 00550 rIP=((sockaddr_in*)&saConnected)->sin_addr.S_un.S_addr; 00551 00552 //Port 00553 rSourcePort=htons(((sockaddr_in*)&saConnected)->sin_port); 00554 00555 //Done 00556 return iResult; 00557 } 00558 else 00559 { 00560 //Error 00561 SetLastError("Receive"); 00562 00563 //Reset the data 00564 rIP=0; 00565 rSourcePort=0; 00566 00567 //Done 00568 return iResult; 00569 } 00570 } 00571 else 00572 { 00573 //Report it 00574 ReportError("Receive","Can't run on TCP socket!"); 00575 00576 //Exit 00577 return GetErrorCode(); 00578 } 00579 } 00580 ERROR_HANDLER_RETURN("Receive",GetErrorCode()) 00581 }
Definition at line 647 of file ErrorHandler.cpp. 00649 { 00650 try 00651 { 00652 //Add the error 00653 CErrorsRepository::GetInstance().GetErrorsMap().insert(CErrorsRepository::ErrorMap::value_type(dwErrorCode,rDescription)); 00654 } 00655 ERROR_HANDLER_STATIC(CErrorHandler_Class,"RegisterError") 00656 }
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 304 of file ErrorHandler.cpp. 00307 { 00308 if (!GetLog()) 00309 return; 00310 00311 try 00312 { 00313 //Convert the error code 00314 char aTmp[11]; 00315 sprintf(aTmp,"%d",iErrorCode); 00316 00317 //Get the string for it 00318 std::string sError; 00319 sError=rMessage; 00320 sError+=", and Socket error: "; 00321 sError+=aTmp; 00322 sError+=", "; 00323 sError+=ErrorCodeToString(iErrorCode); 00324 00325 //Report to the log 00326 WriteError(m_sClassName, 00327 rMethod, 00328 sError); 00329 } 00330 ERROR_UNKNOWN("ReportError") 00331 }
Definition at line 333 of file ErrorHandler.cpp. 00335 { 00336 if (!GetLog()) 00337 return; 00338 00339 try 00340 { 00341 //Convert the error code 00342 char aTmp[11]; 00343 sprintf(aTmp,"%d",iErrorCode); 00344 00345 //Get the string for it 00346 std::string sError; 00347 sError="Socket error: "; 00348 sError+=aTmp; 00349 sError+=", "; 00350 sError+=ErrorCodeToString(iErrorCode); 00351 00352 //Report to the log 00353 WriteError(m_sClassName, 00354 rMethod, 00355 sError); 00356 } 00357 ERROR_UNKNOWN("ReportError") 00358 }
Definition at line 461 of file ErrorHandler.cpp. 00464 { 00465 if (!GetLog()) 00466 return; 00467 00468 try 00469 { 00470 //Create the new message 00471 std::string sNewMessage(rMessage); 00472 sNewMessage+=", Additional data: "; 00473 sNewMessage+=rAdditionalData; 00474 00475 //Report to the log 00476 WriteError(m_sClassName, 00477 rMethod, 00478 sNewMessage); 00479 } 00480 ERROR_UNKNOWN("ReportError") 00481 }
Definition at line 483 of file ErrorHandler.cpp. 00486 { 00487 if (!GetLog()) 00488 return; 00489 00490 try 00491 { 00492 //Convert the number 00493 char aTmp[11]; 00494 ltoa(dwAdditionalData,aTmp,10); 00495 00496 //Create the new message 00497 std::string sNewMessage(rMessage); 00498 sNewMessage+=", Additional data: "; 00499 sNewMessage+=aTmp; 00500 00501 //Report to the log 00502 WriteError(m_sClassName, 00503 rMethod, 00504 sNewMessage); 00505 } 00506 ERROR_UNKNOWN("ReportError") 00507 }
Definition at line 376 of file ErrorHandler.cpp. 00378 { 00379 if (!GetLog()) 00380 return; 00381 00382 try 00383 { 00384 //Report to the log 00385 WriteError(m_sClassName, 00386 rMethod, 00387 rMessage); 00388 } 00389 ERROR_UNKNOWN("ReportError") 00390 }
Definition at line 515 of file ErrorHandler.cpp. 00516 { 00517 if (!GetLog()) 00518 return; 00519 00520 try 00521 { 00522 //Get the last error 00523 DWORD dwLastError; 00524 dwLastError=GetLastError(); 00525 00526 //Report the error 00527 WriteError(m_sClassName, 00528 rMethod, 00529 ErrorCodeToString(dwLastError)); 00530 } 00531 ERROR_UNKNOWN("ReportError") 00532 }
Definition at line 427 of file ErrorHandler.cpp. 00429 { 00430 if (!GetLog()) 00431 return; 00432 00433 try 00434 { 00435 //Get the last error 00436 DWORD dwLastError; 00437 dwLastError=GetLastError(); 00438 00439 //Format the message 00440 std::string sMessage; 00441 sMessage=rMessage; 00442 sMessage+=", with error code: "; 00443 00444 //Convert the error code 00445 char aTmp[11]; 00446 itoa(dwLastError,aTmp,10); 00447 00448 //Add it again 00449 sMessage+=aTmp; 00450 sMessage+=" "; 00451 sMessage+=ErrorCodeToString(dwLastError); 00452 00453 //Report to the log 00454 WriteError(m_sClassName, 00455 rMethod, 00456 sMessage); 00457 } 00458 ERROR_UNKNOWN("ReportErrorOS") 00459 }
Definition at line 590 of file ErrorHandler.cpp. 00594 { 00595 if (!m_pLog) 00596 return; 00597 00598 try 00599 { 00600 //Convert the number 00601 char aTmp[11]; 00602 ltoa(dwAdditionalData,aTmp,10); 00603 00604 //Create the new message 00605 std::string sNewMessage(rMessage); 00606 sNewMessage+=", Additional data: "; 00607 sNewMessage+=aTmp; 00608 00609 //Report to the log 00610 WriteStaticError(rClass, 00611 rMethod, 00612 sNewMessage); 00613 } 00614 ERROR_UNKNOWN("ReportStaticError") 00615 }
Definition at line 573 of file ErrorHandler.cpp. 00576 { 00577 if (!m_pLog) 00578 return; 00579 00580 try 00581 { 00582 //Report to the log 00583 WriteStaticError(rClass, 00584 rMethod, 00585 rMessage); 00586 } 00587 ERROR_UNKNOWN("ReportStaticError") 00588 }
Definition at line 553 of file ErrorHandler.cpp. 00555 { 00556 if (!m_pLog) 00557 return; 00558 00559 try 00560 { 00561 //Get the last error 00562 DWORD dwLastError; 00563 dwLastError=GetLastError(); 00564 00565 //Report the error 00566 WriteStaticError(rClass, 00567 rMethod, 00568 ErrorCodeToString(dwLastError)); 00569 } 00570 ERROR_UNKNOWN("ReportStaticError") 00571 }
Definition at line 392 of file ErrorHandler.cpp. 00395 { 00396 if (!m_pLog) 00397 return; 00398 00399 try 00400 { 00401 //Get the last error 00402 DWORD dwLastError; 00403 dwLastError=GetLastError(); 00404 00405 //Format the message 00406 std::string sMessage; 00407 sMessage=rMessage; 00408 sMessage+=", with error code: "; 00409 00410 //Convert the error code 00411 char aTmp[11]; 00412 itoa(dwLastError,aTmp,10); 00413 00414 //Add it again 00415 sMessage+=aTmp; 00416 sMessage+=" "; 00417 sMessage+=ErrorCodeToString(dwLastError); 00418 00419 //Report to the log 00420 WriteStaticError(rClass, 00421 rMethod, 00422 sMessage); 00423 } 00424 ERROR_UNKNOWN("ReportStaticError") 00425 }
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 }
Definition at line 245 of file Socket.cpp. 00249 { 00250 try 00251 { 00252 //Quit if not ok 00253 if (!CheckSocketValid()) 00254 return GetErrorCode(); 00255 00256 return Send(inet_addr(rDestinationAddress.c_str()), 00257 pBuffer, 00258 ulBufferLength, 00259 usDestinationPort); 00260 } 00261 ERROR_HANDLER_RETURN("Send",GetErrorCode()) 00262 }
Definition at line 191 of file Socket.cpp. 00195 { 00196 try 00197 { 00198 //Quit if not ok 00199 if (!CheckSocketValid()) 00200 return GetErrorCode(); 00201 00202 //Is it a valid size 00203 if (ulBufferLength && 00204 !pBuffer) 00205 return GetErrorCode(); 00206 00207 //Define the target address 00208 sockaddr_in aTargetAddress; 00209 memset(&aTargetAddress, 00210 0, 00211 sizeof(aTargetAddress)); 00212 00213 aTargetAddress.sin_family=AF_INET; 00214 aTargetAddress.sin_addr.s_addr=aDestinationAddress; 00215 aTargetAddress.sin_port=htons(usDestinationPort); 00216 00217 //packet send status ? 00218 int iResult; 00219 00220 //Set to no error 00221 iResult=!GetErrorCode(); 00222 00223 //Check if we had an error 00224 if (iResult!=GetErrorCode()) 00225 //Use regular send !!! 00226 iResult=sendto(GetHandle(), 00227 (const char*)pBuffer, 00228 ulBufferLength, 00229 0, 00230 (sockaddr*)&aTargetAddress, 00231 sizeof(aTargetAddress)); 00232 00233 //Is all OK? 00234 if (iResult==GetErrorCode() && 00235 GetSystemLastError()!=WSAEWOULDBLOCK) 00236 //Set the error 00237 SetLastError("Send"); 00238 00239 //Done 00240 return iResult; 00241 } 00242 ERROR_HANDLER_RETURN("Send",GetErrorCode()) 00243 }
Definition at line 818 of file Socket.cpp. 00819 { 00820 try 00821 { 00822 //Quit if not ok 00823 if (!CheckSocketValid()) 00824 return FALSE; 00825 00826 //Set broadcast option 00827 if(setsockopt(GetHandle(), 00828 SOL_SOCKET, 00829 SO_BROADCAST, 00830 (char*)&bBroadcast, 00831 sizeof(bBroadcast))==GetErrorCode()) 00832 { 00833 //Check for options error 00834 SetLastError("SetBroadcast"); 00835 00836 //Exit 00837 return FALSE; 00838 } 00839 00840 return TRUE; 00841 } 00842 ERROR_HANDLER_RETURN("SetBroadcast",FALSE) 00843 }
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 543 of file ErrorHandler.cpp. 00545 { 00546 //Save the log 00547 m_pLocalLog=pLog; 00548 00549 //Save the write to main flag 00550 m_bWriteToMain=bWriteToMain; 00551 }
Definition at line 860 of file Socket.cpp. 00861 { 00862 try 00863 { 00864 //Quit if not ok 00865 if (!CheckSocketValid()) 00866 return FALSE; 00867 00868 //Set it 00869 if(setsockopt(GetHandle(), 00870 SOL_SOCKET, 00871 SO_RCVTIMEO, 00872 (char*)&ulMS, 00873 sizeof(ulMS))==GetErrorCode()) 00874 { 00875 //Check for options error 00876 SetLastError("SetReceiveTimeout"); 00877 00878 //Exit 00879 return FALSE; 00880 } 00881 else 00882 return TRUE; 00883 } 00884 ERROR_HANDLER_RETURN("SetReceiveTimeout",FALSE) 00885 }
Definition at line 440 of file Socket.cpp. 00441 { 00442 try 00443 { 00444 //Set the source address, in case we want to spoof it 00445 if (rSourceAddress.empty()) 00446 m_ulSourceAddress=0; 00447 else 00448 m_ulSourceAddress=inet_addr(rSourceAddress.c_str()); 00449 } 00450 ERROR_HANDLER("SetSourceAddress") 00451 }
Definition at line 453 of file Socket.cpp. 00454 { 00455 try 00456 { 00457 //Quit if not ok 00458 if (!CheckSocketValid()) 00459 return; 00460 00461 if(setsockopt(GetHandle(), 00462 IPPROTO_IP, 00463 IP_TTL, 00464 (const char*)&ucTTL, 00465 sizeof(ucTTL))) 00466 SetLastError("SetTTL"); 00467 } 00468 ERROR_HANDLER("SetTTL") 00469 }
Definition at line 683 of file Socket.cpp. 00684 { 00685 if (!CheckSocketValid()) 00686 return FALSE; 00687 00688 try 00689 { 00690 int iHow; 00691 00692 //Convert the how to a real flag 00693 if (eHow==ssReceive) 00694 iHow=SD_RECEIVE; 00695 else if (eHow==ssSend) 00696 iHow=SD_SEND; 00697 else 00698 iHow=SD_BOTH; 00699 00700 //Do it 00701 if (shutdown(GetHandle(),iHow)) 00702 { 00703 //Report it 00704 SetLastError("Shutdown"); 00705 00706 //Exit 00707 return FALSE; 00708 } 00709 00710 //Done 00711 return TRUE; 00712 } 00713 ERROR_HANDLER_RETURN("Shutdown",FALSE) 00714 }
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 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 168 of file ErrorHandler.cpp. 00171 { 00172 //Do we have a log? 00173 if (!GetLog()) 00174 return; 00175 00176 //Format the msg 00177 std::string sError; 00178 sError=FormatData(rClass, 00179 rMethod, 00180 rError); 00181 00182 //Write it 00183 GetLog()->WriteError(sError); 00184 00185 //Write to main 00186 if (m_bWriteToMain && 00187 m_pLog) 00188 //Write it 00189 m_pLog->WriteError(sError); 00190 }
Definition at line 360 of file ErrorHandler.cpp. 00362 { 00363 if (!GetLog()) 00364 return; 00365 00366 try 00367 { 00368 //Report to the log 00369 WriteMessage(m_sClassName, 00370 rMethod, 00371 rMessage); 00372 } 00373 ERROR_UNKNOWN("WriteMessage") 00374 }
Definition at line 226 of file ErrorHandler.cpp. 00229 { 00230 //Do we have a log? 00231 if (!GetLog()) 00232 return; 00233 00234 //Format the msg 00235 std::string sMsg; 00236 sMsg=FormatData(rClass, 00237 rMethod, 00238 rMessage, 00239 false); 00240 00241 //Write it 00242 GetLog()->WriteMessage(sMsg); 00243 00244 //Write to main 00245 if (m_bWriteToMain && 00246 m_pLog) 00247 //Write it 00248 m_pLog->WriteMessage(sMsg); 00249 }
Definition at line 192 of file ErrorHandler.cpp. 00195 { 00196 //Do we have a log? 00197 if (!m_pLog) 00198 return; 00199 00200 //Format the msg 00201 std::string sError; 00202 sError=FormatData(rClass, 00203 rMethod, 00204 rError); 00205 00206 //Write it 00207 m_pLog->WriteError(sError); 00208 }
Definition at line 210 of file ErrorHandler.cpp. 00213 { 00214 //Do we have a log? 00215 if (!m_pLog) 00216 return; 00217 00218 //Format the msg 00219 std::string sMsg; 00220 sMsg=FormatData(rClass, 00221 rMethod, 00222 rMessage, 00223 false); 00224 }
Friends And Related Function Documentation
Member Data Documentation
Definition at line 122 of file SocketBase.h.
The documentation for this class was generated from the following files: |