/** * http * */ #ifndef MYHTTP_H_ #define MYHTTP_H_ #include #include #include #include #include #include #include #include namespace ai_matrix { class MyHttp final { public: static MyHttp *getins(); std::string socketHttp(std::string host, std::string request); std::string postData(std::string host, std::string path, std::string post_content); std::string getData(std::string host, std::string path, std::string get_content); private: MyHttp() = default; MyHttp(const MyHttp &) = delete; MyHttp(MyHttp &&) = delete; MyHttp &operator=(const MyHttp &) = delete; MyHttp &operator=(MyHttp &&) = delete; ~MyHttp() = default; //定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露 class GarbageCollector { public: ~GarbageCollector() { if (MyHttp::ins) { delete MyHttp::ins; MyHttp::ins = nullptr; } } }; static GarbageCollector gc; static MyHttp *ins; static std::mutex mx; //锁,保证线程安全 }; } #endif