first commit: echo server

This commit is contained in:
Antonio Cossari
2026-09-07 00:45:35 +02:00
commit b15ce130f9
47 changed files with 2614 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Epoll.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acossari <acossari@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/08/26 11:34:23 by acossari #+# #+# */
/* Updated: 2026/08/26 11:34:25 by acossari ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <sys/epoll.h>
#include <array>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <span>
#include <string>
#include "net/FileDescriptor.hpp"
namespace webserv {
class Epoll final {
public:
class Error : public std::exception {
public:
explicit Error(std::string message);
const char* what() const noexcept override;
private:
std::string msg_;
};
// wait() returns at most this many ready events per call. Smaller batches
// require more calls, while larger batches delay the next loop iteration.
// The value is a middle ground. Excess events remain for later calls.
static constexpr std::size_t EVENT_BATCH_CAPACITY = 256;
Epoll();
void add(int fd, std::uint32_t events, std::uint64_t token);
void modify(int fd, std::uint32_t events, std::uint64_t token);
void remove(int fd) noexcept;
std::span<const epoll_event> wait(int timeoutMillis);
private:
FileDescriptor fd_;
std::array<epoll_event, EVENT_BATCH_CAPACITY> events_{};
};
} // namespace webserv