From ac43595b0212f349934d7ab0a6612b9ec82d2e77 Mon Sep 17 00:00:00 2001 From: Noah Ravaux Date: Sat, 23 Dec 2023 13:22:53 +0100 Subject: [PATCH] server draft --- .gitignore | 3 ++- src/api/api.h | 30 +++++++++++++++++++++++++++++- src/cu_submitter.cpp | 8 +++----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 5410b14..3afad25 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ _deps .idea/ build/ -cmake-build-debug/ \ No newline at end of file +cmake-build-debug/ +cmake-build-debug-wsl/ \ No newline at end of file diff --git a/src/api/api.h b/src/api/api.h index 4e554f3..c15c1f5 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -22,8 +22,36 @@ class CUSubmitterHandler : public Http::Handler { void onRequest(const Http::Request& request, Http::ResponseWriter response) override { logRequest(request); - response.send(Http::Code::Ok, "CU Submitter backend is reponding\n"); + if (request.resource() == "/" && request.method() == Http::Method::Get) { + response.send(Http::Code::Ok, "CU Submitter backend is reponding\n"); + } else { + response.send(Http::Code::Not_Found); + } } }; +class CUSubmitterService { +public: + explicit CUSubmitterService(Address addr) + : server(std::make_shared(addr)) {} + + void init(size_t thr = 2) { + auto opts = Http::Endpoint::options().threads(static_cast(thr)); + + server->init(opts); + server->setHandler(Http::make_handler()); + } + + void start() { + server->serve(); + } + + void shutdown() { + server->shutdown(); + } + +private: + std::shared_ptr server; +}; + #endif //CU_SUBMITTER_API_H \ No newline at end of file diff --git a/src/cu_submitter.cpp b/src/cu_submitter.cpp index 21b2c0b..9828a33 100644 --- a/src/cu_submitter.cpp +++ b/src/cu_submitter.cpp @@ -130,10 +130,8 @@ int main(int argc, char* argv[]) Address addr(Ipv4::any(), Port(stoi(port))); - auto opts = Http::Endpoint::options().threads(1); - Http::Endpoint server(addr); + CUSubmitterService service(addr); + service.init(); - server.init(opts); - server.setHandler(Http::make_handler()); - server.serve(); + service.start(); }