Skip to content

Commit

Permalink
refactor: changed from jthread to async
Browse files Browse the repository at this point in the history
  • Loading branch information
araujo88 committed Mar 25, 2024
1 parent acdfc8d commit 19dfb92
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/teapot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <optional>
#include <unordered_map>
#include <memory>
#include <future>

#include "middleware.hpp"
#include "cors_middleware.hpp"
Expand Down Expand Up @@ -68,7 +69,7 @@ namespace tpt

std::optional<Request> parseRequest(int client_socket);
std::string determineContentType(const std::string &uri);
void mainEventLoop(SOCKET client_socket);
void requestHandler(SOCKET client_socket);

public:
Teapot();
Expand Down
5 changes: 3 additions & 2 deletions src/teapot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::string Teapot::determineContentType(const std::string &uri)
return "text/plain";
}

void Teapot::mainEventLoop(SOCKET client_socket)
void Teapot::requestHandler(SOCKET client_socket)
{
auto context = std::make_unique<Context>(nullptr, nullptr);
auto request = parseRequest(client_socket);
Expand Down Expand Up @@ -224,7 +224,8 @@ void Teapot::run()
try
{
socket.acceptConnection(client_socket, client_addr);
std::jthread th(&Teapot::mainEventLoop, this, client_socket);
auto res = std::async(std::launch::async, &Teapot::requestHandler, this, client_socket);
// std::jthread th(&Teapot::requestHandler, this, client_socket);
}
catch (IPBlackListedException &e)
{
Expand Down

0 comments on commit 19dfb92

Please sign in to comment.