Webserv
Loading...
Searching...
No Matches
network::Reactor Class Reference

Manages the full lifecycle of a single client connection. More...

#include <Reactor.hpp>

Inheritance diagram for network::Reactor:
network::AEventHandler

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 &)
Reactoroperator= (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 ()

Detailed Description

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.

Constructor & Destructor Documentation

◆ Reactor() [1/2]

network::Reactor::Reactor ( int clientFd,
int port,
http::Router const & router )

◆ ~Reactor()

network::Reactor::~Reactor ( )

◆ Reactor() [2/2]

network::Reactor::Reactor ( const Reactor & )
private

Member Function Documentation

◆ clearResponseBuffer()

void network::Reactor::clearResponseBuffer ( )
private

Clears the response buffer and resets sent byte count.

◆ closeConnection()

void network::Reactor::closeConnection ( )
private

Closes the connection and removes it from the dispatcher.

◆ generateResponse()

void network::Reactor::generateResponse ( )
private

Processes a fully parsed request to generate a response.

◆ getHandle()

int network::Reactor::getHandle ( ) const
virtual

◆ handleEvent()

void network::Reactor::handleEvent ( uint32_t events)
virtual

◆ handleRead()

void network::Reactor::handleRead ( )
private

Handles incoming data on the socket.

◆ handleWrite()

void network::Reactor::handleWrite ( )
private

Handles outgoing data on the socket.

◆ operator=()

Reactor & network::Reactor::operator= ( const Reactor & )
private

◆ resetForNewRequest()

void network::Reactor::resetForNewRequest ( )
private

Resets the reactor state for a new request (keep-alive).

◆ sendResponseBuffer()

bool network::Reactor::sendResponseBuffer ( )
private

Sends the contents of the response buffer.

Returns
False on fatal error.

◆ tryParseHeaders()

void network::Reactor::tryParseHeaders ( )
private

Attempts to parse headers from the request buffer.

Member Data Documentation

◆ bodyStart_

size_t network::Reactor::bodyStart_
private

Start position of the body in requestBuffer_.

◆ clientFd_

int network::Reactor::clientFd_
private

◆ contentLength_

size_t network::Reactor::contentLength_
private

Expected length of the request body.

◆ IO_BUFFER_SIZE

const size_t network::Reactor::IO_BUFFER_SIZE = 8192
staticprivate

Size for read/write chunks.

◆ port_

int network::Reactor::port_
private

◆ requestBuffer_

std::string network::Reactor::requestBuffer_
private

Buffer for incoming request data.

◆ requestState_

RequestState network::Reactor::requestState_
private

The current state of request parsing.

◆ response_

http::HttpResponse network::Reactor::response_
private

The HTTP response being prepared/sent.

◆ responseBuffer_

std::vector<char> network::Reactor::responseBuffer_
private

Buffer for the outgoing response.

◆ responseState_

ResponseState network::Reactor::responseState_
private

The current state of response sending.

◆ router_

http::Router const& network::Reactor::router_
private

◆ sentResponseBytes_

size_t network::Reactor::sentResponseBytes_
private

Number of bytes sent from responseBuffer_.


The documentation for this class was generated from the following files: