Some progress may have been made, but its still blocking unexpectedly

This commit is contained in:
TriantaTV 2023-10-03 13:04:22 -05:00
parent f8f03bb5ee
commit 42bf316ccb
3 changed files with 53 additions and 8 deletions

View File

@ -4,6 +4,41 @@
#include <string.h> // Needed for strcpy() and strlen()
#include <iostream>
void TestSockets(int sender_s, int receiver_s) {
char in_buf[BUF_SIZE]; // Input buffer for GET resquest
char out_buf[BUF_SIZE]; // Output buffer for HTML response
ssize_t buf_len; // Buffer length for file reads
//
// Pass GET along from browser to server
std::cout << "Attempting to send data to receiver" << std::endl;
do {
buf_len = recv(sender_s, in_buf, BUF_SIZE, 0);
if (buf_len == -1) {
std::cout << "ERROR (info) - recv" << std::endl;
}
if (buf_len == 0) { continue; }
send(receiver_s, in_buf, buf_len, 0);
std::cout << "LOG (info) - pipe packet size: " << buf_len << std::endl;
} while (buf_len > 0);
std::cout << "Sent data to receiver" << std::endl;
// Pass response along from server to browser
std::cout << "Attempting to send to browser" << std::endl;
do {
buf_len = recv(receiver_s, out_buf, BUF_SIZE, 0);
if (buf_len == -1) {
std::cout << "ERROR (info) - recv" << std::endl;
break;
}
if (buf_len == 0) { continue; }
send(sender_s, out_buf, buf_len, 0);
std::cout << "LOG (info) - proxy packet size: " << buf_len << std::endl;
} while (buf_len > 0);
std::cout << "Sent to browser" << std::endl;
close(sender_s);
close(receiver_s);
}
void PipeSockets(int sender_s, int receiver_s) {
char in_buf[BUF_SIZE]; // Input buffer for GET resquest
ssize_t buf_len; // Buffer length for file reads
@ -12,13 +47,15 @@ void PipeSockets(int sender_s, int receiver_s) {
std::cout << "Attempting to send data to receiver" << std::endl;
do {
buf_len = recv(sender_s, in_buf, BUF_SIZE, 0);
std::cout << "LOG (info) - pipe packet recv size: " << buf_len << std::endl;
if (buf_len == -1) {
std::cout << "ERROR (info) - recv" << std::endl;
std::terminate();
return;
}
send(receiver_s, in_buf, buf_len, 0);
std::cout << "LOG (info) - pipe packet size: " << buf_len << std::endl;
} while (buf_len > 0);
if (buf_len == 0) { break; }
buf_len = send(receiver_s, in_buf, buf_len, 0);
std::cout << "LOG (info) - pipe packet send size: " << buf_len << std::endl;
} while (buf_len < BUF_SIZE);
std::cout << "Sent data to receiver" << std::endl;
}
@ -31,13 +68,15 @@ void ProxySockets(int sender_s, int receiver_s) {
std::cout << "Attempting to send to browser" << std::endl;
do {
buf_len = recv(sender_s, out_buf, BUF_SIZE, 0);
std::cout << "LOG (info) - proxy packet recv size: " << buf_len << std::endl;
if (buf_len == -1) {
std::cout << "ERROR (info) - recv" << std::endl;
std::terminate();
return;
}
send(receiver_s, out_buf, buf_len, 0);
std::cout << "LOG (info) - proxy packet size: " << buf_len << std::endl;
} while (buf_len > 0);
if (buf_len == 0) { break; }
buf_len = send(receiver_s, out_buf, buf_len, 0);
std::cout << "LOG (info) - proxy packet send size: " << buf_len << std::endl;
} while (buf_len < BUF_SIZE);
std::cout << "Sent to browser" << std::endl;
close(sender_s);
close(receiver_s);

View File

@ -10,6 +10,7 @@
#define kWebserverIP "127.0.0.1"
#define kWebserverPort 7080
void TestSockets(int sender_s, int receiver_s);
void PipeSockets(int sender_s, int receiver_s);
void ProxySockets(int sender_s, int receiver_s);

View File

@ -35,7 +35,12 @@ 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;