|
Webserv
|
Manages the full lifecycle of a single client connection. More...
#include <ClientHandler.hpp>
Classes | |
| struct | CgiState |
| struct | SendBuffer |
Public Member Functions | |
| ClientHandler (int clientFd, int port, std::string const &clientAddr, http::Router const &) | |
| virtual | ~ClientHandler () |
| virtual void | handleEvent (uint32_t events) |
| virtual int | getFd () const |
| void | pushToSendBuffer (const char *data, size_t length) |
| Pushes data into the client's send buffer. This is called by the CGIHandler when it reads from the pipe. | |
| bool | isSendBufferFull () const |
| Checks if the send buffer is over its high-water mark. This is the backpressure mechanism. | |
| void | onCgiComplete () |
| Called by CGIHandler when the CGI script finishes (EOF). | |
| void | onCgiHeadersParsed (http::Headers const &) |
| Notification that CGI headers have been fully parsed. | |
| void | handleError (http::HttpStatus) |
| Triggers an error response (e.g., 404, 500). | |
| Public Member Functions inherited from network::IEventHandler | |
| virtual | ~IEventHandler () |
Private Member Functions | |
| void | handleRead () |
| Handles incoming data on the socket. | |
| void | handleDraining () |
| void | handleStaticResponseWrite () |
| Handles outgoing data on the socket. | |
| void | handleCgiResponseWrite () |
| void | generateResponse () |
| Processes a fully parsed request to generate a response. | |
| void | handleRequestParsingState (http::RequestParser::State state) |
| bool | setupCgiHandler (http::IResponseBody *body) |
| void | setupStaticResponse () |
| void | resetForNewRequest () |
| Resets the ClientHandler state for a new request (keep-alive). | |
| void | closeConnection () |
| Closes the connection and removes it from the dispatcher. | |
| void | initiateDraining () |
| void | finalizeConnection () |
| ClientHandler (const ClientHandler &) | |
| ClientHandler & | operator= (const ClientHandler &) |
| std::string | getLogSignature () const |
Private Attributes | |
| int | clientFd_ |
| int | port_ |
| std::string | clientAddr_ |
| bool | headersSent_ |
| http::Router const & | router_ |
| http::Request | request_ |
| http::Response | response_ |
| http::RequestParser | reqParser_ |
| bool | isKeepAlive_ |
| bool | isDraining_ |
| std::time_t | drainStartTime_ |
| SendBuffer | rspBuffer_ |
| CgiState | cgiState_ |
Static Private Attributes | |
| static const size_t | IO_BUFFER_SIZE = 8192 |
Additional Inherited Members | |
| Protected Member Functions inherited from network::IEventHandler | |
| IEventHandler () | |
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::ClientHandler::ClientHandler | ( | int | clientFd, |
| int | port, | ||
| std::string const & | clientAddr, | ||
| http::Router const & | router ) |
|
virtual |
|
private |
|
private |
Closes the connection and removes it from the dispatcher.
|
private |
|
private |
Processes a fully parsed request to generate a response.
|
virtual |
Implements network::IEventHandler.
|
private |
|
private |
|
private |
| void network::ClientHandler::handleError | ( | http::HttpStatus | status | ) |
Triggers an error response (e.g., 404, 500).
|
virtual |
Implements network::IEventHandler.
|
private |
Handles incoming data on the socket.
|
private |
|
private |
Handles outgoing data on the socket.
|
private |
| bool network::ClientHandler::isSendBufferFull | ( | ) | const |
Checks if the send buffer is over its high-water mark. This is the backpressure mechanism.
| void network::ClientHandler::onCgiComplete | ( | ) |
Called by CGIHandler when the CGI script finishes (EOF).
| void network::ClientHandler::onCgiHeadersParsed | ( | http::Headers const & | headers | ) |
Notification that CGI headers have been fully parsed.
|
private |
| void network::ClientHandler::pushToSendBuffer | ( | const char * | data, |
| size_t | length ) |
Pushes data into the client's send buffer. This is called by the CGIHandler when it reads from the pipe.
|
private |
Resets the ClientHandler state for a new request (keep-alive).
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |