forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
67 lines (58 loc) · 1.68 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "utils/nitro_utils.h"
#include <climits> // for PATH_MAX
#include <drogon/HttpAppFramework.h>
#include <drogon/drogon.h>
#include <iostream>
#if defined(__APPLE__) && defined(__MACH__)
#include <libgen.h> // for dirname()
#include <mach-o/dyld.h>
#elif defined(__linux__)
#include <libgen.h> // for dirname()
#include <unistd.h> // for readlink()
#elif defined(_WIN32)
#include <windows.h>
#undef max
#else
#error "Unsupported platform!"
#endif
int main(int argc, char *argv[]) {
int thread_num = 1;
std::string host = "127.0.0.1";
int port = 3928;
std::string uploads_folder_path;
// Number of nitro threads
if (argc > 1) {
thread_num = std::atoi(argv[1]);
}
// Check for host argument
if (argc > 2) {
host = argv[2];
}
// Check for port argument
if (argc > 3) {
port = std::atoi(argv[3]); // Convert string argument to int
}
// Uploads folder path
if (argc > 4) {
uploads_folder_path = argv[4];
}
int logical_cores = std::thread::hardware_concurrency();
int drogon_thread_num = std::max(thread_num, logical_cores);
nitro_utils::nitro_logo();
#ifdef NITRO_VERSION
LOG_INFO << "Nitro version: " << NITRO_VERSION;
#else
LOG_INFO << "Nitro version: undefined";
#endif
LOG_INFO << "Server started, listening at: " << host << ":" << port;
LOG_INFO << "Please load your model";
drogon::app().addListener(host, port);
drogon::app().setThreadNum(drogon_thread_num);
if (!uploads_folder_path.empty()) {
LOG_INFO << "Drogon uploads folder is at: " << uploads_folder_path;
drogon::app().setUploadPath(uploads_folder_path);
}
LOG_INFO << "Number of thread is:" << drogon::app().getThreadNum();
drogon::app().run();
return 0;
}