From b4eb64ca3f79bfc8fa10e873dd20073dfe4d44ee Mon Sep 17 00:00:00 2001 From: adjoly Date: Tue, 22 Apr 2025 16:35:52 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20correct?= =?UTF-8?q?ed=20issue=20with=20ip=20in=20the=20main=20loop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exemples/test.toml | 2 +- src/server/Server.cpp | 11 ++++++++--- src/server/ServerUtils.cpp | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-) 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());