Skip to content

Commit 6e03842

Browse files
committed
Added test settings to config
1 parent 2c2b248 commit 6e03842

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ port=8000
22
log_path=./log
33
queue_size=10
44
config_test=Config Loaded, hello from server.cpp!
5+
start_full_server=false
56
;
67

78
Config manual:
89
; signals the end of the config file, anything below ; is ignored. WARNIRNG: has to be placed BELOW the final line
9-
= means that the following value will be converted to string
10-
//== means that the following value will be treated as int
10+
config_test - test setting for config, far from essential
11+
start_full_server - less hassle while testing logger

src/Config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void Config::loadConfigFileToMap(){
2121
int configFileDescriptor = open("./config", O_RDONLY);
2222
char configFileContents[CONFIG_SIZE];
2323
read(configFileDescriptor, &configFileContents, CONFIG_SIZE);
24+
close(configFileDescriptor);
2425

2526
//Removes everything after ; in config file
2627
configString = std::string(configFileContents);

src/server.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ int main() {
1616
// Init basic classes
1717
CmdLine cmdline;
1818
Config config;
19-
Logger logger(config.get_str_setting("log_path"), "Server");
19+
Logger logger(config.get_str_setting("log_path"), "Server");
20+
//"hello from server.cpp" message, to be removed
21+
logger.info(config.get_str_setting("config_test"));
2022

21-
// starting watching the incoming port using the router
22-
std::string port = config.get_str_setting("port");
23-
logger.info("Starting HackTTP at port: " + port);
24-
25-
//"hello from server.cpp" message, to be removed
26-
logger.info(config.get_str_setting("config_test"));
27-
Router router( config.get_int_setting("queue_size") );
28-
router.watch(port);
23+
if(config.get_str_setting("start_full_server") == "true") {
24+
// starting the full server
25+
std::string port = config.get_str_setting("port");
26+
logger.info("Starting HackTTP at port: " + port);
2927

28+
Router router(config.get_int_setting("queue_size"));
29+
router.watch(port);
30+
} else {
31+
logger.info("Running in test mode");
32+
}
3033
// cleanup
3134
logger.info("HackTTP shutting down");
3235

0 commit comments

Comments
 (0)