代码验证
#include <event2/event.h>
#include <signal.h>
#include <iostream>
using namespace std;
int main()
{
#ifdef _WIN32
//初始化socket库
WSADATA wsa;
WSAStartup(MAKEWORD(2, 2), &wsa);
#else
//忽略管道信号,发送数据给已关闭的socket
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
return 1;
#endif
//创建配置上下文
event_config* conf = event_config_new();
//显示支持的网络模式
const char** methods = event_get_supported_methods();
cout << "supported_methods:" << endl;
for (int i = 0; methods[i] != NULL; i++)
{
cout << methods[i] << endl;
}
//设置特征
//设置了EV_FEATURE_FDS 其他特征就无法设置,在windows中EV_FEATURE_FDS无效
//event_config_require_features(conf, EV_FEATURE_ET| EV_FEATURE_FDS);
event_config_require_features(conf, EV_FEATURE_FDS);
//初始化配置libevent上下文
event_base* base = event_base_new_with_config(conf);
event_config_free(conf);
//设置网络模型,使用select
//event_config_avoid_method(conf, "epoll");
//event_config_avoid_method(conf, "poll");
if (!base)
{
cerr << "event_base_new_with_config failed!" << endl;
base = event_base_new();
if (!base)
{
cerr << "event_base_new failed!" << endl;
return 0;
}
}
else
{
//确认特征是否生效
int f = event_base_get_features(base);
if (f & EV_FEATURE_ET)
cout << "EV_FEATURE_ET events are supported." << endl;
else
cout << "EV_FEATURE_ET events are not supported." << endl;
if (f & EV_FEATURE_O1)
cout << "EV_FEATURE_O1 events are supported." << endl;
else
cout << "EV_FEATURE_O1 events are not supported." << endl;
if (f & EV_FEATURE_FDS)
cout << "EV_FEATURE_FDS events are supported." << endl;
else
cout << "EV_FEATURE_FDS events are not supported." << endl;
if (f & EV_FEATURE_EARLY_CLOSE)
cout << "EV_FEATURE_EARLY_CLOSE events are supported." << endl;
else
cout << "EV_FEATURE_EARLY_CLOSE events are not supported." << endl;
cout << "event_base_new_with_config success!" << endl;
event_base_free(base);
}
return 0;
}
window下
event_config_require_features(conf, EV_FEATURE_ET);
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/adc1d40bce8e777e210732d931459f84.png)
event_config_require_features(conf, EV_FEATURE_FDS);
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e0c721817d0bdd42a64c2a3a424ad483.png)
event_config_require_features(conf, EV_FEATURE_ET| EV_FEATURE_FDS);
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8574b82f38243d288a6195f6aea12b0e.png)
linux下
event_config_require_features(conf, EV_FEATURE_ET);
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/973c6d322d34c6d16f521539948fb125.png)
event_config_require_features(conf, EV_FEATURE_FDS);
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5efc8fef905338e35e8f23293e3bbc9f.png)
event_config_require_features(conf, EV_FEATURE_ET| EV_FEATURE_FDS);
设置了EV_FEATURE_FDS 其他特征就无法设置
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/52abc2259b4973cfe8cbf2a56fc9d8fd.png)