# wepoll - epoll for windows
[![][ci status badge]][ci status link]
This library implements the [epoll][man epoll] API for Windows
applications. It is fast and scalable, and it closely resembles the API
and behavior of Linux' epoll.
## Rationale
Unlike Linux, OS X, and many other operating systems, Windows doesn't
have a good API for receiving socket state notifications. It only
supports the `select` and `WSAPoll` APIs, but they
[don't scale][select scale] and suffer from
[other issues][wsapoll broken].
Using I/O completion ports isn't always practical when software is
designed to be cross-platform. Wepoll offers an alternative that is
much closer to a drop-in replacement for software that was designed
to run on Linux.
## Features
* Can poll 100000s of sockets efficiently.
* Fully thread-safe.
* Multiple threads can poll the same epoll port.
* Sockets can be added to multiple epoll sets.
* All epoll events (`EPOLLIN`, `EPOLLOUT`, `EPOLLPRI`, `EPOLLRDHUP`)
are supported.
* Level-triggered and one-shot (`EPOLLONESTHOT`) modes are supported
* Trivial to embed: you need [only two files][dist].
## Limitations
* Only works with sockets.
* Edge-triggered (`EPOLLET`) mode isn't supported.
## How to use
The library is [distributed][dist] as a single source file
([wepoll.c][wepoll.c]) and a single header file ([wepoll.h][wepoll.h]).<br>
Compile the .c file as part of your project, and include the header wherever
needed.
## Compatibility
* Requires Windows Vista or higher.
* Can be compiled with recent versions of MSVC, Clang, and GCC.
## API
### General remarks
* The epoll port is a `HANDLE`, not a file descriptor.
* All functions set both `errno` and `GetLastError()` on failure.
* For more extensive documentation, see the [epoll(7) man page][man epoll],
and the per-function man pages that are linked below.
### epoll_create/epoll_create1
```c
HANDLE epoll_create(int size);
HANDLE epoll_create1(int flags);
```
* Create a new epoll instance (port).
* `size` is ignored but most be greater than zero.
* `flags` must be zero as there are no supported flags.
* Returns `NULL` on failure.
* [Linux man page][man epoll_create]
### epoll_close
```c
int epoll_close(HANDLE ephnd);
```
* Close an epoll port.
* Do not attempt to close the epoll port with `close()`,
`CloseHandle()` or `closesocket()`.
### epoll_ctl
```c
int epoll_ctl(HANDLE ephnd,
int op,
SOCKET sock,
struct epoll_event* event);
```
* Control which socket events are monitored by an epoll port.
* `ephnd` must be a HANDLE created by
[`epoll_create()`](#epoll_createepoll_create1) or
[`epoll_create1()`](#epoll_createepoll_create1).
* `op` must be one of `EPOLL_CTL_ADD`, `EPOLL_CTL_MOD`, `EPOLL_CTL_DEL`.
* `sock` must be a valid socket created by [`socket()`][msdn socket],
[`WSASocket()`][msdn wsasocket], or [`accept()`][msdn accept].
* `event` should be a pointer to a [`struct epoll_event`](#struct-epoll_event).<br>
If `op` is `EPOLL_CTL_DEL` then the `event` parameter is ignored, and it
may be `NULL`.
* Returns 0 on success, -1 on failure.
* It is recommended to always explicitly remove a socket from its epoll
set using `EPOLL_CTL_DEL` *before* closing it.<br>
As on Linux, closed sockets are automatically removed from the epoll set, but
wepoll may not be able to detect that a socket was closed until the next call
to [`epoll_wait()`](#epoll_wait).
* [Linux man page][man epoll_ctl]
### epoll_wait
```c
int epoll_wait(HANDLE ephnd,
struct epoll_event* events,
int maxevents,
int timeout);
```
* Receive socket events from an epoll port.
* `events` should point to a caller-allocated array of
[`epoll_event`](#struct-epoll_event) structs, which will receive the
reported events.
* `maxevents` is the maximum number of events that will be written to the
`events` array, and must be greater than zero.
* `timeout` specifies whether to block when no events are immediately available.
- `<0` block indefinitely
- `0` report any events that are already waiting, but don't block
- `≥1` block for at most N milliseconds
* Return value:
- `-1` an error occurred
- `0` timed out without any events to report
- `≥1` the number of events stored in the `events` buffer
* [Linux man page][man epoll_wait]
### struct epoll_event
```c
typedef union epoll_data {
void* ptr;
int fd;
uint32_t u32;
uint64_t u64;
SOCKET sock; /* Windows specific */
HANDLE hnd; /* Windows specific */
} epoll_data_t;
```
```c
struct epoll_event {
uint32_t events; /* Epoll events and flags */
epoll_data_t data; /* User data variable */
};
```
* The `events` field is a bit mask containing the events being
monitored/reported, and optional flags.<br>
Flags are accepted by [`epoll_ctl()`](#epoll_ctl), but they are not reported
back by [`epoll_wait()`](#epoll_wait).
* The `data` field can be used to associate application-specific information
with a socket; its value will be returned unmodified by
[`epoll_wait()`](#epoll_wait).
* [Linux man page][man epoll_ctl]
| Event | Description |
|---------------|----------------------------------------------------------------------|
| `EPOLLIN` | incoming data available, or incoming connection ready to be accepted |
| `EPOLLOUT` | ready to send data, or outgoing connection successfully established |
| `EPOLLRDHUP` | remote peer initiated graceful socket shutdown |
| `EPOLLPRI` | out-of-band data available for reading |
| `EPOLLERR` | socket error<sup>1</sup> |
| `EPOLLHUP` | socket hang-up<sup>1</sup> |
| `EPOLLRDNORM` | same as `EPOLLIN` |
| `EPOLLRDBAND` | same as `EPOLLPRI` |
| `EPOLLWRNORM` | same as `EPOLLOUT` |
| `EPOLLWRBAND` | same as `EPOLLOUT` |
| `EPOLLMSG` | never reported |
| Flag | Description |
|------------------|---------------------------|
| `EPOLLONESHOT` | report event(s) only once |
| `EPOLLET` | not supported by wepoll |
| `EPOLLEXCLUSIVE` | not supported by wepoll |
| `EPOLLWAKEUP` | not supported by wepoll |
<sup>1</sup>: the `EPOLLERR` and `EPOLLHUP` events may always be reported by
[`epoll_wait()`](#epoll_wait), regardless of the event mask that was passed to
[`epoll_ctl()`](#epoll_ctl).
[ci status badge]: https://ci.appveyor.com/api/projects/status/github/piscisaureus/wepoll?branch=master&svg=true
[ci status link]: https://ci.appveyor.com/project/piscisaureus/wepoll/branch/master
[dist]: https://github.com/piscisaureus/wepoll/tree/dist
[man epoll]: http://man7.org/linux/man-pages/man7/epoll.7.html
[man epoll_create]: http://man7.org/linux/man-pages/man2/epoll_create.2.html
[man epoll_ctl]: http://man7.org/linux/man-pages/man2/epoll_ctl.2.html
[man epoll_wait]: http://man7.org/linux/man-pages/man2/epoll_wait.2.html
[msdn accept]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms737526(v=vs.85).aspx
[msdn socket]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740506(v=vs.85).aspx
[msdn wsasocket]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx
[select scale]: https://daniel.haxx.se/docs/poll-vs-select.html
[wsapoll broken]: https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/
[wepoll.c]: https://github.com/piscisaureus/wepoll/blob/dist/wepoll.c
[wepoll.h]: https://github.com/piscisaureus/wepoll/blob/dist/wepoll.h
没有合适的资源?快使用搜索试试~ 我知道了~
pyzmq-25.1.1b1.tar.gz
0 下载量 148 浏览量
2024-06-13
23:16:46
上传
评论
收藏 1.17MB GZ 举报
温馨提示
Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
资源推荐
资源详情
资源评论
收起资源包目录
pyzmq-25.1.1b1.tar.gz (621个子文件)
_service 2KB
setup.cfg.android 438B
LICENSE.BSD 2KB
socket.c 640KB
message.c 458KB
_poll.c 294KB
monitoredqueue.c 287KB
context.c 282KB
_device.c 230KB
_proxy_steerable.c 216KB
utils.c 187KB
error.c 144KB
_version.c 138KB
wepoll.c 66KB
tweetnacl.c 21KB
_cffi.c 1KB
vers.c 243B
check_sys_un.c 225B
dummy.c 90B
setup.cfg 38B
changelog 150B
run_with_env.cmd 4KB
compat 2B
control 2KB
COPYING 34KB
copyright 6KB
.coveragerc 186B
socket_base.cpp 68KB
zmq.cpp 43KB
ws_engine.cpp 39KB
options.cpp 38KB
ip.cpp 28KB
proxy.cpp 26KB
norm_engine.cpp 26KB
ctx.cpp 25KB
session_base.cpp 23KB
pgm_socket.cpp 23KB
stream_engine_base.cpp 22KB
radix_tree.cpp 21KB
ip_resolver.cpp 20KB
select.cpp 20KB
zmtp_engine.cpp 19KB
socket_poller.cpp 19KB
msg.cpp 19KB
curve_server.cpp 18KB
udp_engine.cpp 18KB
pipe.cpp 17KB
router.cpp 16KB
err.cpp 15KB
xpub.cpp 14KB
object.cpp 14KB
socks_connecter.cpp 14KB
tcp.cpp 14KB
mechanism.cpp 13KB
thread.cpp 12KB
signaler.cpp 12KB
gssapi_mechanism_base.cpp 12KB
trie.cpp 11KB
curve_mechanism_base.cpp 11KB
ws_listener.cpp 10KB
ipc_listener.cpp 10KB
zap_client.cpp 10KB
zmq_utils.cpp 10KB
socks.cpp 10KB
tcp_address.cpp 10KB
curve_client.cpp 9KB
tcp_connecter.cpp 9KB
req.cpp 9KB
stream.cpp 9KB
ws_decoder.cpp 9KB
plain_server.cpp 9KB
pgm_receiver.cpp 9KB
vmci_connecter.cpp 9KB
ws_connecter.cpp 9KB
tcp_listener.cpp 9KB
dish.cpp 9KB
clock.cpp 9KB
xsub.cpp 8KB
radio.cpp 8KB
vmci_listener.cpp 8KB
null_mechanism.cpp 8KB
plain_client.cpp 7KB
pgm_sender.cpp 7KB
gssapi_server.cpp 7KB
gssapi_client.cpp 7KB
dist.cpp 7KB
wss_engine.cpp 7KB
pollset.cpp 6KB
stream_connecter_base.cpp 6KB
epoll.cpp 6KB
udp_address.cpp 6KB
kqueue.cpp 6KB
random.cpp 6KB
v2_decoder.cpp 6KB
devpoll.cpp 6KB
own.cpp 6KB
ipc_connecter.cpp 6KB
lb.cpp 6KB
poll.cpp 6KB
server.cpp 5KB
共 621 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
程序员Chino的日记
- 粉丝: 3689
- 资源: 5万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- YOLOv10深度学习目标检测基础教程
- 全栈 Vue + Laravel + Axios CRUD 示例.zip
- 关注基础知识,打造优质前端博客,公众号前端工匠的作者.zip
- 具有电子表格外观和感觉的 Vue 数据网格 Handsontable 的官方 Vue 包装器 .zip
- 学生实验编程基础教程:构建你的第一个计算器
- 分布式应用程序启动器Vue 前端、以太坊 , IPFS 后端.zip
- 创建美观且省力的表单,输出有效数据 在 npm 上发布为 @koumoul,vjsf .zip
- 初级项目CNode社区.zip
- 从零开始的软件安装基础教程
- 16进制编辑器.apk
- 功能齐全的 Webpack + vue-loader 设置,具有热重载、linting、测试和 css 提取功能 .zip
- IT类课程习题解析与实践基础教程
- 另一个由 vite 提供支持的 Web 扩展(chrome、firefox 等)入门模板 .zip
- 可组合 Promises 和 Promises 作为组件.zip
- 可调整大小的 Vue.js 分割窗格 .zip
- 因时间精力有限,项目已不再维护,请慎重使用,vue2-cli-vux2-multe-page,使用了webpack2+vuejs2+vuxUI2的多页面脚手架.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功