Finished project on Linux

This commit is contained in:
TriantaTV 2023-10-03 23:06:11 -05:00
parent e6a1c34695
commit 5d3dda1df6
3 changed files with 13 additions and 8 deletions

View File

@ -32,9 +32,12 @@ void PipeSockets(int sender_s, int receiver_s) {
|| (strstr(in_buf, hazardous_contents_CS_02) != NULL)) {
std::cerr << "LOG (warn) - Hazardous contents detected" << std::endl;
strcpy(in_buf, FORBIDDEN_403);
send(receiver_s, in_buf, strlen(in_buf), 0);
send(sender_s, in_buf, strlen(in_buf), 0);
strcpy(in_buf, MESS_403);
send(receiver_s, in_buf, strlen(in_buf), 0);
send(sender_s, in_buf, strlen(in_buf), 0);
close(sender_s);
close(receiver_s);
return;
}
// Send
@ -50,6 +53,7 @@ void ProxySockets(int sender_s, int receiver_s) {
ssize_t buf_len; // Buffer length for file reads
// Pass response along from server to browser
sleep(1);
std::cout << "Attempting to send to browser" << std::endl;
do {
// Receive
@ -68,6 +72,9 @@ void ProxySockets(int sender_s, int receiver_s) {
send(receiver_s, out_buf, strlen(out_buf), 0);
strcpy(out_buf, MESS_403);
send(receiver_s, out_buf, strlen(out_buf), 0);
close(sender_s);
close(receiver_s);
return;
}
// Send

View File

@ -32,12 +32,6 @@ int main(void)
auto newThreadRequest2 = std::async(std::launch::async, ProxySockets, webserver.socketFD, browser.socketFD);
pending_futures.push_back(std::move(newThreadRequest1));
pending_futures.push_back(std::move(newThreadRequest2));
/*
auto newThreadRequest = std::async(std::launch::async, TestSockets, browser.socketFD, webserver.socketFD);
pending_futures.push_back(std::move(newThreadRequest));
std::cout << "Returned from creating threads, continuing..." << std::endl;
*/
//TestSockets(browser.socketFD, webserver.socketFD);
}
proxy.Close();
return 0;

View File

@ -122,6 +122,10 @@ void ClientRequest(int client_s) {
retcode = recv(client_s, in_buf, BUF_SIZE, 0);
if (retcode == -1) { std::cerr << "ERROR (info) - recv" << std::endl; }
if (retcode == 0) {
std::cout << "LOG (info) - Webserver received no data" << std::endl;
return;
}
// Handle the GET if there is one (see note #3 in the header)
// Parse out the filename from the GET request
strtok(in_buf, " ");