2222#error "Unsupported platform!"
2323#endif
2424
25- void RunServer (){
25+ void RunServer () {
2626 // Create logs/ folder and setup log to file
27- std::filesystem::create_directory (cortex_utils::logs_folder);
28- trantor::AsyncFileLogger asyncFileLogger;
29- asyncFileLogger.setFileName (cortex_utils::logs_base_name);
30- asyncFileLogger.startLogging ();
31- trantor::Logger::setOutputFunction (
32- [&](const char * msg, const uint64_t len) {
33- asyncFileLogger.output (msg, len);
34- },
35- [&]() { asyncFileLogger.flush (); });
36- asyncFileLogger.setFileSizeLimit (cortex_utils::log_file_size_limit);
37- // Number of cortex.cpp threads
38- // if (argc > 1) {
39- // thread_num = std::atoi(argv[1]);
40- // }
27+ std::filesystem::create_directory (cortex_utils::logs_folder);
28+ trantor::AsyncFileLogger asyncFileLogger;
29+ asyncFileLogger.setFileName (cortex_utils::logs_base_name);
30+ asyncFileLogger.startLogging ();
31+ trantor::Logger::setOutputFunction (
32+ [&](const char * msg, const uint64_t len) {
33+ asyncFileLogger.output (msg, len);
34+ },
35+ [&]() { asyncFileLogger.flush (); });
36+ asyncFileLogger.setFileSizeLimit (cortex_utils::log_file_size_limit);
37+ // Number of cortex.cpp threads
38+ // if (argc > 1) {
39+ // thread_num = std::atoi(argv[1]);
40+ // }
4141
42- // // Check for host argument
43- // if (argc > 2) {
44- // host = argv[2];
45- // }
42+ // // Check for host argument
43+ // if (argc > 2) {
44+ // host = argv[2];
45+ // }
4646
47- // // Check for port argument
48- // if (argc > 3) {
49- // port = std::atoi(argv[3]); // Convert string argument to int
50- // }
51- int thread_num = 1 ;
52- std::string host = " 127.0.0.1" ;
53- int port = 3928 ;
47+ // // Check for port argument
48+ // if (argc > 3) {
49+ // port = std::atoi(argv[3]); // Convert string argument to int
50+ // }
51+ int thread_num = 1 ;
52+ std::string host = " 127.0.0.1" ;
53+ int port = 3928 ;
5454
55- int logical_cores = std::thread::hardware_concurrency ();
56- int drogon_thread_num = std::max (thread_num, logical_cores);
57- // cortex_utils::nitro_logo();
55+ int logical_cores = std::thread::hardware_concurrency ();
56+ int drogon_thread_num = std::max (thread_num, logical_cores);
57+ // cortex_utils::nitro_logo();
5858#ifdef CORTEX_CPP_VERSION
59- LOG_INFO << " cortex.cpp version: " << CORTEX_CPP_VERSION;
59+ LOG_INFO << " cortex.cpp version: " << CORTEX_CPP_VERSION;
6060#else
61- LOG_INFO << " cortex.cpp version: undefined" ;
61+ LOG_INFO << " cortex.cpp version: undefined" ;
6262#endif
6363
64- LOG_INFO << " Server started, listening at: " << host << " :" << port;
65- LOG_INFO << " Please load your model" ;
66- drogon::app ().addListener (host, port);
67- drogon::app ().setThreadNum (drogon_thread_num);
68- LOG_INFO << " Number of thread is:" << drogon::app ().getThreadNum ();
64+ LOG_INFO << " Server started, listening at: " << host << " :" << port;
65+ LOG_INFO << " Please load your model" ;
66+ drogon::app ().addListener (host, port);
67+ drogon::app ().setThreadNum (drogon_thread_num);
68+ LOG_INFO << " Number of thread is:" << drogon::app ().getThreadNum ();
6969
70- drogon::app ().run ();
71- // return 0;
70+ drogon::app ().run ();
71+ // return 0;
7272}
7373
7474void ForkProcess () {
@@ -80,19 +80,21 @@ void ForkProcess() {
8080 ZeroMemory (&si, sizeof (si));
8181 si.cb = sizeof (si);
8282 ZeroMemory (&pi, sizeof (pi));
83- std::string cmds = cortex_utils::GetCurrentPath () + " /cortex-cpp.exe --start-server" ;
83+ std::string cmds =
84+ cortex_utils::GetCurrentPath () + " /cortex-cpp.exe --start-server" ;
8485 // Create child process
8586 if (!CreateProcess (
8687 NULL , // No module name (use command line)
87- const_cast <char *>(cmds.c_str ()), // Command line (replace with your actual executable)
88- NULL , // Process handle not inheritable
89- NULL , // Thread handle not inheritable
90- FALSE , // Set handle inheritance to FALSE
91- 0 , // No creation flags
92- NULL , // Use parent's environment block
93- NULL , // Use parent's starting directory
94- &si, // Pointer to STARTUPINFO structure
95- &pi)) // Pointer to PROCESS_INFORMATION structure
88+ const_cast <char *>(
89+ cmds.c_str ()), // Command line (replace with your actual executable)
90+ NULL , // Process handle not inheritable
91+ NULL , // Thread handle not inheritable
92+ FALSE , // Set handle inheritance to FALSE
93+ 0 , // No creation flags
94+ NULL , // Use parent's environment block
95+ NULL , // Use parent's starting directory
96+ &si, // Pointer to STARTUPINFO structure
97+ &pi)) // Pointer to PROCESS_INFORMATION structure
9698 {
9799 std::cout << " Could not start server: " << GetLastError () << std::endl;
98100 } else {
0 commit comments