-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebproxy.cpp
More file actions
36 lines (36 loc) · 1.09 KB
/
Copy pathwebproxy.cpp
File metadata and controls
36 lines (36 loc) · 1.09 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
#include "debug.h"
#include "netutils.h"
#include "signal.h"
#include "utils.h"
#include <iostream>
#include <thread>
int cache_timeout;
int main(int argc, char** argv)
{
u_short listen_fd, port, conn_fd, timeout;
struct sockaddr_in remote_addr;
socklen_t addr_size = sizeof(struct sockaddr_in);
if (argc < 3 || argc > 3) {
Utils::print_error("USAGE: <PORT> <TIMEOUT>");
exit(EXIT_FAILURE);
}
int n = 1;
std::string file_path = "BLOCKED";
NetUtils::fill_block_ip(file_path);
port = (u_short)strtoul(argv[1], NULL, 0);
timeout = (u_short)strtoul(argv[2], NULL, 0);
listen_fd = NetUtils::create_socket(port);
Utils::set_cache_timeout(timeout);
signal(SIGPIPE, SIG_IGN);
while (true) {
debug("Waiting to accept connection");
if ((conn_fd = accept(listen_fd, (struct sockaddr*)&remote_addr, &addr_size)) < 0) {
Utils::print_error_with_message("Error Accepting Connection");
}
debugs("Accepted Connection", conn_fd);
//NetUtils::spawn_request_handler(conn_fd);
std::thread t(&NetUtils::spawn_request_handler, conn_fd);
t.detach();
}
return 0;
}