err = OTInstallNotifier((ProviderRef) newosfd, RawEndpointNotifierRoutine, endthr);
err = OTInstallNotifier((ProviderRef) newosfd, RawEndpointNotifierRoutineUPP, endthr);
PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout){    OSStatus err;    EndpointRef endpoint = (EndpointRef) fd->secret->md.osfd;    PRThread *me = _PR_MD_CURRENT_THREAD();    TBind bindReq;    PRNetAddr bindAddr;    PRInt32 newosfd = -1;    TCall call;    PRNetAddr callAddr;    RawEndpointAndThread *endthr = NULL;    if (endpoint == NULL) {        err = kEBADFErr;        goto ErrorExit;    }            memset(&call, 0 , sizeof(call));    if (addr != NULL) {        call.addr.maxlen = *addrlen;        call.addr.len = *addrlen;        call.addr.buf = (UInt8*) addr;    } else {        call.addr.maxlen = sizeof(callAddr);        call.addr.len = sizeof(callAddr);        call.addr.buf = (UInt8*) &callAddr;    }	do {	    PrepareForAsyncCompletion(me, fd->secret->md.osfd);	    fd->secret->md.misc.thread = me;	    	    // Perform the listen. 	    err = OTListen (endpoint, &call);	    if (err == kOTNoError)	    	break; // got the call information	    else if ((!fd->secret->nonblocking) && (err == kOTNoDataErr)) {	        WaitOnThisThread(me, timeout);	        err = me->md.osErrCode;	        if ((err != kOTNoError) && (err != kOTNoDataErr))	        	goto ErrorExit;			// we can get kOTNoError here, but still need			// to loop back to call OTListen, in order			// to get call info for OTAccept	    } else {	    	goto ErrorExit; // we're nonblocking, and/or we got an error	    }   	}	while(1);    newosfd = _MD_socket(AF_INET, SOCK_STREAM, 0);    if (newosfd == -1)        return -1;            	// Attach the raw endpoint handler to this endpoint for now.	endthr = (RawEndpointAndThread *) PR_Malloc(sizeof(RawEndpointAndThread));	endthr->thread = me;	endthr->endpoint = (EndpointRef) newosfd;		err = OTInstallNotifier((ProviderRef) newosfd, RawEndpointNotifierRoutine, endthr);    PR_ASSERT(err == kOTNoError);    	err = OTSetAsynchronous((EndpointRef) newosfd);	PR_ASSERT(err == kOTNoError);    // Bind to a local port; let the system assign it.    bindAddr.inet.family = AF_INET;    bindAddr.inet.port = bindAddr.inet.ip = 0;    bindReq.addr.maxlen = PR_NETADDR_SIZE (&bindAddr);    bindReq.addr.len = 0;    bindReq.addr.buf = (UInt8*) &bindAddr;    bindReq.qlen = 0;    PrepareForAsyncCompletion(me, newosfd);        err = OTBind((EndpointRef) newosfd, &bindReq, NULL);    if (err != kOTNoError)        goto ErrorExit;    WaitOnThisThread(me, timeout);    err = me->md.osErrCode;    if (err != kOTNoError)        goto ErrorExit;    PrepareForAsyncCompletion(me, newosfd);        err = OTAccept (endpoint, (EndpointRef) newosfd, &call); 	if ((err != kOTNoError) && (err != kOTNoDataErr))        goto ErrorExit;    WaitOnThisThread(me, timeout);    err = me->md.osErrCode;    if (err != kOTNoError)        goto ErrorExit;    if (addrlen != NULL)        *addrlen = call.addr.len;	// Remove the temporary notifier we installed to set up the new endpoint.	OTRemoveNotifier((EndpointRef) newosfd);	PR_Free(endthr); // free the temporary context we set up for this endpoint    return newosfd;ErrorExit:	me->io_pending = PR_FALSE; // clear pending wait state if any    if (newosfd != -1)        _MD_closesocket(newosfd);    macsock_map_error(err);    return -1;}