From 883310d241f58be0b44d1c87297a3868e665ff3e Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 3 Nov 2022 21:58:25 +0100 Subject: [PATCH] Fix bug --- include/webcxx/App.h | 2 +- src/App.cpp | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/webcxx/App.h b/include/webcxx/App.h index f68535a..c120bac 100644 --- a/include/webcxx/App.h +++ b/include/webcxx/App.h @@ -43,7 +43,7 @@ private: sockaddr_in m_addr; - int handle_request(Request& req); + int handle_request(Request& req, int fd); std::string get_client_addr(); diff --git a/src/App.cpp b/src/App.cpp index 01856bd..144b319 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -210,7 +210,7 @@ void webcxx::App::connection_thread() int status; - if((status = handle_request(req))) + if((status = handle_request(req, fd))) { return; } @@ -335,7 +335,7 @@ webcxx::Response webcxx::file(const std::string& item_path) return res; } -int webcxx::App::handle_request(Request& req) +int webcxx::App::handle_request(Request& req, int fd) { Response res(200); @@ -356,8 +356,8 @@ int webcxx::App::handle_request(Request& req) } catch (...) { res = error(500); req.log(res.status); - res.send(m_current_connection_fd); - close(m_current_connection_fd); + res.send(fd); + close(fd); close(m_socket_fd); std::rethrow_exception(std::current_exception()); } @@ -372,8 +372,8 @@ int webcxx::App::handle_request(Request& req) } catch (...) { res = error(500); req.log(res.status); - res.send(m_current_connection_fd); - close(m_current_connection_fd); + res.send(fd); + close(fd); close(m_socket_fd); std::rethrow_exception(std::current_exception()); } @@ -388,8 +388,8 @@ int webcxx::App::handle_request(Request& req) } catch (...) { res = error(500); req.log(res.status); - res.send(m_current_connection_fd); - close(m_current_connection_fd); + res.send(fd); + close(fd); close(m_socket_fd); std::rethrow_exception(std::current_exception()); } @@ -404,8 +404,8 @@ int webcxx::App::handle_request(Request& req) } catch (...) { res = error(500); req.log(res.status); - res.send(m_current_connection_fd); - close(m_current_connection_fd); + res.send(fd); + close(fd); close(m_socket_fd); std::rethrow_exception(std::current_exception()); } @@ -419,9 +419,9 @@ int webcxx::App::handle_request(Request& req) } req.log(res.status); - if (res.send(m_current_connection_fd) < 0) { + if (res.send(fd) < 0) { perror("send"); - close(m_current_connection_fd); + close(fd); close(m_socket_fd); return 1; }