# 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
没有合适的资源?快使用搜索试试~ 我知道了~
基于C++11的高性能运营级流媒体服务框架
共558个文件
cpp:180个
h:169个
xml:22个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 75 浏览量
2024-05-13
10:18:29
上传
评论
收藏 22.91MB ZIP 举报
温馨提示
实现RTSP/RTMP/HLS/HTTP协议的轻量级流媒体框架,支持大并发连接请求。基于C++11开发,避免使用裸指针,代码稳定可靠,性能优越。使用多路复用/多线程/异步网络IO模式开发,并发性能优越,支持海量客户端连接。代码经过长期大量的稳定性、性能测试,已经在线上商用验证已久。支持linux、macos、ios、android、windows全平台。支持x86、arm、risc-v、mips、龙芯、申威等指令集平台。支持画面秒开、极低延时(500毫秒内,最低可达100毫秒)。
资源推荐
资源详情
资源评论
收起资源包目录
基于C++11的高性能运营级流媒体服务框架 (558个子文件)
app-debug.apk 18.72MB
AUTHORS 4KB
gradlew.bat 3KB
gradlew.bat 2KB
wepoll.c 80KB
SPSParser.c 73KB
server.c 19KB
websocket.c 7KB
h264_media_server.c 6KB
pusher.c 4KB
h264_pusher.c 4KB
player_opencv.c 3KB
httpclient.c 2KB
.clang-format 3KB
android.toolchain.cmake 80KB
ios.toolchain.cmake 29KB
AndroidNdkGdb.cmake 4KB
FindMYSQL.cmake 4KB
Jemalloc.cmake 3KB
AndroidNdkModules.cmake 3KB
FindSRTP.cmake 2KB
FindX264.cmake 2KB
FindJEMALLOC.cmake 1KB
FindSCTP.cmake 555B
FindSWRESAMPLE.cmake 507B
FindAVFORMAT.cmake 483B
FindSWSCALE.cmake 471B
FindAVCODEC.cmake 471B
FindAVUTIL.cmake 459B
FindMP4V2.cmake 411B
FindSDL2.cmake 376B
FindFAAC.cmake 291B
WebApi.cpp 76KB
Sdp.cpp 60KB
WebRtcTransport.cpp 51KB
RtspSession.cpp 49KB
DtlsTransport.cpp 43KB
SctpAssociation.cpp 34KB
StunPacket.cpp 33KB
SrtTransport.cpp 30KB
MediaSource.cpp 30KB
JPEGRtp.cpp 29KB
RtmpProtocol.cpp 28KB
RtspPlayer.cpp 28KB
HttpSession.cpp 28KB
HttpFileManager.cpp 27KB
WebHook.cpp 27KB
Rtcp.cpp 26KB
RtpExt.cpp 23KB
RtmpSession.cpp 22KB
Transcode.cpp 22KB
MultiMediaSourceMuxer.cpp 22KB
mk_events_objects.cpp 21KB
Rtsp.cpp 21KB
config.cpp 21KB
RtspPusher.cpp 19KB
HlsPlayer.cpp 19KB
main.cpp 18KB
VideoStack.cpp 17KB
IceServer.cpp 17KB
amf.cpp 17KB
RtcpFCI.cpp 17KB
Packet.cpp 16KB
PacketQueue.cpp 15KB
AAC.cpp 14KB
HttpClient.cpp 14KB
test_sortor.cpp 14KB
test_server.cpp 14KB
mk_tcp.cpp 14KB
MediaSink.cpp 14KB
RtmpPlayer.cpp 14KB
FFmpegSource.cpp 14KB
H264.cpp 13KB
H264Encoder.cpp 13KB
RtpSender.cpp 13KB
mk_media.cpp 12KB
H265Rtp.cpp 12KB
SrtTransportImp.cpp 12KB
PlayerProxy.cpp 12KB
RtpServer.cpp 12KB
Stamp.cpp 11KB
mk_common.cpp 11KB
test_bench_forward.cpp 11KB
Rtmp.cpp 11KB
H264Rtp.cpp 11KB
H265.cpp 10KB
Process.cpp 10KB
HttpBody.cpp 10KB
RtmpPusher.cpp 10KB
Parser.cpp 10KB
test_bench_push.cpp 10KB
Nack.cpp 10KB
RtpSession.cpp 10KB
RtpProcess.cpp 10KB
Frame.cpp 10KB
HttpCookieManager.cpp 9KB
DeviceHK.cpp 9KB
mk_events.cpp 9KB
native-lib.cpp 9KB
RtcpContext.cpp 9KB
共 558 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6718
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功