From 6a37435c59b7a7d6581cff6697e748ebc95312ec Mon Sep 17 00:00:00 2001 From: Jille Timmermans Date: Sat, 28 Apr 2012 00:40:49 +0200 Subject: [PATCH 1/2] Use -1 as "This fd is closed" instead of 0, which can be a valid filedescriptor. --- berthad-vfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/berthad-vfs.c b/berthad-vfs.c index 26df0d0..327ea80 100644 --- a/berthad-vfs.c +++ b/berthad-vfs.c @@ -572,7 +572,7 @@ static void conn_put_free(BProgram* prog, GList* lhconn) BConnPut* data = conn->state_data; if (data->checksum) g_checksum_free(data->checksum); - if (data->fd) + if (data->fd != -1) close (data->fd); if (data->tmp_fn) { unlink(data->tmp_fn->str); @@ -589,7 +589,7 @@ static void conn_get_free(BProgram* prog, GList* lhconn) { BConn* conn = lhconn->data; BConnGet* data = conn->state_data; - if (data->fd) + if (data->fd != -1) close(data->fd); #ifdef USE_SPLICE if (data->pipe[0]) @@ -1296,7 +1296,7 @@ static void conn_put_handle(BProgram* prog, GList* lhconn) /* Close the file descriptor */ close(data->fd); - data->fd = 0; + data->fd = -1; /* Get the final key */ g_checksum_get_digest(data->checksum, key, &len); From 71e393ce0baa0c178ed7b77bf2c1555d3952601e Mon Sep 17 00:00:00 2001 From: Jille Timmermans Date: Fri, 27 Apr 2012 23:54:44 +0000 Subject: [PATCH 2/2] Workaround FreeBSD's sendfile not reading data from the disk. #5 Signed-off-by: Jille Timmermans --- berthad-vfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/berthad-vfs.c b/berthad-vfs.c index 327ea80..1dcbed1 100644 --- a/berthad-vfs.c +++ b/berthad-vfs.c @@ -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"); @@ -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 */