Skip to content

Commit

Permalink
Merge pull request #47 from ilovenoah/43-feature-create-serversocket-…
Browse files Browse the repository at this point in the history
…referring-to-config-class

43 feature create serversocket referring to config class
  • Loading branch information
ilovenoah authored Feb 5, 2024
2 parents f01f30d + c2ccc70 commit 1240db0
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
#include "ServerSocket.hpp"
#include "loop.hpp"

// int main(int argc, const char *argv[]) {
// Config config;

// config.setServers(argc, argv);
// startServerLoop(config);
// return (0);
// }
static bool startUpServerSockets(std::map<int, ServerSocket> &ssmap, Config &config) {
std::vector<Server> servers(config.getServers());
for (std::vector<Server>::iterator iter = servers.begin(); iter != servers.end(); ++iter) {
std::string ipAddr = iter->getIpAddress();
std::string port = iter->getPort();
if (ipAddr.empty() == true) { ipAddr = "0.0.0.0"; }
if (port.empty() == true) { port = "8000"; }
ServerSocket ss(ipAddr, port);
if (ss.init() == false) { return false; }
std::cout << "Start up server: " << ipAddr << ":" << port << std::endl;
ssmap.insert(std::pair<int, ServerSocket>(ss.getFd(), ss));
}
return true;
}

int main(int argc, const char *argv[]) {
ServerSocket ss("127.0.0.1", "8080");
std::map<int, ServerSocket> ssmap;
Config config;

config.setServers(argc, argv);
ss.init();
std::map<int, ServerSocket> ssmap;
ssmap.insert(std::pair<int, ServerSocket>(ss.getFd(), ss));
bool test = loop(ssmap, config);
(void)test;
if (startUpServerSockets(ssmap, config) == false) { exit(1); }
loop(ssmap, config);
}

0 comments on commit 1240db0

Please sign in to comment.