中间件底层,websocket

RcfConfig.cpp 778B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "RcfConfig.h"
  2. #include <yaml-cpp/yaml.h>
  3. #include <fstream>
  4. using namespace std;
  5. #pragma comment(lib,"libyaml-cppmd-mt.lib")
  6. #define YAMLCONFIGFILEPATH "RcfConfig.yml"
  7. RcfConfig::RcfConfig()
  8. {
  9. try
  10. {
  11. YAML::Node node = YAML::LoadFile(YAMLCONFIGFILEPATH);
  12. if (node["Rcf"])
  13. {
  14. this->m_RcfIp = node["Rcf"]["IP"].as<string>();
  15. this->m_RcfPort = node["Rcf"]["PORT"].as<int>();
  16. }
  17. }
  18. catch (const std::exception&)
  19. {
  20. // 配置文件 读取异常,重新初始化配置文件
  21. YAML::Node node;
  22. std::ofstream fout(YAMLCONFIGFILEPATH);
  23. node["Rcf"]["IP"] = "127.0.0.1";
  24. node["Rcf"]["PORT"] = 8821;
  25. fout << node;
  26. fout.close();
  27. this->m_RcfIp = node["ACD"]["IP"].as<string>();
  28. this->m_RcfPort = node["ACD"]["PORT"].as<int>();
  29. }
  30. }
  31. RcfConfig RcfConfig::instance;