linux版本中间件

main.cpp 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <cstdio>
  2. #include "EslGateway.h"
  3. #include "Log.h"
  4. #include "Config.h"
  5. #include "WebSocketServer.h"
  6. #ifdef __linux__
  7. #include <sys/resource.h>
  8. #define CORE_SIZE 1024 * 1024 * 500
  9. #endif
  10. int dump()
  11. {
  12. struct rlimit crlmt;
  13. if (getrlimit(RLIMIT_CORE, &crlmt) == -1) {
  14. return -1;
  15. }
  16. LOG_INFO("Before set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
  17. //crlmt.rlim_cur = (rlim_t)CORE_SIZE;
  18. //crlmt.rlim_max = (rlim_t)CORE_SIZE;
  19. // 设置新的资源限制
  20. crlmt.rlim_cur = RLIM_INFINITY; // 软限制为无限制
  21. crlmt.rlim_max = RLIM_INFINITY; // 硬限制为无限制
  22. if (setrlimit(RLIMIT_CORE, &crlmt) == -1) {
  23. return -1;
  24. }
  25. if (getrlimit(RLIMIT_CORE, &crlmt) == -1) {
  26. return -1;
  27. }
  28. LOG_INFO("After set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
  29. return 0;
  30. }
  31. int main()
  32. {
  33. if (MYLog::instance()->Init("log4cpp.conf") != 0) {
  34. std::cout << "日志文件加载失败" << std::endl;
  35. getchar();
  36. return 0;
  37. }
  38. LOG_INFO("日志配置文件加载成功");
  39. if (!CConfig::GetInstance()->load()) {
  40. LOG_ERROR("FS配置文件加载失败");
  41. getchar();
  42. return 0;
  43. }
  44. LOG_INFO("FS配置文件加载成功");
  45. dump();
  46. std::unique_ptr<EslGateway> pEslGateway = std::make_unique<EslGateway>();
  47. if (!pEslGateway->initDB()) {
  48. getchar();
  49. return 0;
  50. }
  51. if (!pEslGateway->initWs()) {
  52. LOG_ERROR("websocket端口监听失败");
  53. getchar();
  54. return 0;
  55. }
  56. LOG_INFO("websocket监听成功");
  57. if (!pEslGateway->start()) {
  58. LOG_ERROR("FS链接失败");
  59. getchar();
  60. return 0;
  61. }
  62. LOG_INFO_S("FS链接成功");
  63. pEslGateway->runWs();
  64. return 0;
  65. }