mirror of
https://github.com/Mercantec-GHC/h5-projekt-mst.git
synced 2026-08-27 05:37:39 +02:00
backend: push http progress
This commit is contained in:
parent
c7adfaf96a
commit
3cc6303f92
23
backend/src/http.cpp
Normal file
23
backend/src/http.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "http.hpp"
|
||||
|
||||
namespace mst {
|
||||
auto HttpServer::start() -> Result<void>
|
||||
{
|
||||
while (1) {
|
||||
auto res = this->listener.accept();
|
||||
if (res) { }
|
||||
}
|
||||
};
|
||||
|
||||
auto HttpServer::bind(const std::string& host, uint16_t port)
|
||||
-> Result<HttpServer>
|
||||
{
|
||||
auto x = TcpListener::bind(host, port);
|
||||
|
||||
if (!x) {
|
||||
return std::unexpected(std::move(x.error()));
|
||||
}
|
||||
|
||||
return HttpServer(*x);
|
||||
}
|
||||
}
|
||||
36
backend/src/http.hpp
Normal file
36
backend/src/http.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "tcp.hpp"
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <netinet/in.h>
|
||||
#include <string>
|
||||
|
||||
namespace mst {
|
||||
template <typename T> using Result = std::expected<T, std::string>;
|
||||
|
||||
class HttpServer;
|
||||
|
||||
class HttpDaemon {
|
||||
|
||||
public:
|
||||
HttpDaemon(HttpServer&, TcpConnection connection)
|
||||
: connection(connection) { };
|
||||
|
||||
private:
|
||||
TcpConnection connection;
|
||||
};
|
||||
|
||||
class HttpServer {
|
||||
|
||||
public:
|
||||
auto start() -> Result<void>;
|
||||
static auto bind(const std::string& host, uint16_t port)
|
||||
-> Result<HttpServer>;
|
||||
|
||||
private:
|
||||
HttpServer(TcpListener listener)
|
||||
: listener(listener) { };
|
||||
TcpListener listener;
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user