Skip to content

Commit 49521b1

Browse files
fix: setting handler to done when read returns 0
1 parent 2cdf177 commit 49521b1

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/handler/static_file_handler.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ StaticFileHandler::StaticFileHandler(const std::string& path,
184184
out_off_(0),
185185
file_size_(0),
186186
fd_(-1),
187-
eof_(false)
187+
done_(false)
188188

189189
{
190190
struct ResolveResult r;
@@ -207,7 +207,7 @@ StaticFileHandler::StaticFileHandler(const std::string& path,
207207
HttpResponse::kStatusOk, "text/html; charset=UTF-8", html, req_);
208208

209209
out_buf_ = res_.to_string();
210-
eof_ = true;
210+
done_ = true;
211211
return;
212212
}
213213

@@ -245,11 +245,16 @@ size_t StaticFileHandler::read_output(char* buf, size_t n)
245245
}
246246
}
247247
if (fd_ == -1) // safeguard
248+
{
249+
done_ = true;
248250
return copied;
251+
}
252+
249253
ssize_t bytes = read(fd_, buf + copied, n - copied);
250254
if (bytes == 0) {
251255
close(fd_);
252256
fd_ = -1;
257+
done_ = true;
253258
return copied;
254259
}
255260
if (bytes < 0) {
@@ -271,7 +276,7 @@ void StaticFileHandler::set_error(const HttpResponse::Status code)
271276
{
272277
res_ = HttpResponse::make_error(code, rc_.shared.error_pages, req_);
273278
out_buf_ = res_.to_string();
274-
eof_ = true;
279+
done_ = true;
275280
}
276281

277282
void StaticFileHandler::set_redirect(const HttpResponse::Status code,
@@ -280,5 +285,5 @@ void StaticFileHandler::set_redirect(const HttpResponse::Status code,
280285
res_ = HttpResponse::make_response_headers_only(code, "", 0, req_);
281286
res_.location = redirect_path;
282287
out_buf_ = res_.to_string();
283-
eof_ = true;
288+
done_ = true;
284289
}

src/handler/static_file_handler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class StaticFileHandler : public Handler {
2828
virtual bool is_regular_file() const { return true; }
2929
virtual bool has_output() const { return out_off_ < out_buf_.size() || fd_ != -1; }
3030
virtual bool needs_input() const { return false; };
31-
virtual bool is_done() const { return eof_ && out_off_ >= out_buf_.size() && fd_ == -1; }
31+
virtual bool is_done() const { return done_ && out_off_ >= out_buf_.size() && fd_ == -1; }
3232

3333
virtual int cgi_read_fd() const { return -1; };
3434
virtual int cgi_write_fd() const { return -1; };
@@ -52,7 +52,7 @@ class StaticFileHandler : public Handler {
5252
// other handler specifc variables
5353
off_t file_size_;
5454
int fd_;
55-
bool eof_;
55+
bool done_;
5656
};
5757

5858
#endif

0 commit comments

Comments
 (0)