Webserv
|
Manages the full lifecycle of a single client connection. More...
#include <Reactor.hpp>
Public Member Functions | |
Reactor (int clientFd, int port, http::Router const &) | |
~Reactor () | |
virtual void | handleEvent (uint32_t events) |
virtual int | getHandle () const |
Public Member Functions inherited from network::AEventHandler | |
virtual | ~AEventHandler () |
Private Member Functions | |
Reactor (const Reactor &) | |
Reactor & | operator= (const Reactor &) |
void | handleRead () |
Handles incoming data on the socket. | |
void | handleWrite () |
Handles outgoing data on the socket. | |
void | tryParseHeaders () |
Attempts to parse headers from the request buffer. | |
void | generateResponse () |
Processes a fully parsed request to generate a response. | |
bool | sendResponseBuffer () |
Sends the contents of the response buffer. | |
void | clearResponseBuffer () |
Clears the response buffer and resets sent byte count. | |
void | resetForNewRequest () |
Resets the reactor state for a new request (keep-alive). | |
void | closeConnection () |
Closes the connection and removes it from the dispatcher. |
Private Attributes | |
int | clientFd_ |
int | port_ |
http::Router const & | router_ |
http::HttpResponse | response_ |
The HTTP response being prepared/sent. | |
RequestState | requestState_ |
The current state of request parsing. | |
std::string | requestBuffer_ |
Buffer for incoming request data. | |
size_t | bodyStart_ |
Start position of the body in requestBuffer_. | |
size_t | contentLength_ |
Expected length of the request body. | |
std::vector< char > | responseBuffer_ |
Buffer for the outgoing response. | |
ResponseState | responseState_ |
The current state of response sending. | |
size_t | sentResponseBytes_ |
Number of bytes sent from responseBuffer_. |
Static Private Attributes | |
static const size_t | IO_BUFFER_SIZE = 8192 |
Size for read/write chunks. |
Additional Inherited Members | |
Protected Member Functions inherited from network::AEventHandler | |
AEventHandler () |
Manages the full lifecycle of a single client connection.
This class acts as a state machine for a client, handling I/O events via epoll. It reads and parses HTTP requests, dispatches them to a router, and manages sending the response back to the client, including streaming large files. Each instance corresponds to one connected client socket.
network::Reactor::Reactor | ( | int | clientFd, |
int | port, | ||
http::Router const & | router ) |
network::Reactor::~Reactor | ( | ) |
|
private |
|
private |
Clears the response buffer and resets sent byte count.
|
private |
Closes the connection and removes it from the dispatcher.
|
private |
Processes a fully parsed request to generate a response.
|
virtual |
Implements network::AEventHandler.
|
virtual |
Implements network::AEventHandler.
|
private |
Handles incoming data on the socket.
|
private |
Handles outgoing data on the socket.
|
private |
Resets the reactor state for a new request (keep-alive).
|
private |
Sends the contents of the response buffer.
|
private |
Attempts to parse headers from the request buffer.
|
private |
Start position of the body in requestBuffer_.
|
private |
|
private |
Expected length of the request body.
|
staticprivate |
Size for read/write chunks.
|
private |
|
private |
Buffer for incoming request data.
|
private |
The current state of request parsing.
|
private |
The HTTP response being prepared/sent.
|
private |
Buffer for the outgoing response.
|
private |
The current state of response sending.
|
private |
|
private |
Number of bytes sent from responseBuffer_.