Skip to content

Commit

Permalink
Workaround FreeBSD's sendfile not reading data from the disk. bertha#5
Browse files Browse the repository at this point in the history
Signed-off-by: Jille Timmermans <[email protected]>
  • Loading branch information
Jille committed Apr 27, 2012
1 parent 6a37435 commit 71e393c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions berthad-vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,11 @@ static inline void conn_get_handle__sendfile(BProgram* prog, GList* lhconn)
/* Socket buffers are full */
data->socket_ready = FALSE;
} else if(errno == EBUSY) {
char cbuf;
/* File buffers are depleted */
data->file_ready = FALSE;
/* Trigger the kernel to read from the disk */
res = read(data->fd, &cbuf, 1);
} else {
perror("sendfile");
g_error("Sendfile failed?!\n");
Expand All @@ -1035,7 +1038,9 @@ static inline void conn_get_handle__sendfile(BProgram* prog, GList* lhconn)
/* We're done! */
shutdown(conn->sock, SHUT_RDWR);
conn_close(prog, lhconn);
return;
}
lseek(data->fd, data->n_sent, SEEK_SET);
}
#endif /* USE_SENDFILE */

Expand Down

2 comments on commit 71e393c

@bwesterb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dadbb9a work for you?

@Jille
Copy link
Owner Author

@Jille Jille commented on 71e393c May 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would. If sendfile(2) does actually transmit some bytes it doesn't change the file-offset so read(2) reads a random piece of data instead of the next byte of the wanted data. The lseek(2) should be done before the read.

There was a (efficiency) reason why I did the lseek(2) at the end of the function instead of just before the read(2), but I'm afraid I forgot why.

Please sign in to comment.