⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uxwrap.c

📁 Netscape NSPR库源码
💻 C
📖 第 1 页 / 共 2 页
字号:
                        | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) {                    FD_SET(unixpd->osfd, rd);                    nbits++;                }                if (wr && (unixpd->in_flags & _PR_UNIX_POLL_WRITE)                        && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE                        | _PR_UNIX_POLL_ERR))) {                    FD_SET(unixpd->osfd, wr);                    nbits++;                }                if (ex && (unixpd->in_flags & _PR_UNIX_POLL_WRITE)                        && (unixpd->out_flags & PR_POLL_EXCEPT)) {                    FD_SET(unixpd->osfd, ex);                    nbits++;                }                PR_ASSERT(nbits > 0);#if defined(HPUX) || defined(SOLARIS) || defined(SUNOS4) || defined(OSF1) || defined(AIX)                retVal += nbits;#else /* IRIX */                retVal += 1;#endif            }        }    }    PR_ASSERT(tv || retVal != 0);    PR_LOG(_pr_io_lm, PR_LOG_MIN, ("select returns %d", retVal));    PR_DELETE(unixpds);    return retVal;}/* * Redefine poll, when supported on platforms, for local threads *//* * I am commenting out the poll() wrapper for Linux for now * because it is difficult to define _MD_POLL that works on all * Linux varieties.  People reported that glibc 2.0.7 on Debian * 2.0 Linux machines doesn't have the __syscall_poll symbol * defined.  (WTC 30 Nov. 1998) */#if defined(_PR_POLL_AVAILABLE) && !defined(LINUX)/* *----------------------------------------------------------------------- * poll() -- * * RETURN VALUES:  *     -1:  fails, errno indicates the error. *      0:  timed out, the revents bitmasks are not set. *      positive value: the number of file descriptors for which poll() *          has set the revents bitmask. * *----------------------------------------------------------------------- */#include <poll.h>#if defined(AIX_RENAME_SELECT)int wrap_poll(void *listptr, unsigned long nfds, long timeout)#elif (defined(AIX) && !defined(AIX_RENAME_SELECT))int poll(void *listptr, unsigned long nfds, long timeout)#elif defined(OSF1) || (defined(HPUX) && !defined(HPUX9))int poll(struct pollfd filedes[], unsigned int nfds, int timeout)#elif defined(HPUX9)int poll(struct pollfd filedes[], int nfds, int timeout)#elif defined(NETBSD)int poll(struct pollfd *filedes, nfds_t nfds, int timeout)#elif defined(OPENBSD)int poll(struct pollfd *filedes, int nfds, int timeout)#elif defined(FREEBSD)int poll(struct pollfd *filedes, unsigned nfds, int timeout)#elseint poll(struct pollfd *filedes, unsigned long nfds, int timeout)#endif{#ifdef AIX    struct pollfd *filedes = (struct pollfd *) listptr;#endif    struct pollfd *pfd, *epfd;    _PRUnixPollDesc *unixpds, *unixpd, *eunixpd;    PRIntervalTime ticks;    PRInt32 pdcnt;    int ready;    /*     * Easy special case: zero timeout.  Simply call the native     * poll() with no fear of blocking.     */    if (timeout == 0) {#if defined(AIX)        return _MD_POLL(listptr, nfds, timeout);#else        return _MD_POLL(filedes, nfds, timeout);#endif    }    if (!_pr_initialized) {        _PR_ImplicitInitialization();    }#ifndef _PR_LOCAL_THREADS_ONLY    if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {    	return _MD_POLL(filedes, nfds, timeout);    }#endif    /* We do not support the pollmsg structures on AIX */#ifdef AIX    PR_ASSERT((nfds & 0xff00) == 0);#endif    if (timeout < 0 && timeout != -1) {        errno = EINVAL;        return -1;    }    /* Convert timeout from miliseconds to ticks */    if (timeout == -1) {        ticks = PR_INTERVAL_NO_TIMEOUT;    } else {        ticks = PR_MillisecondsToInterval(timeout);    }    /* Check for no descriptor case (just do a timeout) */    if (nfds == 0) {        PR_Sleep(ticks);        return 0;    }    unixpds = (_PRUnixPollDesc *)            PR_MALLOC(nfds * sizeof(_PRUnixPollDesc));    if (NULL == unixpds) {        errno = EAGAIN;        return -1;    }    pdcnt = 0;    epfd = filedes + nfds;    unixpd = unixpds;    for (pfd = filedes; pfd < epfd; pfd++) {        /*         * poll() ignores negative fd's.         */        if (pfd->fd >= 0) {            unixpd->osfd = pfd->fd;#ifdef _PR_USE_POLL            unixpd->in_flags = pfd->events;#else            /*             * Map the poll events to one of the three that can be             * represented by the select fd_sets:             *     POLLIN, POLLRDNORM  ===> readable             *     POLLOUT, POLLWRNORM ===> writable             *     POLLPRI, POLLRDBAND ===> exception             *     POLLNORM, POLLWRBAND (and POLLMSG on some platforms)             *     are ignored.             *             * The output events POLLERR and POLLHUP are never turned on.             * POLLNVAL may be turned on.             */            unixpd->in_flags = 0;            if (pfd->events & (POLLIN#ifdef POLLRDNORM                    | POLLRDNORM#endif                    )) {                unixpd->in_flags |= _PR_UNIX_POLL_READ;            }            if (pfd->events & (POLLOUT#ifdef POLLWRNORM                    | POLLWRNORM#endif                    )) {                unixpd->in_flags |= _PR_UNIX_POLL_WRITE;            }            if (pfd->events & (POLLPRI#ifdef POLLRDBAND                    | POLLRDBAND#endif                    )) {                unixpd->in_flags |= PR_POLL_EXCEPT;            }#endif  /* _PR_USE_POLL */            unixpd->out_flags = 0;            unixpd++;            pdcnt++;        }    }    ready = _PR_WaitForMultipleFDs(unixpds, pdcnt, ticks);    if (-1 == ready) {        if (PR_GetError() == PR_PENDING_INTERRUPT_ERROR) {            errno = EINTR;  /* XXX we aren't interrupted by a signal, but... */        } else {            errno = PR_GetOSError();        }    }    if (ready <= 0) {        goto done;    }    /*     * Copy the out_flags from the _PRUnixPollDesc structures to the     * user's pollfd structures and free the allocated memory     */    unixpd = unixpds;    for (pfd = filedes; pfd < epfd; pfd++) {        pfd->revents = 0;        if (pfd->fd >= 0) {#ifdef _PR_USE_POLL            pfd->revents = unixpd->out_flags;#else            if (0 != unixpd->out_flags) {                if (unixpd->out_flags & _PR_UNIX_POLL_READ) {                    if (pfd->events & POLLIN) {                        pfd->revents |= POLLIN;                    }#ifdef POLLRDNORM                    if (pfd->events & POLLRDNORM) {                        pfd->revents |= POLLRDNORM;                    }#endif                }                if (unixpd->out_flags & _PR_UNIX_POLL_WRITE) {                    if (pfd->events & POLLOUT) {                        pfd->revents |= POLLOUT;                    }#ifdef POLLWRNORM                    if (pfd->events & POLLWRNORM) {                        pfd->revents |= POLLWRNORM;                    }#endif                }                if (unixpd->out_flags & _PR_UNIX_POLL_EXCEPT) {                    if (pfd->events & POLLPRI) {                        pfd->revents |= POLLPRI;                    }#ifdef POLLRDBAND                    if (pfd->events & POLLRDBAND) {                        pfd->revents |= POLLRDBAND;                    }#endif                }                if (unixpd->out_flags & _PR_UNIX_POLL_ERR) {                    pfd->revents |= POLLERR;                }                if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) {                    pfd->revents |= POLLNVAL;                }                if (unixpd->out_flags & _PR_UNIX_POLL_HUP) {                    pfd->revents |= POLLHUP;                }            }#endif  /* _PR_USE_POLL */            unixpd++;        }    }done:    PR_DELETE(unixpds);    return ready;}#endif  /* !defined(LINUX) */#endif  /* defined(_PR_PTHREADS) || defined(_PR_GLOBAL_THREADS_ONLY) *//* uxwrap.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -