a few upgrades for the HttpServer example (#955)

This commit is contained in:
rimmartin
2019-10-29 19:28:11 +01:00
committed by Alex Hultman
parent 8af994f713
commit 4a9ab556bd
3 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
#include <experimental/filesystem>
#include <filesystem>
struct AsyncFileStreamer {
@@ -12,7 +12,7 @@ struct AsyncFileStreamer {
void updateRootCache() {
// todo: if the root folder changes, we want to reload the cache
for(auto &p : std::experimental::filesystem::recursive_directory_iterator(root)) {
for(auto &p : std::filesystem::recursive_directory_iterator(root)) {
std::string url = p.path().string().substr(root.length());
if (url == "/index.html") {
url = "/";
@@ -38,7 +38,7 @@ struct AsyncFileStreamer {
static void streamFile(uWS::HttpResponse<SSL> *res, AsyncFileReader *asyncFileReader) {
/* Peek from cache */
std::string_view chunk = asyncFileReader->peek(res->getWriteOffset());
if (!chunk.length() || res->tryEnd(chunk, asyncFileReader->getFileSize())) {
if (!chunk.length() || res->tryEnd(chunk, asyncFileReader->getFileSize()).first) {
/* Request new chunk */
// todo: we need to abort this callback if peer closed!
// this also means Loop::defer needs to support aborting (functions should embedd an atomic boolean abort or something)