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
+56
View File
@@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* EventToken.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acossari <acossari@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/08/25 13:26:42 by acossari #+# #+# */
/* Updated: 2026/08/25 19:06:13 by acossari ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <cstdint>
namespace webserv {
enum class EndpointKind {
ClientSocket,
CgiStdin,
CgiStdout,
Listener,
};
// Identifies which registered endpoint produced an epoll event without storing
// a pointer. For Listener, index selects a listener; for every other kind it
// selects a connection slot, while kind identifies its client socket or CGI
// pipe. epoll_wait() returns a batch in which an old event may remain after its
// endpoint has been retired and re-registered. generation distinguishes that
// old registration from the current one even when index and kind are equal.
//
// Packed layout in epoll_event.data.u64:
// bits 0-29 | index | 30 bits
// bits 30-31 | kind | 2 bits
// bits 32-63 | generation | 32 bits
struct EventToken {
static constexpr std::uint64_t INDEX_BITS = 30;
static constexpr std::uint64_t KIND_BITS = 2;
// List-initialization gives 1 the exact std::uint32_t type before shifting.
// std::uint32_t{1} << INDEX_BITS = 1,073,741,824
// (std::uint32_t{1} << INDEX_BITS) - 1 = 1,073,741,823
// Binary: 100...000 (30 zeros) - 1 = 011...111 (30 ones).
static constexpr std::uint32_t MAX_INDEX =
(std::uint32_t{1} << INDEX_BITS) - 1;
std::uint32_t index;
EndpointKind kind;
std::uint32_t generation;
};
std::uint64_t pack(EventToken token);
EventToken unpack(std::uint64_t token);
} // namespace webserv