more benchmarks
This commit is contained in:
parent
ef78691f97
commit
89a6d9a528
6 changed files with 82 additions and 26 deletions
30
main.cpp
30
main.cpp
|
|
@ -5,6 +5,7 @@
|
|||
#include <netinet/in.h>
|
||||
#include <sstream>
|
||||
#include <sys/socket.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
@ -14,6 +15,15 @@ void log_request_an_response(http_request req, http_response resp);
|
|||
|
||||
constexpr int default_port = 80;
|
||||
|
||||
void handle_client(anthracite_socket s, file_backend fb)
|
||||
{
|
||||
http_request req(s);
|
||||
http_response resp = fb.handle_request(req);
|
||||
log_request_an_response(req, resp);
|
||||
s.send_message(resp.to_string());
|
||||
s.close_conn();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int port_number = default_port;
|
||||
|
|
@ -22,25 +32,21 @@ int main(int argc, char** argv)
|
|||
port_number = atoi(argv[1]);
|
||||
}
|
||||
|
||||
cout << "Initializing Anthracite\n";
|
||||
cout << "Initializing Anthracite" << endl;
|
||||
anthracite_socket s(port_number);
|
||||
cout << "Initialization Complete\n";
|
||||
cout << "Listening for HTTP connections on port " << port_number << "\n";
|
||||
file_backend fb;
|
||||
file_backend fb(false);
|
||||
cout << "Initialization Complete" << endl;
|
||||
cout << "Listening for HTTP connections on port " << port_number << endl;
|
||||
|
||||
while (true) {
|
||||
while(true) {
|
||||
s.wait_for_conn();
|
||||
http_request req(s);
|
||||
http_response resp = fb.handle_request(req);
|
||||
log_request_an_response(req, resp);
|
||||
s.send_message(resp.to_string());
|
||||
s.close_conn();
|
||||
thread(handle_client, s, ref(fb)).detach();
|
||||
}
|
||||
|
||||
return 0;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void log_request_an_response(http_request req, http_response resp)
|
||||
{
|
||||
cout << "[" << resp.status_code() << " " + http_status_map.find(resp.status_code())->second + "] " + req.client_ip() + " " + http_reverse_method_map.find(req.method())->second + " " + req.path() + "\n";
|
||||
cout << "[" << resp.status_code() << " " + http_status_map.find(resp.status_code())->second + "] " + req.client_ip() + " " + http_reverse_method_map.find(req.method())->second + " " + req.path() << endl;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue