Added basic multi-threading

multi_plaform
anulax1225 ago%!(EXTRA string=1 year)
parent 1a64a6bb47
commit a9b47c4a74
  1. 16
      bakanet/src/bakanet/http/http_server.cpp
  2. 6
      bakanet/src/bakanet/http/http_server.h

@ -11,13 +11,10 @@ namespace Bk::Net {
while (running)
{
auto conn = socket->ack();
threads.emplace_back(std::thread([&](Socket& conn)
{
log("Caca")
route_request(conn, recv_request(conn));
log("Pipi")
}, std::ref(*conn)));
threads.push_back(std::thread([this](std::unique_ptr<Socket> conn)
{
route_request(*conn, recv_request(*conn));
}, std::move(conn)));
}
}
@ -25,16 +22,13 @@ namespace Bk::Net {
{
Packet req;
bool reading = true;
log("Proute")
while(reading)
{
auto data = conn.obtain(1024);
int size = data.size();
log("SIZE " << data.size())
req.append_data(data);
reading = data.size() >= 1024;
}
log("Cul")
int req_size = req.size();
if (req_size) return HttpRequest(std::string(req.pull<char>(req_size).release(), req_size));
return HttpRequest("", "", "");
@ -50,8 +44,6 @@ namespace Bk::Net {
void HttpServer::route_request(Socket& conn, HttpRequest req)
{
log("to string")
log(req.to_string())
if(req_mapper[req.url]) send_reponse(conn, req_mapper[req.url](req));
else send_reponse(conn, HttpReponse(HTTP_RES_404, "HTTP/1.1"));
}

@ -1,9 +1,9 @@
#pragma once
#include <bakanetpch.h>
#include <bakanet/sock_layer/ip_address.h>
#include <bakanet/sock_layer/packet.h>
#include <bakanet/sock_layer/socket.h>
#include <bakanet/core/ip_address.h>
#include <bakanet/core/packet.h>
#include <bakanet/core/socket.h>
#include "http_packet.h"
namespace Bk::Net {

Loading…
Cancel
Save