proxy-network/src/proxy.cpp

40 lines
1.3 KiB
C++

//----- Include files ---------------------------------------------------------
#include <algorithm>
#include <cstring>
#include <future>
#include <iostream>
#include <vector>
#include "network.hpp"
int main(void)
{
strcpy(hazardous_contents_CS_01, "password.txt");
strcpy(hazardous_contents_CS_02, "admin.config");
std::vector<std::future<void>> pending_futures;
Server proxy(kProxyPort);
Client browser;
Client webserver;
// Main loop to listen, accept, and then spin-off a thread to handle the GET
while (1)
{
if (browser.ConnectFrom(proxy.socketFD) != 0)
{
std::cerr << "ERROR - Unable to create socket to client" << std::endl;
continue;
}
if (webserver.ConnectTo(kWebserverPort) != 0)
{
std::cerr << "ERROR - Unable to connect to webserver" << std::endl;
continue;
}
auto newThreadRequest1 = std::async(std::launch::async, PipeSockets, browser.socketFD, webserver.socketFD);
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));
}
proxy.Close();
return 0;
}