You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

93 lines
1.9 KiB

#include <iostream>
#include<event2/event.h>
#ifndef _WIN32
#include <signal.h>
#endif // !_WIN32
using namespace std;
int main()
{
#ifdef _WIN32
//初始化socket库
WSADATA wsa;
WSAStartup(MAKEWORD(2, 2), &wsa);
#else
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { //忽略管道信号,发送数据给已关闭的socket,会飞掉!
return 1;
}
#endif
//初始化libevent上下文
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;
}
//设置特征
//event_config_require_features(conf, EV_FEATURE_FDS);
//初始化配置上下文
event_base* base = event_base_new_with_config(conf);
if (!base) {
cout << "event_base_new_with_config failed!" << endl;
base = event_base_new();
if (!base) {
cerr << "event_base_new failed" << endl;
return 0;
}
}
else {
//获取当前网络模型
cout << "current mothed is " << event_base_get_method(base) << endl;
//确认特征是否生效
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_config_free(conf);
}
return 0;
}