-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebserver.cpp
More file actions
38 lines (34 loc) · 907 Bytes
/
Copy pathwebserver.cpp
File metadata and controls
38 lines (34 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "webserver.h"
/**
* @brief Constructs a WebServer object.
*/
WebServer::WebServer() : isBusy(false), remainingTime(0) {}
/**
* @brief Checks if the web server is available.
*
* @return True if the web server is available, false otherwise.
*/
bool WebServer::isAvailable() const {
return !isBusy;
}
/**
* @brief Processes a request by setting the server as busy and initializing the remaining time.
*
* @param request The request to be processed.
*/
void WebServer::processRequest(const Request& request) {
isBusy = true;
remainingTime = request.getTime();
}
/**
* @brief Ticks the server's clock, decrementing the remaining processing time.
* If the remaining time reaches zero, the server becomes available.
*/
void WebServer::tick() {
if (isBusy) {
remainingTime--;
if (remainingTime <= 0) {
isBusy = false;
}
}
}