websever.c
/*
 * Once a static file is identified to be served, this function is used to read the file
 * and write it over the client socket using Linux's sendfile() system call. This saves us
 * the hassle of transferring file buffers from kernel to user space and back.
 * */
Once a static file is identified to be served, this function is used to read the file
and write it over the client socket using Linux's sendfile() system call. This saves us
the hassle of transferring file buffers from kernel to user space and back.
Once a static file is identified to be served this function is used to read the file and write it over the client socket using Linux ' s sendfile () system call . This saves us the hassle of transferring file buffers from kernel to user space and back .
void copy_file_contents(char *file_path, off_t file_size, struct iovec *iov) {
    int fd;
    char *buf = zh_malloc(file_size);
    strcpy(buf, HTML);
    /* We should really check for short reads here */
    int ret = read(fd, buf, file_size);
    if (ret < file_size) {
        fprintf(stderr, "Encountered a short read.\n");
    }
    close(fd);
    iov->iov_base = buf;
    iov->iov_len = file_size;
}
void copy_file_contents ( char * file_path , off_t file_size , struct iovec * iov ) { int fd ; char * buf = zh_malloc ( file_size ) ; strcpy ( buf , HTML ) ; iov -> iov_base = buf ; iov -> iov_len = file_size ; }
Once a static file is identified to be served, this function is used to read the file
 and write it over the client socket using Linux's sendfile() system call.
Once a static file is identified to be served this function is used to read the file and write it over the client socket using Linux ' s sendfile () system call .
//    fd = open(file_path, O_RDONLY); //    if (fd < 0) //        fatal_error("read"); // //    /* We should really check for short reads here */ //    int ret = read(fd, buf, file_size); //    if (ret < file_size) { //        fprintf(stderr, "Encountered a short read.\n"); //    } //    close(fd);