if (pd->in_flags & PR_POLL_READ) { in_flags_read = (pd->fd->methods->poll)( pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read); } if (pd->in_flags & PR_POLL_WRITE) { in_flags_write = (pd->fd->methods->poll)( pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write); } if ((0 != (in_flags_read & out_flags_read)) || (0 != (in_flags_write & out_flags_write))) { ready += 1;   pd->out_flags = out_flags_read | out_flags_write; } else { PRFileDesc *bottomFD; PRBool readReady, writeReady, exceptReady;
PR_Unlock(thread->md.asyncIOLock); _PR_FAST_INTSON(is);
PRInt32 _MD_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout){    PRInt32 ready = 0;    PRPollDesc *pd, *epd;    PRThread	*thread = _PR_MD_CURRENT_THREAD();    PRIntervalTime timein;        if (PR_INTERVAL_NO_TIMEOUT != timeout)        timein = PR_IntervalNow();    do    {        for (pd = pds, epd = pd + npds; pd < epd; pd++)        {            PRInt16  in_flags_read = 0,  in_flags_write = 0;            PRInt16 out_flags_read = 0, out_flags_write = 0;            if (NULL == pd->fd || pd->in_flags == 0) continue;            if (pd->in_flags & PR_POLL_READ)            {                in_flags_read = (pd->fd->methods->poll)(                    pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);            }            if (pd->in_flags & PR_POLL_WRITE)            {                in_flags_write = (pd->fd->methods->poll)(                    pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);            }            if ((0 != (in_flags_read & out_flags_read))            || (0 != (in_flags_write & out_flags_write)))            {                ready += 1;  /* some layer has buffer input */                pd->out_flags = out_flags_read | out_flags_write;            }            else            {                PRFileDesc *bottomFD;                PRBool readReady, writeReady, exceptReady;                pd->out_flags = 0;  /* pre-condition */                bottomFD = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);                PR_ASSERT(NULL != bottomFD);                if ((NULL != bottomFD) && (_PR_FILEDESC_OPEN == bottomFD->secret->state))                {                    bottomFD->secret->md.poll.thread = thread;                	                    if (GetState(bottomFD, &readReady, &writeReady, &exceptReady))                    {                        if (readReady)                        {                            if (in_flags_read & PR_POLL_READ)                                pd->out_flags |= PR_POLL_READ;                            if (in_flags_write & PR_POLL_READ)                                pd->out_flags |= PR_POLL_WRITE;                        }                        if (writeReady)                        {                            if (in_flags_read & PR_POLL_WRITE)                                pd->out_flags |= PR_POLL_READ;                            if (in_flags_write & PR_POLL_WRITE)                                pd->out_flags |= PR_POLL_WRITE;                        }                        if (exceptReady && (pd->in_flags & PR_POLL_EXCEPT))                        {                            pd->out_flags |= PR_POLL_EXCEPT;                        }                        if (0 != pd->out_flags) ready++;                    }                }                else                {                    ready += 1;  /* this will cause an abrupt return */                    pd->out_flags = PR_POLL_NVAL;  /* bogii */                }            }        }        if (ready > 0) return ready;        thread->io_pending       = PR_TRUE;        thread->io_fd            = NULL;        thread->md.osErrCode     = noErr;        WaitOnThisThread(thread, timeout);    } while ((timeout == PR_INTERVAL_NO_TIMEOUT) ||           (((PRIntervalTime)(PR_IntervalNow() - timein)) < timeout));    return 0; /* timed out */}