From 2363d60f2e46d5621898b925c1750cddb202a4a2 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Fri, 15 May 2020 19:27:42 +0200 Subject: detect file truncation We have to close the connection here to notify the client. --- hittpd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hittpd.c b/hittpd.c index 270f81b..6b295ee 100644 --- a/hittpd.c +++ b/hittpd.c @@ -804,14 +804,18 @@ write_client(int i) w = write(sockfd, buf, n); if (w > 0) data->off += w; - if (w == 0 || data->off == data->last) + if (data->off == data->last) finish_response(i); + else if (w == 0) + close_connection(i); // file was truncated! } #else w = sendfile(sockfd, data->stream_fd, &(data->off), data->last - data->off); - if (w == 0 || data->off == data->last) + if (data->off == data->last) finish_response(i); + else if (w == 0) + close_connection(i); // file was truncated! #endif } else if (data->buf) { if (data->off == data->last) { -- cgit 1.4.1