summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--hittpd.c8
1 files 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) {