From 0823ce2894746823995fed325ab514f3f135a867 Mon Sep 17 00:00:00 2001 From: adjoly Date: Thu, 22 May 2025 17:37:37 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fixed?= =?UTF-8?q?=20throw=20with=20client=20in=20main=20loop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/Client.cpp | 4 ++-- src/server/Server.cpp | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/server/Client.cpp b/src/server/Client.cpp index 3ce85f3..fc61f51 100644 --- a/src/server/Client.cpp +++ b/src/server/Client.cpp @@ -6,7 +6,7 @@ /* By: mmoussou getHeader("Host"); bool ret = _conf->isServerName(host.substr(0, host.find(':'))); if (ret == false) { - throw std::runtime_error("serverName nor correcponding"); + throw std::runtime_error("serverName not correcponding"); } } diff --git a/src/server/Server.cpp b/src/server/Server.cpp index 13e1c6a..eff9099 100644 --- a/src/server/Server.cpp +++ b/src/server/Server.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */ -/* Updated: 2025/05/19 15:11:00 by adjoly ### ########.fr */ +/* Updated: 2025/05/22 17:36:13 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -176,7 +176,23 @@ void Server::_run(void) { _log->error("client does not exist"); continue; } - client->parse(); + try { + client->parse(); + } catch (std::exception &e) { + _log->error(e.what()); + _client_data.erase(std::find(_client_data.begin(), + _client_data.end(), client)); + delete client; + for (auto it = range(_client_fds)) { + if (_client_fds[i].fd == (*it).fd) { + _log->debug("client fds erased"); + close(it.base()->fd); + _client_fds.erase(it); + break; + } + } + i--; + } } else if (_client_fds[i].revents & POLLOUT) { std::stringstream str; str << _client_fds[i].fd;