NS_ADDREF(infoObject);  infoObject->SetHostName((char*)host); infoObject->SetHostPort(port); infoObject->SetProxyName((char*)proxyHost); infoObject->SetProxyPort(proxyPort);  layer->secret = (PRFilePrivate*) infoObject; rv = PR_PushIOLayer(sock, PR_GetLayersIdentity(sock), layer);  if (rv == PR_SUCCESS) { *fd   = sock; *info = infoObject; NS_ADDREF(*info); return NS_OK; }  PR_Close(sock); return NS_ERROR_FAILURE;
*fd   = sock; *info = infoObject; NS_ADDREF(*info); return NS_OK;
nsSSLIOLayerNewSocket( const char *host,                        PRInt32 port,                        const char *proxyHost,                        PRInt32 proxyPort,                       PRFileDesc **fd,                        nsISupports** info){    static PRBool  firstTime = PR_TRUE;    if (firstTime)    {        nsSSLIOLayerIdentity        = PR_GetUniqueIdentity("Cartman layer");        nsSSLIOLayerMethods         = *PR_GetDefaultIOMethods();        nsSSLIOLayerMethods.connect = nsSSLIOLayerConnect;        nsSSLIOLayerMethods.close   = nsSSLIOLayerClose;        nsSSLIOLayerMethods.read    = nsSSLIOLayerRead;        nsSSLIOLayerMethods.write   = nsSSLIOLayerWrite;                        nsresult result = nsServiceManager::GetService( PSM_COMPONENT_PROGID,                                                        NS_GET_IID(nsIPSMComponent),                                                         (nsISupports**)&gPSMService);          if (NS_FAILED(result))            return PR_FAILURE;            firstTime                   = PR_FALSE;    }        PRFileDesc *   sock;    PRFileDesc *   layer;    PRStatus       rv;    /* Get a normal NSPR socket */    sock = PR_NewTCPSocket();      if (! sock) return NS_ERROR_OUT_OF_MEMORY;        /* disable Nagle algorithm delay for control sockets */    PRSocketOptionData sockopt;    sockopt.option = PR_SockOpt_NoDelay;    sockopt.value.no_delay = PR_TRUE;       rv = PR_SetSocketOption(sock, &sockopt);    PR_ASSERT(PR_SUCCESS == rv);    layer = PR_CreateIOLayerStub(nsSSLIOLayerIdentity, &nsSSLIOLayerMethods);    if (! layer)    {        PR_Close(sock);        return NS_ERROR_FAILURE;    }            nsPSMSocketInfo *infoObject = new nsPSMSocketInfo();    if (!infoObject)    {        PR_Close(sock);        // clean up IOLayerStub.        return NS_ERROR_FAILURE;    }        NS_ADDREF(infoObject);        infoObject->SetHostName((char*)host);    infoObject->SetHostPort(port);    infoObject->SetProxyName((char*)proxyHost);    infoObject->SetProxyPort(proxyPort);    layer->secret = (PRFilePrivate*) infoObject;    rv = PR_PushIOLayer(sock, PR_GetLayersIdentity(sock), layer);        if (rv == PR_SUCCESS)    {        *fd   = sock;        *info = infoObject;        NS_ADDREF(*info);        return NS_OK;    }        PR_Close(sock);    return NS_ERROR_FAILURE;}