412 Project 3
Loading...
Searching...
No Matches
WebServer Class Reference

The WebServer class simulates a server that processes network requests. More...

#include <WebServer.h>

Public Member Functions

 WebServer ()
 Constructs a new WebServer object.
 
void create_request (Request &request)
 Assigns a request to the server and marks it as busy.
 
void process_request (int time)
 Processes the current request for the specified time.
 
void finish_request ()
 Marks the current request as finished and sets the server to idle.
 

Public Attributes

Request curr_request
 The current request being processed by the server.
 
int time_left
 The remaining time to finish the current request.
 
int time_idle
 The amount of time the server has been idle.
 
bool busy
 Indicates whether the server is currently busy.
 

Detailed Description

The WebServer class simulates a server that processes network requests.

A WebServer can handle a single request at a time, and tracks the time left to process the current request. It also keeps track of its idle time when not processing requests.

Constructor & Destructor Documentation

◆ WebServer()

WebServer::WebServer ( )

Constructs a new WebServer object.

Initializes the server in an idle state.

Member Function Documentation

◆ create_request()

void WebServer::create_request ( Request & request)

Assigns a request to the server and marks it as busy.

Parameters
requestThe request to be processed by the server. The request contains the incoming IP, outgoing IP, and the time required for processing.

◆ finish_request()

void WebServer::finish_request ( )

Marks the current request as finished and sets the server to idle.

Prints a message indicating that the server has completed the request.

◆ process_request()

void WebServer::process_request ( int time)

Processes the current request for the specified time.

Decreases the time left on the request by the given time unit. If the request is finished (time_left <= 0), the server marks the request as completed. If no request is being processed, the server remains idle and increments its idle time counter.

Parameters
timeThe amount of time to process the request.

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