#include <ServerManager.hpp>
|
| int | _createListeningSocket (const struct sockaddr_in &addr) |
| | Creates, binds, listens, and sets O_NONBLOCK on a socket.
|
| |
| void | _acceptNewConnections (int listenFd) |
| | Accepts all pending connections on a listening fd. Sets each client fd to O_NONBLOCK and adds it to _pollfds.
|
| |
| bool | _readAndPrint (int fd) |
| | Reads from a client fd and prints the raw data.
|
| |
| void | _handleConnection (Connection *conn, uint32_t events) |
| | Dispatches epoll events to the correct Connection handler and drives state transitions. Called from run() for every client event.
|
| |
| void | _runRoundRobin () |
| | Runs a budgeted round-robin pass over _processingQueue. Calls process() once per connection, re-enqueues if still PROCESSING, budgeted to BACKLOG/2 per tick, which is arbitrary, tune as needed.
|
| |
| void | _dropConnection (int fd) |
| | Closes a client fd and removes it from epoll and _connections.
|
| |
| void | _enqueueProcessing (Connection *conn) |
| | Adds a connection to the processing queue if not already queued.
|
| |
| void | _dequeueProcessing (Connection *conn) |
| | Removes a connection from the processing set (queue cleanup is lazy).
|
| |
| void | _finalizeProcessed (Connection *conn) |
| | Handles state transition for a connection that just left PROCESSING.
|
| |
| void | _sweepTimeouts () |
| | Scans all connections and drops any that have been idle too long.
|
| |
| void | _registerCgiPipe (Connection *conn) |
| | Registers a CGI pipe fd in epoll and maps it to its Connection.
|
| |
| void | _unregisterCgiPipe (int pipeFd) |
| | Unregisters a CGI pipe fd from epoll and removes the mapping.
|
| |
| void | _handleCgiPipeEvent (int pipeFd, uint32_t events) |
| | Handles an epoll event on a CGI pipe fd.
|
| |
| void | _sweepCgiTimeouts () |
| | Sweeps CGI processes for timeout.
|
| |
| void | _closeAllFds () |
| | Closes all fds (listeners + clients) during shutdown.
|
| |
Definition at line 40 of file ServerManager.hpp.
◆ ServerManager() [1/3]
| ServerManager::ServerManager |
( |
| ) |
|
◆ ServerManager() [2/3]
| ServerManager::ServerManager |
( |
std::vector< ServerConf > |
confs | ) |
|
◆ ServerManager() [3/3]
◆ ~ServerManager()
| ServerManager::~ServerManager |
( |
| ) |
|
◆ operator=()
◆ addServer()
| void ServerManager::addServer |
( |
const ServerConf * |
conf | ) |
|
Creates a listening socket for the given ServerConf's IP:Port and registers the mapping.
- Parameters
-
| conf | Pointer to the configuration block (pointer used to avoid heavy copying). |
- Exceptions
-
Definition at line 107 of file ServerManager.cpp.
◆ addListenPort()
| void ServerManager::addListenPort |
( |
int |
port | ) |
|
Temporary overload for early development: creates a listening socket on the given port bound to INADDR_ANY, with no ServerConf mapping.
listen without needing a conf file.
Definition at line 122 of file ServerManager.cpp.
◆ run()
| void ServerManager::run |
( |
| ) |
|
Enters the main epoll() event loop. Blocks until g_running becomes false.
Definition at line 143 of file ServerManager.cpp.
◆ addPollFd()
| void ServerManager::addPollFd |
( |
int |
fd, |
|
|
uint32_t |
events |
|
) |
| |
Adds or updates an fd in the epoll list (e.g., CGI output pipe).
- Parameters
-
| fd | The file descriptor to monitor. |
| events | EPOLLIN/EPOLLOUT mask to apply. |
Definition at line 247 of file ServerManager.cpp.
◆ getServerConfForFd()
| const ServerConf * ServerManager::getServerConfForFd |
( |
int |
clientFd | ) |
const |
Uses getsockname() to find the local address of a client fd, then returns the matching ServerConf.
- Parameters
-
| clientFd | The file descriptor returned by accept(). |
- Returns
- const ServerConf* Pointer to the matching configuration, or NULL if not found.
Definition at line 268 of file ServerManager.cpp.
◆ _createListeningSocket()
| int ServerManager::_createListeningSocket |
( |
const struct sockaddr_in & |
addr | ) |
|
|
private |
Creates, binds, listens, and sets O_NONBLOCK on a socket.
- Returns
- The listening fd.
- Exceptions
-
Definition at line 284 of file ServerManager.cpp.
◆ _acceptNewConnections()
| void ServerManager::_acceptNewConnections |
( |
int |
listenFd | ) |
|
|
private |
Accepts all pending connections on a listening fd. Sets each client fd to O_NONBLOCK and adds it to _pollfds.
Definition at line 318 of file ServerManager.cpp.
◆ _readAndPrint()
| bool ServerManager::_readAndPrint |
( |
int |
fd | ) |
|
|
private |
Reads from a client fd and prints the raw data.
- Returns
- false if the client disconnected or errored, true otherwise.
Definition at line 356 of file ServerManager.cpp.
◆ _handleConnection()
| void ServerManager::_handleConnection |
( |
Connection * |
conn, |
|
|
uint32_t |
events |
|
) |
| |
|
private |
Dispatches epoll events to the correct Connection handler and drives state transitions. Called from run() for every client event.
Definition at line 192 of file ServerManager.cpp.
◆ _runRoundRobin()
| void ServerManager::_runRoundRobin |
( |
| ) |
|
|
private |
Runs a budgeted round-robin pass over _processingQueue. Calls process() once per connection, re-enqueues if still PROCESSING, budgeted to BACKLOG/2 per tick, which is arbitrary, tune as needed.
- Warning
- tribute to Prof.waleed al-maqableh.
Definition at line 405 of file ServerManager.cpp.
◆ _dropConnection()
| void ServerManager::_dropConnection |
( |
int |
fd | ) |
|
|
private |
Closes a client fd and removes it from epoll and _connections.
Definition at line 374 of file ServerManager.cpp.
◆ _enqueueProcessing()
| void ServerManager::_enqueueProcessing |
( |
Connection * |
conn | ) |
|
|
private |
Adds a connection to the processing queue if not already queued.
Definition at line 394 of file ServerManager.cpp.
◆ _dequeueProcessing()
| void ServerManager::_dequeueProcessing |
( |
Connection * |
conn | ) |
|
|
private |
Removes a connection from the processing set (queue cleanup is lazy).
Definition at line 400 of file ServerManager.cpp.
◆ _finalizeProcessed()
| void ServerManager::_finalizeProcessed |
( |
Connection * |
conn | ) |
|
|
private |
Handles state transition for a connection that just left PROCESSING.
Definition at line 449 of file ServerManager.cpp.
◆ _sweepTimeouts()
| void ServerManager::_sweepTimeouts |
( |
| ) |
|
|
private |
Scans all connections and drops any that have been idle too long.
Definition at line 578 of file ServerManager.cpp.
◆ _registerCgiPipe()
| void ServerManager::_registerCgiPipe |
( |
Connection * |
conn | ) |
|
|
private |
◆ _unregisterCgiPipe()
| void ServerManager::_unregisterCgiPipe |
( |
int |
pipeFd | ) |
|
|
private |
Unregisters a CGI pipe fd from epoll and removes the mapping.
Definition at line 481 of file ServerManager.cpp.
◆ _handleCgiPipeEvent()
| void ServerManager::_handleCgiPipeEvent |
( |
int |
pipeFd, |
|
|
uint32_t |
events |
|
) |
| |
|
private |
◆ _sweepCgiTimeouts()
| void ServerManager::_sweepCgiTimeouts |
( |
| ) |
|
|
private |
◆ _closeAllFds()
| void ServerManager::_closeAllFds |
( |
| ) |
|
|
private |
Closes all fds (listeners + clients) during shutdown.
need to rename this. its growing to an all encompassing cleanup function.
Definition at line 606 of file ServerManager.cpp.
◆ _interfacePortPairs
◆ _serverConfs
| std::vector<ServerConf*> ServerManager::_serverConfs |
|
private |
◆ _processingQueue
| std::deque<Connection*> ServerManager::_processingQueue |
|
private |
◆ _processingSet
| std::set<Connection*> ServerManager::_processingSet |
|
private |
◆ _connections
| std::map<int, Connection*> ServerManager::_connections |
|
private |
◆ _cgiPipeToConn
| std::map<int, Connection*> ServerManager::_cgiPipeToConn |
|
private |
◆ _cgiStartTimes
| std::map<int, time_t> ServerManager::_cgiStartTimes |
|
private |
◆ _epollFd
| int ServerManager::_epollFd |
|
private |
◆ _eventBuffer
| std::vector<struct epoll_event> ServerManager::_eventBuffer |
|
private |
◆ _fdEvents
| std::map<int, uint32_t> ServerManager::_fdEvents |
|
private |
◆ _listenFds
| std::set<int> ServerManager::_listenFds |
|
private |
◆ _listenFdToServerConf
| std::map<int, const ServerConf*> ServerManager::_listenFdToServerConf |
|
private |
The documentation for this class was generated from the following files: