From 12b952333e4bb81377e58ee1a80f18de1992085e Mon Sep 17 00:00:00 2001 From: Vinayak Ambigapathy Date: Tue, 18 Feb 2025 18:55:08 +0100 Subject: [PATCH] Initial commit --- app/src/app.cpp | 58 ++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/app/src/app.cpp b/app/src/app.cpp index 250bffa..e46f163 100644 --- a/app/src/app.cpp +++ b/app/src/app.cpp @@ -1,17 +1,19 @@ #include #include -#define minPort 8000 -#define maxPort 8000 -#define target "127.0.0.1" +#define MIN_PORT 8000 +#define MAX_PORT 8000 +#define RANGE MAX_PORT - MIN_PORT + 1 +#define TARGET "127.0.0.1" using namespace Bk; using namespace Bk::Net; struct Binder { - Scope src; - int port; + Scope src = nullptr; + Scope dest = nullptr; + int port = 0; Binder(Scope src, int port) :src(std::move(src)), port(port) { } @@ -20,40 +22,39 @@ struct Binder int main() { - Log::Init("Bakanet"); - //hostent* h = gethostbyname("localhost"); - //BK_INFO(std::string(h->h_addr_list[0], h->h_length)); - IpAddress ip("127.0.0.1"); - HttpServer server(ip, 8080); - server.get("/", [](HttpRequest& req) - { - HttpReponse res(HTTP_RES_200, req.version); - res.body = "

Bakanet

"; - res.body += "

Working http server

"; - res.body += "\n

URL /

"; - return res; - }); - server.start(); - return 0; + //Log::Init("Bakanet"); + ////hostent* h = gethostbyname("localhost"); + ////BK_INFO(std::string(h->h_addr_list[0], h->h_length)); + //IpAddress ip("127.0.0.1"); + //HttpServer server(ip, 8080); + //server.get("/", [](HttpRequest& req) + //{ + // HttpReponse res(HTTP_RES_200, req.version); + // res.body = "

Bakanet

"; + // res.body += "

Working http server

"; + // res.body += "\n

URL /

"; + // return res; + //}); + //server.start(); + //return 0; - /*Log::Init("Bakanet"); - IpAddress src("192.168.10.235"); + Log::Init("Bakanet"); + IpAddress src; ThreadPool pool(5); - int range = maxPort - minPort + 1; - int ports[maxPort - minPort + 1]; std::vector sockets; - sockets.reserve(range); + sockets.reserve(RANGE); - for (int i = 0; i < range; i++) + for (int i = 0; i < RANGE; i++) { - int port = minPort + i; + int port = MIN_PORT + i; Binder bind = { CreateScope(Socket::create(src, port, IpProtocol::TCP)), + port }; - if (!(bind.src->init() && bind.src->start(10))) throw new std::exception("Error"); + if (!(bind.src->init() && bind.src->start(10))) throw new std::exception(Tools::string_format("Couldn't bind on port %d", port)); sockets.push_back(bind); } @@ -87,5 +88,4 @@ int main() } } return 0; - */ } \ No newline at end of file