|
412 Project 3
|
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. | |
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.
| WebServer::WebServer | ( | ) |
Constructs a new WebServer object.
Initializes the server in an idle state.
| void WebServer::create_request | ( | Request & | request | ) |
Assigns a request to the server and marks it as busy.
| request | The request to be processed by the server. The request contains the incoming IP, outgoing IP, and the time required for processing. |
| 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.
| 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.
| time | The amount of time to process the request. |