if (result != kOTNoDataErr)
if (err != kOTNoDataErr)
static PRInt32 SendReceiveDgram(PRFileDesc *fd, void *buf, PRInt32 amount,                                PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,                                PRIntervalTime timeout, SndRcvOpCode opCode){    OSStatus err;    EndpointRef endpoint = (EndpointRef) fd->secret->md.osfd;    PRThread *me = _PR_MD_CURRENT_THREAD();    PRInt32 bytesLeft = amount;    TUnitData dgram;    OTResult	result;    PR_ASSERT(flags == 0);        if (endpoint == NULL) {        err = kEBADFErr;        goto ErrorExit;    }            if (buf == NULL || addr == NULL) {        err = kEFAULTErr;        goto ErrorExit;    }        if (opCode != kDGRAM_SEND && opCode != kDGRAM_RECEIVE) {        err = kEINVALErr;        goto ErrorExit;    }            memset(&dgram, 0 , sizeof(dgram));    dgram.addr.maxlen = *addrlen;    dgram.addr.len = *addrlen;    dgram.addr.buf = (UInt8*) addr;    dgram.udata.maxlen = amount;    dgram.udata.len = amount;    dgram.udata.buf = (UInt8*) buf;        while (bytesLeft > 0) {            PrepareForAsyncCompletion(me, fd->secret->md.osfd);            if (opCode == kDGRAM_SEND) {			fd->secret->md.write.thread = me;			fd->secret->md.writeReady = PR_FALSE;				// expect the worst            err = OTSndUData(endpoint, &dgram);			if (result != kOTFlowErr)							// hope for the best				fd->secret->md.writeReady = PR_TRUE;		} else {			fd->secret->md.read.thread = me;			fd->secret->md.readReady = PR_FALSE;				// expect the worst			            err = OTRcvUData(endpoint, &dgram, NULL);			if (result != kOTNoDataErr)							// hope for the best				fd->secret->md.readReady = PR_TRUE;		}        if (err == kOTNoError) {            buf = (void *) ( (UInt32) buf + (UInt32)dgram.udata.len );            bytesLeft -= dgram.udata.len;            dgram.udata.buf = (UInt8*) buf;                me->io_pending = PR_FALSE;        } else {            PR_ASSERT(err == kOTNoDataErr || err == kOTOutStateErr);            WaitOnThisThread(me, timeout);            err = me->md.osErrCode;            if (err != kOTNoError)                goto ErrorExit;        }    }    if (opCode == kDGRAM_RECEIVE)        *addrlen = dgram.addr.len;    return amount;ErrorExit:    macsock_map_error(err);    return -1;}