diff --git a/berthad-vfs.c b/berthad-vfs.c index 26df0d0..1dcbed1 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]) @@ -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 */ @@ -1296,7 +1301,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);