Added an update interval setting to the web server. Also update will get called if it's > 0.

This commit is contained in:
Relintai 2022-02-10 16:59:31 +01:00
parent 26d161fd26
commit e705cbca34
3 changed files with 41 additions and 32 deletions

View File

@ -28,6 +28,7 @@ void WebServer::handle_request(Request *request) {
WebServer::WebServer() : NodeTree() { WebServer::WebServer() : NodeTree() {
_web_root = nullptr; _web_root = nullptr;
_update_interval = 0.5;
} }
WebServer::~WebServer() { WebServer::~WebServer() {

View File

@ -21,7 +21,7 @@ public:
protected: protected:
WebNode *_web_root; WebNode *_web_root;
float _update_interval;
}; };
#endif #endif

View File

@ -12,8 +12,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "core/net/tcp_connection.h"
#include "core/log/async_file_logger.h" #include "core/log/async_file_logger.h"
#include "core/net/tcp_connection.h"
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -209,6 +209,14 @@ void DrogonWebServer::run() {
_beginning_advices.clear(); _beginning_advices.clear();
}); });
if (_update_interval > 0) {
get_loop()->runEvery(_update_interval, [this]() {
this->update();
});
}
//
get_loop()->loop(); get_loop()->loop();
} }