if (firstTime) { nsSOCKSIOLayerIdentity		= PR_GetUniqueIdentity("SOCKS layer"); nsSOCKSIOLayerMethods		= *PR_GetDefaultIOMethods();  nsSOCKSIOLayerMethods.connect	= nsSOCKSIOLayerConnect; nsSOCKSIOLayerMethods.bind	= nsSOCKSIOLayerBind; nsSOCKSIOLayerMethods.acceptread = nsSOCKSIOLayerAcceptRead; nsSOCKSIOLayerMethods.getsockname = nsSOCKSIOLayerGetName; nsSOCKSIOLayerMethods.getpeername = nsSOCKSIOLayerGetPeerName; nsSOCKSIOLayerMethods.accept	= nsSOCKSIOLayerAccept; nsSOCKSIOLayerMethods.listen	= nsSOCKSIOLayerListen; nsSOCKSIOLayerMethods.close	= nsSOCKSIOLayerClose;  firstTime			= false; }   PRFileDesc *	layer; PRStatus	rv;  layer = PR_CreateIOLayerStub(nsSOCKSIOLayerIdentity, &nsSOCKSIOLayerMethods); if (! layer) { return NS_ERROR_FAILURE; }  nsSOCKSSocketInfo *infoObject = new nsSOCKSSocketInfo(); if (!infoObject) {  return NS_ERROR_FAILURE; }  NS_ADDREF(infoObject); infoObject->SetProxyHost(proxyHost); infoObject->SetProxyPort(proxyPort); layer->secret = (PRFilePrivate*) infoObject; rv = PR_PushIOLayer(fd, PR_GetLayersIdentity(fd), layer);  if (rv == PR_SUCCESS) { *info 	= infoObject; NS_ADDREF(*info); return NS_OK; }  return NS_ERROR_FAILURE;
if (firstTime) { nsSOCKSIOLayerIdentity		= PR_GetUniqueIdentity("SOCKS layer"); nsSOCKSIOLayerMethods		= *PR_GetDefaultIOMethods();  nsSOCKSIOLayerMethods.connect	= nsSOCKSIOLayerConnect; nsSOCKSIOLayerMethods.bind	= nsSOCKSIOLayerBind; nsSOCKSIOLayerMethods.acceptread = nsSOCKSIOLayerAcceptRead; nsSOCKSIOLayerMethods.getsockname = nsSOCKSIOLayerGetName; nsSOCKSIOLayerMethods.getpeername = nsSOCKSIOLayerGetPeerName; nsSOCKSIOLayerMethods.accept	= nsSOCKSIOLayerAccept; nsSOCKSIOLayerMethods.listen	= nsSOCKSIOLayerListen; nsSOCKSIOLayerMethods.close	= nsSOCKSIOLayerClose;  firstTime			= false; }   PRFileDesc *	layer; PRStatus	rv;  layer = PR_CreateIOLayerStub(nsSOCKSIOLayerIdentity, &nsSOCKSIOLayerMethods); if (! layer) { return NS_ERROR_FAILURE; }  nsSOCKSSocketInfo * infoObject = new nsSOCKSSocketInfo(); if (!infoObject) {  PR_DELETE(layer); return NS_ERROR_FAILURE; }  NS_ADDREF(infoObject); infoObject->SetProxyHost(proxyHost); infoObject->SetProxyPort(proxyPort); layer->secret = (PRFilePrivate*) infoObject; rv = PR_PushIOLayer(fd, PR_GetLayersIdentity(fd), layer);  if (NS_FAILED(rv)) { NS_RELEASE(infoObject); PR_DELETE(layer); return NS_ERROR_FAILURE; }  *info = infoObject; NS_ADDREF(*info); return NS_OK;
nsSOCKSIOLayerAddToSocket(const char *host, 			  PRInt32 port,			  const char *proxyHost,			  PRInt32 proxyPort,			  PRFileDesc *fd, 			  nsISupports** info){   if (firstTime)     {	nsSOCKSIOLayerIdentity		= PR_GetUniqueIdentity("SOCKS layer");	nsSOCKSIOLayerMethods		= *PR_GetDefaultIOMethods();		nsSOCKSIOLayerMethods.connect	= nsSOCKSIOLayerConnect;	nsSOCKSIOLayerMethods.bind	= nsSOCKSIOLayerBind;	nsSOCKSIOLayerMethods.acceptread = nsSOCKSIOLayerAcceptRead;	nsSOCKSIOLayerMethods.getsockname = nsSOCKSIOLayerGetName;	nsSOCKSIOLayerMethods.getpeername = nsSOCKSIOLayerGetPeerName;	nsSOCKSIOLayerMethods.accept	= nsSOCKSIOLayerAccept;	nsSOCKSIOLayerMethods.listen	= nsSOCKSIOLayerListen;	nsSOCKSIOLayerMethods.close	= nsSOCKSIOLayerClose;		firstTime			= false;     }         PRFileDesc *	layer;   PRStatus	rv;      layer = PR_CreateIOLayerStub(nsSOCKSIOLayerIdentity, &nsSOCKSIOLayerMethods);   if (! layer)     {	return NS_ERROR_FAILURE;     }      nsSOCKSSocketInfo *infoObject = new nsSOCKSSocketInfo();   if (!infoObject)     {	// clean up IOLayerStub	return NS_ERROR_FAILURE;     }      NS_ADDREF(infoObject);   infoObject->SetProxyHost(proxyHost);   infoObject->SetProxyPort(proxyPort);   layer->secret = (PRFilePrivate*) infoObject;   rv = PR_PushIOLayer(fd, PR_GetLayersIdentity(fd), layer);      if (rv == PR_SUCCESS)     {	*info 	= infoObject;	NS_ADDREF(*info);	return NS_OK;     }   return NS_ERROR_FAILURE;}