Skip to content

Commit b176285

Browse files
committed
Fixing some rookie logic bugs. Fully functional fileserver example here!
1 parent 7f21db4 commit b176285

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libs/network/example/http/fileserver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ struct file_cache {
4545

4646
bool add(std::string const & path) {
4747
boost::upgrade_lock<boost::shared_mutex> lock(cache_mutex);
48-
if (regions.find(doc_root_ + path) != regions.end()) return true;
4948
std::string real_filename = doc_root_+path;
49+
if (regions.find(real_filename) != regions.end()) return true;
5050
int fd = open(real_filename.c_str(), O_RDONLY|O_NOATIME|O_NONBLOCK);
5151
if (fd == -1) return false;
5252
std::size_t size = lseek(fd, 0, SEEK_END);
@@ -91,8 +91,8 @@ struct connection_handler : boost::enable_shared_from_this<connection_handler> {
9191
: file_cache_(cache) {}
9292

9393
void operator()(std::string const & path, server::connection_ptr connection, bool serve_body) {
94-
bool ok = false;
95-
if (!file_cache_.has(path)) ok = file_cache_.add(path);
94+
bool ok = file_cache_.has(path);
95+
if (!ok) ok = file_cache_.add(path);
9696
if (ok) {
9797
send_headers(file_cache_.meta(path), connection);
9898
if (serve_body) send_file(file_cache_.get(path), 0, connection);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy