ini:添加cli和server配置启动。
This commit is contained in:
parent
65435cc8f6
commit
078e574850
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -123,6 +123,8 @@
|
|||||||
"stop_token": "cpp",
|
"stop_token": "cpp",
|
||||||
"*.ipp": "cpp",
|
"*.ipp": "cpp",
|
||||||
"queue": "cpp",
|
"queue": "cpp",
|
||||||
"resumable": "cpp"
|
"resumable": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"set": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
3630
3rd/SimpleIni.h
Normal file
3630
3rd/SimpleIni.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -18,9 +18,9 @@ CClient::~CClient()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::run()
|
void CClient::run(const std::string& ip, const std::string& port)
|
||||||
{
|
{
|
||||||
if (!client_->connect("127.0.0.1", "8080")) {
|
if (!client_->connect(ip, port)) {
|
||||||
logger_->info("{} connect err.", __FUNCTION__);
|
logger_->info("{} connect err.", __FUNCTION__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
~CClient();
|
~CClient();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void run();
|
void run(const std::string& ip, const std::string& port);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool get_task_list();
|
bool get_task_list();
|
||||||
|
@ -1,12 +1,56 @@
|
|||||||
#include <iostream>
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
#include <SimpleIni.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <iostream>
|
||||||
|
#include <of_path.h>
|
||||||
|
|
||||||
|
using namespace ofen;
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
struct TransmSet {
|
||||||
|
std::string ip{};
|
||||||
|
std::string port{};
|
||||||
|
};
|
||||||
|
|
||||||
std::shared_ptr<spdlog::logger> g_Logger = nullptr;
|
std::shared_ptr<spdlog::logger> g_Logger = nullptr;
|
||||||
|
bool gen_default_ini(const std::string& path)
|
||||||
|
{
|
||||||
|
g_Logger->warn("Gen Default Setting Ini in [{}].", path);
|
||||||
|
CSimpleIniA ini_handle{};
|
||||||
|
ini_handle.LoadFile(path.c_str());
|
||||||
|
ini_handle.SetValue("Setting", "IP", "127.0.0.1");
|
||||||
|
ini_handle.SetValue("Setting", "PORT", "8989");
|
||||||
|
ini_handle.SaveFile(path.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
bool read_ini(TransmSet& set)
|
||||||
|
{
|
||||||
|
fs::path home(COfPath::get_home());
|
||||||
|
std::string config_path = home.append("transm.ini").string();
|
||||||
|
if (!fs::exists(config_path) && !gen_default_ini(config_path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CSimpleIniA ini_handle{};
|
||||||
|
SI_Error ret = ini_handle.LoadFile(config_path.c_str());
|
||||||
|
if (ret != SI_OK) {
|
||||||
|
g_Logger->error("Load Ini [{}] Failed.", config_path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
set.ip = ini_handle.GetValue("Setting", "IP");
|
||||||
|
set.port = ini_handle.GetValue("Setting", "PORT");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
g_Logger = get_logger("client", "client.log");
|
g_Logger = get_logger("client", "client.log");
|
||||||
|
TransmSet set;
|
||||||
|
if (!read_ini(set)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
CClient client(g_Logger);
|
CClient client(g_Logger);
|
||||||
client.run();
|
client.run(set.ip, set.port);
|
||||||
|
g_Logger->info("exit &&&&&&&&&&&&&");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,26 +1,25 @@
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// #ifdef _WIN32
|
|
||||||
// #define _CRTDBG_MAP_ALLOC
|
|
||||||
// #include <crtdbg.h>
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
std::shared_ptr<spdlog::logger> g_Logger = nullptr;
|
std::shared_ptr<spdlog::logger> g_Logger = nullptr;
|
||||||
int main()
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// #ifdef _WIN32
|
|
||||||
// _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
|
|
||||||
// #endif
|
|
||||||
g_Logger = get_logger("server", "server.log");
|
g_Logger = get_logger("server", "server.log");
|
||||||
|
|
||||||
|
int port = 9898;
|
||||||
|
if (argc < 2) {
|
||||||
|
g_Logger->info("Use Default Port:{}", port);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::string str_port(argv[1]);
|
||||||
|
port = std::stoi(str_port);
|
||||||
|
g_Logger->info("Use Port:{}", port);
|
||||||
|
}
|
||||||
asio::io_context io_context;
|
asio::io_context io_context;
|
||||||
CTcpServer server(io_context, g_Logger);
|
CTcpServer server(io_context, g_Logger);
|
||||||
if (!server.start(9898)) {
|
if (!server.start(port)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
io_context.run();
|
io_context.run();
|
||||||
// #ifdef _WIN32
|
|
||||||
// _CrtDumpMemoryLeaks();
|
|
||||||
// #endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user