{ rv=PR_FAILURE; goto fail; } }  result = psm->GetControlConnection(&secret->control);  if (result != PR_SUCCESS) { rv = PR_FAILURE; goto fail;
return PR_FAILURE;
nsSSLIOLayerConnect(PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout){    nsSSLIOLayerSecretData *secret;    nsresult                result;    PRStatus                rv = PR_SUCCESS;    CMTStatus               status;    const char*             hostName;    /* Set the error in case of failure. */    PR_SetError(PR_UNKNOWN_ERROR, status);    if (!fd || !addr)        return PR_FAILURE;    secret = (nsSSLIOLayerSecretData *)PR_Malloc(sizeof(nsSSLIOLayerSecretData));    if (!secret) return PR_FAILURE;    memset(secret, 0, sizeof(nsSSLIOLayerSecretData));        /* TODO: this should be allocated from cmshim layer */    secret->cmsock = (CMSocket *)PR_Malloc(sizeof(CMSocket));    if (!secret->cmsock)    {        PR_Free(secret);        return PR_FAILURE;    }       memset(secret->cmsock, 0, sizeof(CMSocket));    if (psm == nsnull)    {        result = nsServiceManager::GetService( PSM_COMPONENT_PROGID,                                               NS_GET_IID(nsIPSMComponent),                                                (nsISupports**)&psm);        if (NS_FAILED(result))        {            rv=PR_FAILURE;            goto fail;        }    }       result = psm->GetControlConnection(&secret->control);    if (result != PR_SUCCESS)    {        rv = PR_FAILURE;        goto fail;    }        secret->cmsock->fd        = fd->lower;    secret->cmsock->isUnix    = PR_FALSE;        /* TODO: XXX fix this RSN */    {        PRSocketOptionData opt;        // Make the socket non-blocking...        opt.option = PR_SockOpt_Nonblocking;        opt.value.non_blocking = PR_FALSE;        rv = PR_SetSocketOption(fd->lower, &opt);        if (PR_SUCCESS != rv)         {            goto fail;        }    }    char ipBuffer[PR_NETDB_BUF_SIZE];    rv = PR_NetAddrToString(addr, (char*)&ipBuffer, PR_NETDB_BUF_SIZE);    if (rv != PR_SUCCESS)    {        goto fail;    }    if (addr->raw.family == PR_AF_INET6 && PR_IsNetAddrType(addr, PR_IpAddrV4Mapped)) {      /* Chop off the leading "::ffff:" */      strcpy(ipBuffer, ipBuffer + 7);    }    if (fd->secret)  // how do we know that this is a necko nsSocketTransportFDPrivate??    {        hostName = (const char*)fd->secret;    }    else    {        // no hostname, use ip address.        hostName = ipBuffer;    }        fd->secret = (PRFilePrivate *)secret;    status = CMT_OpenSSLConnection(secret->control,                                   secret->cmsock,                                   SSM_REQUEST_SSL_DATA_SSL,                                   PR_ntohs(addr->inet.port),                                   ipBuffer,                                   (char*)hostName,                                   CM_TRUE,                                    nsnull);    if (CMTSuccess == status)    {        // since our stuff can block, what we want to do is return PR_FAILURE,        // but set the nspr ERROR to BLOCK.  This will put us into a select        // q.        PR_SetError(PR_WOULD_BLOCK_ERROR, status);        return PR_FAILURE;    }fail:    fd->secret = nsnull;    PR_FREEIF(secret->cmsock)        secret->cmsock = nsnull;    PR_FREEIF(secret);        secret = nsnull;    return rv;}