Add thread cli option

This commit is contained in:
Tyler Perkins 2022-04-30 14:41:17 -04:00
parent d2ad27ea3b
commit 7e8f1e30b7
3 changed files with 10 additions and 2 deletions

View File

@ -28,7 +28,7 @@ int main(int argc, char** argv){
app.port(flags->port)
.server_name(flags->name)
.multithreaded();
.concurrency(flags->threads);
delete flags;

View File

@ -13,6 +13,7 @@ void help(char* progName){
std::cout << " [-n NAME] Server name (Default \"proc-api\")\n";
std::cout << " [-a PATH] Path to file containing authorization tokens\n";
std::cout << " If the -a flag is not passed, no authorization is used\n";
std::cout << " [-t THREADS] Number of threads to use. By default, uses 2 threads\n";
std::cout << " [-h] Display this help message\n\n";
exit(1);
}
@ -23,6 +24,7 @@ option_flags* parse_options(int argc, char** argv){
option_flags* ret = new option_flags;
ret->port = 5000;
ret->threads = 2;
ret->name = "proc-api";
ret->auth_path = "";
@ -37,6 +39,11 @@ option_flags* parse_options(int argc, char** argv){
case 'a':
ret->auth_path = std::string(optarg);
break;
case 't':
ret->threads = atoi(optarg);
if(ret->threads == 0)
ret->threads = 1;
break;
case '?':
std::cerr << "Unkown option: " << (char)optopt << "\n";
case 'h':

View File

@ -12,10 +12,11 @@
///////////////////////////////////////
// cli options
constexpr char optarg_string[] = "n:p:a:h";
constexpr char optarg_string[] = "n:p:a:t:h";
struct option_flags {
uint16_t port;
uint16_t threads;
std::string name;
std::string auth_path;
};