Skip to content

Commit 19dfb92

Browse files
committed
refactor: changed from jthread to async
1 parent acdfc8d commit 19dfb92

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

include/teapot.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <optional>
1414
#include <unordered_map>
1515
#include <memory>
16+
#include <future>
1617

1718
#include "middleware.hpp"
1819
#include "cors_middleware.hpp"
@@ -68,7 +69,7 @@ namespace tpt
6869

6970
std::optional<Request> parseRequest(int client_socket);
7071
std::string determineContentType(const std::string &uri);
71-
void mainEventLoop(SOCKET client_socket);
72+
void requestHandler(SOCKET client_socket);
7273

7374
public:
7475
Teapot();

src/teapot.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ std::string Teapot::determineContentType(const std::string &uri)
6565
return "text/plain";
6666
}
6767

68-
void Teapot::mainEventLoop(SOCKET client_socket)
68+
void Teapot::requestHandler(SOCKET client_socket)
6969
{
7070
auto context = std::make_unique<Context>(nullptr, nullptr);
7171
auto request = parseRequest(client_socket);
@@ -224,7 +224,8 @@ void Teapot::run()
224224
try
225225
{
226226
socket.acceptConnection(client_socket, client_addr);
227-
std::jthread th(&Teapot::mainEventLoop, this, client_socket);
227+
auto res = std::async(std::launch::async, &Teapot::requestHandler, this, client_socket);
228+
// std::jthread th(&Teapot::requestHandler, this, client_socket);
228229
}
229230
catch (IPBlackListedException &e)
230231
{

0 commit comments

Comments
 (0)