summary refs log tree commit diff
path: root/hittpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'hittpd.c')
-rw-r--r--hittpd.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/hittpd.c b/hittpd.c
index 9ddd2c4..3bc6bc6 100644
--- a/hittpd.c
+++ b/hittpd.c
@@ -854,7 +854,21 @@ write_client(int i)
 	ssize_t w = 0;
 
 	if (data->stream_fd >= 0) {
-#ifndef __linux__
+#ifdef __linux__
+		w = sendfile(sockfd, data->stream_fd,
+		    &(data->off), data->last - data->off);
+		if (data->off == data->last) {
+			finish_response(i);
+			return;
+		} else if (w == 0) {
+			close_connection(i);  // file was truncated!
+			return;
+		} else if (w > 0) {
+			return;
+		}
+
+		/* use default code when sendfile failed with w < 0 */
+#endif
 		char buf[16*4096];
 		ssize_t n = pread(data->stream_fd, buf, sizeof buf, data->off);
 		if (n < 0) {
@@ -872,14 +886,6 @@ write_client(int 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 (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) {
 			finish_response(i);