From 5e0069871edad1cdf7b68608012064d6ec2aef85 Mon Sep 17 00:00:00 2001 From: Trimutex Date: Mon, 2 Oct 2023 13:10:33 -0500 Subject: [PATCH] Added some error checking --- src/network.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/network.cpp b/src/network.cpp index addff4d..237506b 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -1,6 +1,7 @@ #include "network.hpp" #include #include // Needed for exit() +#include // Needed for strcpy() and strlen() #include void HandleClient(int browser_s, int server_s) { @@ -9,16 +10,24 @@ void HandleClient(int browser_s, int server_s) { ssize_t buf_len; // Buffer length for file reads // Pass GET along from browser to server + std::cout << "Attempting to send to server" << std::endl; do { buf_len = recv(browser_s, in_buf, BUF_SIZE, 0); + if (buf_len == -1) { + std::cout << "ERROR - recv returned -1" << std::endl; + std::terminate(); + } send(server_s, in_buf, buf_len, 0); } while (buf_len != 0); + std::cout << "Sent to server" << std::endl; // Pass response along from server to browser + std::cout << "Attempting to send to browser" << std::endl; do { buf_len = recv(server_s, out_buf, BUF_SIZE, 0); send(browser_s, out_buf, buf_len, 0); } while (buf_len != 0); + std::cout << "Sent to browser" << std::endl; close(server_s); close(browser_s); }