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.

50 lines
891 B

  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. event_base* base = event_base_new_with_config(conf);
  28. if (!base) {
  29. cout << "event_base_new_with_config failed!" << endl;
  30. }
  31. else {
  32. cout << "event_base_new_with_config success!" << endl;
  33. event_config_free(conf);
  34. }
  35. return 0;
  36. }