Cade Royal CSCE 412 Project 3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
WebServer Class Reference

A class that represents a web server handling HTTP requests. More...

#include <WebServer.h>

Public Member Functions

 WebServer (std::mutex &coutMutex_)
 Constructor to initialize the WebServer with a mutex for output synchronization.
 
 ~WebServer ()
 Destructor to clean up resources used by the WebServer.
 
void start ()
 Starts the web server in a separate thread.
 
void assignRequest (const Request &req)
 Assigns a request to the web server for processing.
 
void stop ()
 Stops the web server and joins the server thread.
 
bool isRunning ()
 Checks if the web server is currently running.
 
bool hasRequest ()
 Checks if the server currently has a request assigned.
 
void printDetails ()
 Prints details about the web server's status and configuration.
 

Detailed Description

A class that represents a web server handling HTTP requests.

The WebServer class encapsulates the logic for processing incoming requests in a separate thread. It includes methods for starting and stopping the server, assigning requests, and checking the server's status.

Constructor & Destructor Documentation

◆ WebServer()

WebServer::WebServer ( std::mutex &  coutMutex)

Constructor to initialize the WebServer with a mutex for output synchronization.

Constructs a WebServer object.

Parameters
coutMutex_A reference to a mutex to ensure thread-safe output to the console.

Initializes the server with a random IP address, sets it to running, and creates a default Request object.

Parameters
coutMutexReference to the mutex used for thread-safe console output.

◆ ~WebServer()

WebServer::~WebServer ( )

Destructor to clean up resources used by the WebServer.

Destructor for WebServer.

Joins the server thread before destruction to ensure proper cleanup.

Member Function Documentation

◆ assignRequest()

void WebServer::assignRequest ( const Request req)

Assigns a request to the web server for processing.

Assigns a Request object to the WebServer.

Parameters
reqThe Request object to be processed by the server.

This function assigns a new Request to the server and notifies the server thread to process it.

Parameters
reqThe Request object to be processed.

◆ hasRequest()

bool WebServer::hasRequest ( )

Checks if the server currently has a request assigned.

Checks if the web server has a pending request.

Returns
True if there is an assigned request, false otherwise.
True if there is a request pending, false otherwise.

◆ isRunning()

bool WebServer::isRunning ( )

Checks if the web server is currently running.

Returns
True if the server is running, false otherwise.
True if the server is running, false otherwise.

◆ printDetails()

void WebServer::printDetails ( )

Prints details about the web server's status and configuration.

Prints the details of the web server.

This function outputs the web server's IP address and running status to the console.

◆ start()

void WebServer::start ( )

Starts the web server in a separate thread.

Starts the web server.

This function creates a new thread that runs the run() function of the WebServer.

◆ stop()

void WebServer::stop ( )

Stops the web server and joins the server thread.

Stops the web server.

This function sets the running flag to false, signaling the server to stop.


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