From 5d3dda1df62d9b256a53356e155e3586e8f8d336 Mon Sep 17 00:00:00 2001 From: TriantaTV Date: Tue, 3 Oct 2023 23:06:11 -0500 Subject: [PATCH] Finished project on Linux --- src/network.cpp | 11 +++++++++-- src/proxy.cpp | 6 ------ src/web_server.cpp | 4 ++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/network.cpp b/src/network.cpp index b41bf77..f63dc8d 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -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 diff --git a/src/proxy.cpp b/src/proxy.cpp index 4b66ef9..3e60e83 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -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; diff --git a/src/web_server.cpp b/src/web_server.cpp index 6eaa5da..1df925c 100644 --- a/src/web_server.cpp +++ b/src/web_server.cpp @@ -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, " ");