LeftHookRoll
An HTTP/1.0 compliant web server, as specified by RFC1945
Loading...
Searching...
No Matches
Connection Class Reference

#include <Connection.hpp>

Collaboration diagram for Connection:

Public Member Functions

 Connection ()
 
 Connection (int fd, const struct sockaddr_in &ipa, const ServerConf *defaultConfig)
 
 Connection (const Connection &other)
 
Connectionoperator= (const Connection &other)
 
 ~Connection ()
 
void handleRead ()
 Reads data from the client socket using recv() into _readBuffer. Transitions state to PROCESSING if the request is fully received.
 
void process ()
 Executes routing logic, instantiates the Response, and prepares data for sending. Transitions state to WRITING or handles CGI setup based on LocationConf.
 
void handleWrite ()
 Writes data from the _writeBuffer (or Response) to the client socket using send(). Transitions state to FINISHED when the transaction is completely sent.
 
bool hasTimedOut (int timeoutSeconds) const
 Checks if the connection has exceeded the defined timeout threshold.
 
void triggerError (int statusCode)
 Forces the connection into an error state, bypassing normal processing.
 
int getFd () const
 
ConnectionState getState () const
 
void setState (ConnectionState state)
 
ResponsegetResponse () const
 
RequestgetRequest () const
 
const ServerConfgetServerConf () const
 
int getCgiPipeFd () const
 Returns the CGI output pipe fd, or -1 if no CGI is active.
 
void setLocationConf (const LocationConf *conf)
 Assigns the appropriate location block after parsing the request URI.
 

Private Member Functions

void _updateActivityTimer ()
 Updates the _lastActivity timestamp to current time.
 
void _readHeaders (const char *buf, size_t n)
 
void _readBody (const char *buf, size_t n)
 
void _readChunked (const char *buf, size_t n)
 

Private Attributes

int _acceptFD
 
struct sockaddr_in _IPA
 
time_t _lastActivity
 
const ServerConf_serverConf
 
const LocationConf_locationConf
 
size_t _readBufferSize
 
std::string _readBuffer
 
Request_request
 
Response_response
 
size_t _writeBufferSize
 
std::string _writeBuffer
 
ConnectionState _state
 
size_t _totalBytesRead
 

Detailed Description

Definition at line 33 of file Connection.hpp.

Constructor & Destructor Documentation

◆ Connection() [1/3]

Connection::Connection ( )

Definition at line 14 of file Connection.cpp.

◆ Connection() [2/3]

Connection::Connection ( int  fd,
const struct sockaddr_in &  ipa,
const ServerConf defaultConfig 
)

Definition at line 31 of file Connection.cpp.

◆ Connection() [3/3]

Connection::Connection ( const Connection other)

Definition at line 51 of file Connection.cpp.

◆ ~Connection()

Connection::~Connection ( )

Definition at line 92 of file Connection.cpp.

Member Function Documentation

◆ operator=()

Connection & Connection::operator= ( const Connection other)

Definition at line 70 of file Connection.cpp.

◆ handleRead()

void Connection::handleRead ( )

Reads data from the client socket using recv() into _readBuffer. Transitions state to PROCESSING if the request is fully received.

Definition at line 180 of file Connection.cpp.

◆ process()

void Connection::process ( )

Executes routing logic, instantiates the Response, and prepares data for sending. Transitions state to WRITING or handles CGI setup based on LocationConf.

Definition at line 210 of file Connection.cpp.

◆ handleWrite()

void Connection::handleWrite ( )

Writes data from the _writeBuffer (or Response) to the client socket using send(). Transitions state to FINISHED when the transaction is completely sent.

Definition at line 268 of file Connection.cpp.

◆ hasTimedOut()

bool Connection::hasTimedOut ( int  timeoutSeconds) const

Checks if the connection has exceeded the defined timeout threshold.

Parameters
timeoutSecondsThe maximum allowed idle time in seconds.
Returns
true if timed out, false otherwise.

Definition at line 279 of file Connection.cpp.

◆ triggerError()

void Connection::triggerError ( int  statusCode)

Forces the connection into an error state, bypassing normal processing.

Parameters
statusCodeThe HTTP status code to generate (e.g., 400, 408, 500).

Definition at line 284 of file Connection.cpp.

◆ getFd()

int Connection::getFd ( ) const

Definition at line 99 of file Connection.cpp.

◆ getState()

ConnectionState Connection::getState ( ) const

Definition at line 100 of file Connection.cpp.

◆ setState()

void Connection::setState ( ConnectionState  state)

Definition at line 101 of file Connection.cpp.

◆ getResponse()

Response * Connection::getResponse ( ) const

Definition at line 102 of file Connection.cpp.

◆ getRequest()

Request * Connection::getRequest ( ) const

Definition at line 103 of file Connection.cpp.

◆ getServerConf()

const ServerConf * Connection::getServerConf ( ) const

Definition at line 104 of file Connection.cpp.

◆ getCgiPipeFd()

int Connection::getCgiPipeFd ( ) const

Returns the CGI output pipe fd, or -1 if no CGI is active.

Definition at line 107 of file Connection.cpp.

◆ setLocationConf()

void Connection::setLocationConf ( const LocationConf conf)

Assigns the appropriate location block after parsing the request URI.

Parameters
confThe correctly matched location configuration.

Definition at line 105 of file Connection.cpp.

◆ _updateActivityTimer()

void Connection::_updateActivityTimer ( )
private

Updates the _lastActivity timestamp to current time.

Definition at line 114 of file Connection.cpp.

◆ _readHeaders()

void Connection::_readHeaders ( const char *  buf,
size_t  n 
)
private

Definition at line 119 of file Connection.cpp.

◆ _readBody()

void Connection::_readBody ( const char *  buf,
size_t  n 
)
private

Definition at line 165 of file Connection.cpp.

◆ _readChunked()

void Connection::_readChunked ( const char *  buf,
size_t  n 
)
private

Definition at line 172 of file Connection.cpp.

Member Data Documentation

◆ _acceptFD

int Connection::_acceptFD
private

Definition at line 98 of file Connection.hpp.

◆ _IPA

struct sockaddr_in Connection::_IPA
private

Definition at line 99 of file Connection.hpp.

◆ _lastActivity

time_t Connection::_lastActivity
private

Definition at line 100 of file Connection.hpp.

◆ _serverConf

const ServerConf* Connection::_serverConf
private

Definition at line 103 of file Connection.hpp.

◆ _locationConf

const LocationConf* Connection::_locationConf
private

Definition at line 104 of file Connection.hpp.

◆ _readBufferSize

size_t Connection::_readBufferSize
private

Definition at line 107 of file Connection.hpp.

◆ _readBuffer

std::string Connection::_readBuffer
private

Definition at line 108 of file Connection.hpp.

◆ _request

Request* Connection::_request
private

Definition at line 110 of file Connection.hpp.

◆ _response

Response* Connection::_response
private

Definition at line 111 of file Connection.hpp.

◆ _writeBufferSize

size_t Connection::_writeBufferSize
private

Definition at line 113 of file Connection.hpp.

◆ _writeBuffer

std::string Connection::_writeBuffer
private

Definition at line 114 of file Connection.hpp.

◆ _state

ConnectionState Connection::_state
private

Definition at line 117 of file Connection.hpp.

◆ _totalBytesRead

size_t Connection::_totalBytesRead
private

Definition at line 118 of file Connection.hpp.


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