diff options
| -rw-r--r-- | server.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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); |
