-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (66 loc) · 2.36 KB
/
Copy pathmain.cpp
File metadata and controls
77 lines (66 loc) · 2.36 KB
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
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include "utility/xml/Parser.h"
#include "utility/json/Parser.h"
#include "utility/ini/IniFile.h"
#include "utility/logger/Logger.h"
#include "utility/Singleton.h"
#include "server/Server.h"
#include "utility/System.h"
using namespace crab;
void test();
int main() {
// test();
Singleton<System>::instance()->init();
auto ini = Singleton<ini::IniFile>::instance();
const std::string &ip = ini->get("server", "ip");
int port = ini->get("server", "port");
int threads = ini->get("server", "threads");
int max_conn = ini->get("server", "max_conn");
int wait_time = ini->get("server", "wait_time");
if (max_conn <= threads) {
max_conn = threads;
warn("max_conn is smaller than the number of threads, so change it to the number of threads:%d", threads);
}
auto server = Singleton<server::Server>::instance();
server->set_threads(threads);
server->set_connects(max_conn);
server->set_wait_time(wait_time);
server->listen(ip, port);
server->start();
return 0;
}
void test() {
std::cout << "===============test logger===============" << std::endl;
crab::logger::Logger::instance()->open("../test_logger.log");
debug("test logger");
std::cout << "===============test server===============" << std::endl;
auto serv = Singleton<server::Server>::instance();
serv->set_threads(1000);
serv->set_connects(10000);
serv->set_wait_time(10);
serv->listen("0.0.0.0", 8080);
serv->start();
//xml
std::cout << "===============test xml===============" << std::endl;
crab::xml::Parser xml_parser;
xml_parser.load_file("../utility/xml/test.xml");
xml_parser.parse();
//json
std::cout << "===============test json===============" << std::endl;
crab::json::Parser json_parser;
crab::json::Json j1;
crab::json::Json j2 = crab::json::Json(true);
crab::json::Json j3 = crab::json::Json(1111);
crab::json::Json j4 = crab::json::Json(1.111);
crab::json::Json j5 = crab::json::Json("c++");
bool b = j2.asBool();
int i = j3.asInt();
double d = j4.asDouble();
const std::string &s = j5.asString();
std::cout << b << i << s << std::endl;
//ini
std::cout << "===============test init===============" << std::endl;
crab::ini::IniFile ini_file;
ini_file.load_file("../utility/ini/test.ini");
ini_file.show();
}