Rework console input to use iostream

This commit is contained in:
Layla 2020-05-01 00:12:57 -04:00
parent 7ca5c63131
commit 6eaa057da8
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31

View File

@ -1,9 +1,9 @@
#ifndef CONSOLE_HPP #ifndef CONSOLE_HPP
#define CONSOLE_HPP #define CONSOLE_HPP
#include <stdio.h>
#include <pthread.h> #include <pthread.h>
#include <iostream> #include <iostream>
#include <string>
#include <cstring> #include <cstring>
@ -22,19 +22,24 @@ class ServerConsole
void * console_logic(void *) void * console_logic(void *)
{ {
printf("Started server console...\n"); std::cout << "Started server console..." << std::endl;
std::string input_string;
while(console_is_running) while(console_is_running)
{ {
char c [256]; if(!std::getline(std::cin, input_string))
fgets(c,sizeof(c), stdin); {
if(c[0] == 'q') std::cout << "Console I/O error!" << std::endl;
}
if(input_string == "stop")
{ {
console_is_running = false; console_is_running = false;
} }
else else
{ {
printf("Invalid console command!\n"); std::cout << "Invalid console command!" << std::endl;
} }
} }
return 0; return 0;