Class CTCPSocketAsync::
Connect()
Base ClassesData ItemsConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: ConnectNext page: Connect    Show member index
Public Function Declared in:
TCPSocketAsync.h

'Declaration' icon -- Shortcut to top of page. Declaration

virtual BOOL Connect(
    unsigned short usSourcePort,
    IP aDestinationAddress,
    unsigned short usDestinationPort,
    BOOL bDisableAsync=FALSE,
    BOOL bForceErrorEvent=FALSE);

'Description' icon -- Shortcut to top of page. Description

Our async connection

'Function Body' icon -- Shortcut to top of page. Function Body

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)

'See Also' icon -- Shortcut to top of page. See Also

Class Overview Class Overview  |  Public base class CTCPSocket  |  Public base class CAsyncSocket  |  Hierarchy Chart Hierarchy Chart


Get Surveyor!This web site was generated using Surveyor V4.50.811.1.  Click here for more information. Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003.