Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: fix fs_async_sendfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Aug 30, 2011
1 parent 1a4ead5 commit 894c005
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
28 changes: 25 additions & 3 deletions src/unix/fs.c
Expand Up @@ -501,9 +501,31 @@ int uv_fs_ftruncate(uv_fs_t* req, uv_file file, off_t offset, uv_fs_cb cb) {
}


int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb) {
assert(0 && "implement me");
return -1;
int uv_fs_sendfile(uv_fs_t* req, uv_file out_fd, uv_file in_fd,
off_t in_offset, size_t length, uv_fs_cb cb) {
uv_fs_req_init(req, UV_FS_SENDFILE, cb);

if (cb) {
/* async */
uv_ref();
req->eio = eio_sendfile(out_fd, in_fd, in_offset, length, EIO_PRI_DEFAULT,
uv__fs_after, req);
if (!req->eio) {
uv_err_new(NULL, ENOMEM);
return -1;
}

} else {
/* sync */
req->result = eio_sendfile_sync(out_fd, in_fd, in_offset, length);

if (req->result) {
uv_err_new(NULL, errno);
return -1;
}
}

return 0;
}


Expand Down
45 changes: 21 additions & 24 deletions test/test-fs.c
Expand Up @@ -35,6 +35,11 @@
# include <io.h>
# define unlink _unlink
# define rmdir _rmdir
# define stat _stat
# define open _open
# define write _write
# define lseek _lseek
# define close _close
#endif

static int close_cb_count;
Expand Down Expand Up @@ -238,7 +243,7 @@ static void stat_cb(uv_fs_t* req) {
static void sendfile_cb(uv_fs_t* req) {
ASSERT(req == &sendfile_req);
ASSERT(req->fs_type == UV_FS_SENDFILE);
ASSERT(req->result == 65548);
ASSERT(req->result == 65546);
sendfile_cb_count++;
uv_fs_req_cleanup(req);
}
Expand Down Expand Up @@ -464,29 +469,25 @@ TEST_IMPL(fs_async_sendfile) {
int f, r;

/* Setup. */
#if UNIX
ASSERT(0 && "implement me");
#else
struct _stat s1, s2;
struct stat s1, s2;

_unlink("test_file");
_unlink("test_file2");
unlink("test_file");
unlink("test_file2");

f = _open("test_file", O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
f = open("test_file", O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
ASSERT(f != -1);

r = _write(f, "begin\n", 6);
ASSERT(r != -1);
r = write(f, "begin\n", 6);
ASSERT(r == 6);

r = _lseek(f, 65536, SEEK_CUR);
ASSERT(r == 65543);
r = lseek(f, 65536, SEEK_CUR);
ASSERT(r == 65542);

r = _write(f, "end\n", 4);
r = write(f, "end\n", 4);
ASSERT(r != -1);

r = _close(f);
r = close(f);
ASSERT(r == 0);
#endif

/* Test starts here. */
uv_init();
Expand Down Expand Up @@ -514,17 +515,13 @@ TEST_IMPL(fs_async_sendfile) {
ASSERT(r == 0);
uv_fs_req_cleanup(&close_req);

#if UNIX
ASSERT(0 && "implement me");
#else
_stat("test_file", &s1);
_stat("test_file2", &s2);
ASSERT(65548 == s2.st_size && s1.st_size == s2.st_size);
stat("test_file", &s1);
stat("test_file2", &s2);
ASSERT(65546 == s2.st_size && s1.st_size == s2.st_size);

/* Cleanup. */
_unlink("test_file");
_unlink("test_file2");
#endif
unlink("test_file");
unlink("test_file2");

return 0;
}

0 comments on commit 894c005

Please sign in to comment.