用独立、可 join 的 Reactor 线程监听单个 Linux 文件描述符。
More...
#include <sttnet.h>
|
| void | startListen (const int &fd, const bool &flag=true, const time::Duration &dt=time::Duration{0, 0, 20, 0, 0}) |
| | 开始监听
|
| |
| bool | isListen () |
| | 返回epoll监听状态
|
| |
| void | setFunction (std::function< bool(const int &fd)> fc) |
| | 设置epoll触发后的处理函数 注册一个回调函数
|
| |
| void | setEndFunction (std::function< void(const int &fd)> fcEnd) |
| | 设置epoll退出前的回调函数 注册一个回调函数
|
| |
| void | setTimeOutFunction (std::function< bool(const int &fd)> fcTimeOut) |
| | 设置epoll超时后出发的回调函数 注册一个回调函数
|
| |
| bool | endListen () |
| | 结束epoll监听 会阻塞直到epoll退出完成
|
| |
| void | endListenWithSignal () |
| | 发送结束epoll的信号
|
| |
| void | waitAndQuit (const time::Duration &t=time::Duration{0, 0, 0, 10, 10}) |
| | 开始退出epoll倒计时,直到套接字有新的消息 如果套接字倒计时结束还没有新的消息,那么退出epoll
|
| |
| | ~EpollSingle () |
| | EpollSingle的析构函数 调用 endListen() 唤醒并 join 监听线程。
|
| |
用独立、可 join 的 Reactor 线程监听单个 Linux 文件描述符。
- Note
- 对象拥有监听线程;停止或析构会通过 eventfd 立即唤醒 epoll,不再依赖轮询等待。
◆ ~EpollSingle()
| stt::network::EpollSingle::~EpollSingle |
( |
| ) |
|
|
inline |
◆ endListen()
| bool stt::network::EpollSingle::endListen |
( |
| ) |
|
结束epoll监听 会阻塞直到epoll退出完成
- Returns
- true:处理结束 false:结束失败
- Note
- 可重复调用。从监听回调线程调用时只请求停止,不会自 join。
◆ endListenWithSignal()
| void stt::network::EpollSingle::endListenWithSignal |
( |
| ) |
|
发送结束epoll的信号
- Note
- 线程安全且不阻塞;使用 eventfd 唤醒 epoll,但不等待线程退出。
◆ isListen()
| bool stt::network::EpollSingle::isListen |
( |
| ) |
|
|
inline |
返回epoll监听状态
- Returns
- true:正在监听 false:没有监听
◆ setEndFunction()
| void stt::network::EpollSingle::setEndFunction |
( |
std::function< void(const int &fd)> | fcEnd | ) |
|
|
inline |
设置epoll退出前的回调函数 注册一个回调函数
- Parameters
-
| fcEnd | 一个函数或函数对象,用于处理epoll退出前的流程 -参数:const int &fd - 要处理的套接字 |
- Note
- 传入的函数应该有如下签名 void func(const int &fd)
◆ setFunction()
| void stt::network::EpollSingle::setFunction |
( |
std::function< bool(const int &fd)> | fc | ) |
|
|
inline |
设置epoll触发后的处理函数 注册一个回调函数
- Parameters
-
| fc | 一个函数或函数对象,用于当有数据时上来的时候回调处理套接字fd -参数:const int &fd - 要处理的套接字 -返回: bool - 返回true成功成功,返回false处理失败 |
- Note
- 传入的函数应该有如下签名 bool func(const int &fd)
-
如果处理失败了 会退出epoll监听(没有关闭套接字)
◆ setTimeOutFunction()
| void stt::network::EpollSingle::setTimeOutFunction |
( |
std::function< bool(const int &fd)> | fcTimeOut | ) |
|
|
inline |
设置epoll超时后出发的回调函数 注册一个回调函数
- Parameters
-
| fcTimeOut | 一个函数或函数对象,用于当epoll超时的时候回调处理套接字fd -参数:const int &fd - 要处理的套接字 -返回: bool - 返回true成功成功,返回false处理失败 |
- Note
- 传入的函数应该有如下签名 bool func(const int &fd)
-
如果处理失败了 会退出epoll监听(没有关闭套接字)
◆ startListen()
| void stt::network::EpollSingle::startListen |
( |
const int & | fd, |
|
|
const bool & | flag = true, |
|
|
const time::Duration & | dt = time::Duration{0, 0, 20, 0, 0} ) |
开始监听
- Parameters
-
| fd | 需要监听的句柄 |
| flag | true:水平触发 false:边缘触发 |
| dt | 填入监听超时时间 |
- Note
- 从其他线程重复调用会先停止并 join 旧监听。不要在本对象自己的监听回调中重启或销毁对象; 回调中需要停止时应调用 endListenWithSignal() 或返回 false。
◆ waitAndQuit()
开始退出epoll倒计时,直到套接字有新的消息 如果套接字倒计时结束还没有新的消息,那么退出epoll
- Parameters
-
| t | 一个Duration对象 填入倒计时时长 (默认为10秒) |
The documentation for this class was generated from the following file: