|
Cade Royal CSCE 412 Project 3
|
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. | |
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.
| WebServer::WebServer | ( | std::mutex & | coutMutex | ) |
Constructor to initialize the WebServer with a mutex for output synchronization.
Constructs a WebServer object.
| 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.
| coutMutex | Reference to the mutex used for thread-safe console output. |
| WebServer::~WebServer | ( | ) |
| void WebServer::assignRequest | ( | const Request & | req | ) |
Assigns a request to the web server for processing.
Assigns a Request object to the WebServer.
| req | The 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.
| req | The Request object to be processed. |
| bool WebServer::hasRequest | ( | ) |
Checks if the server currently has a request assigned.
Checks if the web server has a pending request.
| bool WebServer::isRunning | ( | ) |
Checks if the web server is currently running.
| 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.
| 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.
| 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.