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

📄 rn_sys_epoll.h

📁 linux平台epoll封装
💻 H
字号:
/*-------------------------------------------------------------------------- Copyright 1999,2001, Dan Kegel http://www.kegel.com/ Copyright 2003 Ixia http://www.ixiacom.com/ See the file COPYING This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA--------------------------------------------------------------------------*/#ifndef rn_sys_epoll_H#define rn_sys_epoll_H#include <rn_config.h>	/* must come first */#if defined(HAVE_SYS_EPOLL_H) && defined(HAVE_EPOLL_CREATE)#include <assert.h>#include <errno.h>#include <poll.h>#include <sys/types.h>#include <time.h>   #include <unistd.h>#include <rn_event.h>#ifdef __cplusplusextern "C" {#endif/**  * A class to monitor a set of file descriptors for readiness events. * This implementation is a wrapper around the /dev/epoll event delivery  * scheme provided by Davide Libenzi's patch * (see http://www.xmailserver.org/linux-patches/nio-improve.html ) */struct rn_sys_epoll {	/** max number of fds epoll was told to happen at open time */	int maxfds;	/** The fd returned by epoll_create */	int epfd;	/** The memory-mapped buffer to that fd */	char *epmap;	/** Each fd we watch has an entry in this array. */	rn_client_t *m_fds;	/** Number of elements worth of heap allocated for m_fds. */	int m_fds_alloc;	/** How many fds we are watching. */	int m_fds_used;};/** Initialize the rn_t. */int rn_sys_epoll_init(struct rn_sys_epoll *, int maxfds);/** Release any resouces allocated internally by this rn_t. */void rn_sys_epoll_shutdown(struct rn_sys_epoll *);/** Sets the flags of fd for use with epoll On exit, the fd is ready for use with rn_sys_epoll_add Note: Overrides the old flags of fd. @param fd - the file descriptor to be used for IO @param pid - the pid of the process. Ignored for epoll*/int rn_sys_epoll_prepare_fd_for_add(int fd, int pid);/** Add a file descriptor to the set we monitor.  Caller should already have established a handler for SIGIO. @param fd file descriptor to add @param pfn function to call when fd is ready @param data context pointer to pass to pfn */int rn_sys_epoll_add(struct rn_sys_epoll *, int fd, rn_callback_fn_t pfn, void *data);/** Remove a file descriptor. */int rn_sys_epoll_del(struct rn_sys_epoll *, int fd);/** Sleep at most timeout_millisec waiting for an I/O readiness event on the file descriptors we're watching, and dispatch events to the handler for each file descriptor that is ready for I/O. This is included as an example of how to use waitForEvents and getNextEvent.  Real programs should probably avoid waitAndDispatchEvents and call waitForEvents and getNextEvent instead for maximum control over client deletion. */int rn_sys_epoll_waitAndDispatchEvents(struct rn_sys_epoll *, int timeout_millisec);#ifdef __cplusplus}#endif#endif#endif

⌨️ 快捷键说明

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