58 lines
1.9 KiB
C++
58 lines
1.9 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* 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
|