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.

85 lines
1.7 KiB

3 years ago
3 years ago
3 years ago
  1. 
  2. #include <iostream>
  3. #include<event2/event.h>
  4. #ifndef _WIN32
  5. #include <signal.h>
  6. #endif // !_WIN32
  7. using namespace std;
  8. int main()
  9. {
  10. #ifdef _WIN32
  11. //初始化socket库
  12. WSADATA wsa;
  13. WSAStartup(MAKEWORD(2, 2), &wsa);
  14. #else
  15. if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { //忽略管道信号,发送数据给已关闭的socket,会飞掉!
  16. return 1;
  17. }
  18. #endif
  19. //初始化libevent上下文
  20. event_config *conf = event_config_new();
  21. //显示支持的网络模式
  22. const char** methods = event_get_supported_methods();
  23. cout << "supported_methods" << endl;
  24. for (int i = 0; methods[i] != NULL; i++) {
  25. cout << methods[i] << endl;
  26. }
  27. //设置特征
  28. //初始化配置上下文
  29. event_base* base = event_base_new_with_config(conf);
  30. if (!base) {
  31. cout << "event_base_new_with_config failed!" << endl;
  32. }
  33. else {
  34. //确认特征是否生效
  35. int f = event_base_get_features(base);
  36. if (f& EV_FEATURE_ET) {
  37. cout << "EV_FEATURE_ET events are supported" << endl;
  38. }
  39. else {
  40. cout << "EV_FEATURE_ET events are not supported" << endl;
  41. }
  42. if (f& EV_FEATURE_O1) {
  43. cout << "EV_FEATURE_O1 events are supported" << endl;
  44. }
  45. else {
  46. cout << "EV_FEATURE_O1 events are not supported" << endl;
  47. }
  48. if (f& EV_FEATURE_FDS) {
  49. cout << "EV_FEATURE_FDS events are supported" << endl;
  50. }
  51. else {
  52. cout << "EV_FEATURE_FDS events are not supported" << endl;
  53. }
  54. if (f& EV_FEATURE_EARLY_CLOSE) {
  55. cout << "EV_FEATURE_EARLY_CLOSE events are supported" << endl;
  56. }
  57. else {
  58. cout << "EV_FEATURE_EARLY_CLOSE events are not supported" << endl;
  59. }
  60. cout << "event_base_new_with_config success!" << endl;
  61. event_config_free(conf);
  62. }
  63. return 0;
  64. }