![]() |
Connect() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Public Function |
Declared in: TCPSocketAsync.h |
virtual BOOL Connect( unsigned short usSourcePort, IP aDestinationAddress, unsigned short usDestinationPort, BOOL bDisableAsync=FALSE, BOOL bForceErrorEvent=FALSE);
Our async connection
try { //Quit if not ok if (!CheckSocketValid()) return FALSE; //Set the async notification if (!bDisableAsync) { int iResult; iResult=InternalWSAAsyncSelect(WM_SOCKET_CONNECT, FD_CONNECT); if (iResult) { //Get the error code int iErrorCode; iErrorCode=GetSystemLastError(); //Report it SetLastError("Connect"); //Do we need to call event? if (bForceErrorEvent) SocketConnected(iErrorCode); //Exit return FALSE; } //Set our timeout if (m_ulTimeout && !IsBlocking()) if (!SetSystemTimeout(m_ulTimeout)) { //Report it ReportError("Connect","Failed to set timer!"); //Do we need to call event? if (bForceErrorEvent) SocketConnected(GetErrorCode()); //Exit return FALSE; } } //Set to non blocking! else if (!Block()) return FALSE; //Set the flag m_bDisabledConnect=bDisableAsync; //Call the original connect BOOL bResult; bResult=CTCPSocket::Connect(usSourcePort, aDestinationAddress, usDestinationPort); //Reset the flag m_bDisabledConnect=FALSE; if (bResult) { //Call event, but only if in async if (!bDisableAsync && !IsBlocking()) //Call user, will add socket automatically return SocketConnected(0); else //Set as async return SetAsync(); } else if (GetSystemLastError()!=WSAEWOULDBLOCK || bDisableAsync || IsBlocking()) { if (m_ulTimeout) //Kill the timer KillSystemTimer(); //Get the error code int iErrorCode; iErrorCode=GetSystemLastError(); //Report it SetLastError("Connect"); //Do we need to call event? if (bForceErrorEvent && !bDisableAsync) SocketConnected(iErrorCode); //Exit return FALSE; } else return TRUE; } ERROR_HANDLER_RETURN("Connect",FALSE)
![]() |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |