diff --git a/exemples/test.toml b/exemples/test.toml index a513196..8c0d802 100644 --- a/exemples/test.toml +++ b/exemples/test.toml @@ -2,7 +2,7 @@ log_file = "test.log" [server] server_names = { "localhost", "2B5.local" } -host = "localhost" +host = "0.0.0.0" port = 8080 [server.error_pages] diff --git a/src/server/Server.cpp b/src/server/Server.cpp index 2484109..976b9b6 100644 --- a/src/server/Server.cpp +++ b/src/server/Server.cpp @@ -6,12 +6,13 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */ -/* Updated: 2025/04/22 15:40:59 by adjoly ### ########.fr */ +/* Updated: 2025/04/22 16:34:40 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include #include +#include #include #include #include @@ -145,8 +146,12 @@ void Server::_run(void) { Server::Server(config::Config *conf) : _conf(conf) { log("➕", "Server::Server", "config constructor called"); _log = conf->getLogger(); - _setup(); - _run(); + try { + _setup(); + _run(); + } catch (std::exception &e) { + _log->error(e.what()); + } } Server::~Server(void) { diff --git a/src/server/ServerUtils.cpp b/src/server/ServerUtils.cpp index e8c3a83..9fc4dd4 100644 --- a/src/server/ServerUtils.cpp +++ b/src/server/ServerUtils.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */ -/* Updated: 2025/04/22 16:14:36 by adjoly ### ########.fr */ +/* Updated: 2025/04/22 16:32:45 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,7 +58,9 @@ int Server::_createSocket(std::string host, int port) { struct sockaddr_in addr; addr.sin_family = AF_INET; - convertStringToIP(host.c_str(), &addr.sin_addr); + if (!convertStringToIP(host.c_str(), &addr.sin_addr)) { + throw std::runtime_error("ip is not of the valid format : " + host); + } std::stringstream str; str << port; _log->debug("port : " + str.str());