2026-10-23 18:20:04 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
// Minimal loopback HTTP/1.1 server for manual verification and the real-HTTP
|
|
|
|
|
// round-trip test. Sequential accept loop, static caps, no TLS, no HTTP/2.
|
|
|
|
|
// Gap: real event loop, timeouts, keep-alive, H2, and compression live in
|
|
|
|
|
// 01-runtime.md; this server exists only to prove the stack end to end.
|
|
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
#include "App.hpp"
|
|
|
|
|
|
|
|
|
|
namespace molo::example::fw {
|
|
|
|
|
|
|
|
|
|
class Server {
|
|
|
|
|
public:
|
|
|
|
|
explicit Server(std::shared_ptr<Application> app);
|
|
|
|
|
~Server();
|
|
|
|
|
|
|
|
|
|
Server(const Server&) = delete;
|
|
|
|
|
Server& operator=(const Server&) = delete;
|
|
|
|
|
|
2026-10-24 01:59:27 +02:00
|
|
|
// Optional sink for connection counters; set before start().
|
|
|
|
|
void set_stats(std::shared_ptr<Stats> stats);
|
2026-10-23 18:20:04 +02:00
|
|
|
bool start(const std::string& host, int port);
|
|
|
|
|
void stop();
|
|
|
|
|
int port() const;
|
|
|
|
|
bool running() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void loop();
|
2026-10-24 01:59:27 +02:00
|
|
|
void handle_one(int fd, std::size_t& bytes_in, std::size_t& bytes_out,
|
|
|
|
|
ConnEnd& how);
|
2026-10-23 18:20:04 +02:00
|
|
|
|
|
|
|
|
std::shared_ptr<Application> app_;
|
2026-10-24 01:59:27 +02:00
|
|
|
std::shared_ptr<Stats> stats_;
|
2026-10-23 18:20:04 +02:00
|
|
|
int listen_fd_ = -1;
|
|
|
|
|
int port_ = 0;
|
|
|
|
|
std::atomic<bool> running_{false};
|
|
|
|
|
std::thread worker_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::string http_roundtrip(const std::string& host, int port,
|
|
|
|
|
const std::string& raw_request);
|
|
|
|
|
|
|
|
|
|
} // namespace molo::example::fw
|