-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
43 feature create serversocket referring to config class #47
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directly printing to |
||
ssmap.insert(std::pair<int, ServerSocket>(ss.getFd(), ss)); | ||
} | ||
return true; | ||
Comment on lines
+6
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
|
||
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); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
loop(ssmap, config); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding default values ("0.0.0.0" for IP address and "8000" for port) within the
startUpServerSockets
function reduces flexibility. Move these defaults to a configuration class or a constants file to facilitate easier adjustments and maintainability.