summaryrefslogtreecommitdiffstats
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'server.c')
-rw-r--r--server.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/server.c b/server.c
index 07503e1..296c35f 100644
--- a/server.c
+++ b/server.c
@@ -7,6 +7,8 @@
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sendfile.h>
#include <unistd.h>
int main(int argc, char **argv)
@@ -70,10 +72,15 @@ int main(int argc, char **argv)
strlen(http_content_type), 0);
FILE *index_fd = fopen("./index.html", "r");
- char c;
- while ((c = getc(index_fd)) != EOF) {
- send(new_fd, &c, 1, 0);
+
+ struct stat stat_buf;
+ int stat_result = fstat(fileno(index_fd), &stat_buf);
+ if (stat_result != 0) {
+ perror("fstat");
}
+
+ sendfile(new_fd, fileno(index_fd), NULL,
+ stat_buf.st_size);
}
memset(buf, 0, 1024);