Skip to content

Commit

Permalink
windows: fix fs_read with nbufs > 1 and offset
Browse files Browse the repository at this point in the history
ReadFile() does not seem to update the offset at all.
  • Loading branch information
unknownbrackets authored and saghul committed Oct 26, 2014
1 parent b174a84 commit 5ac921b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/win/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,6 @@ void fs__read(uv_fs_t* req) {

if (offset != -1) {
memset(&overlapped, 0, sizeof overlapped);

offset_.QuadPart = offset;
overlapped.Offset = offset_.LowPart;
overlapped.OffsetHigh = offset_.HighPart;

overlapped_ptr = &overlapped;
} else {
overlapped_ptr = NULL;
Expand All @@ -571,6 +566,13 @@ void fs__read(uv_fs_t* req) {
bytes = 0;
do {
DWORD incremental_bytes;

if (offset != -1) {
offset_.QuadPart = offset + bytes;
overlapped.Offset = offset_.LowPart;
overlapped.OffsetHigh = offset_.HighPart;
}

result = ReadFile(handle,
req->bufs[index].base,
req->bufs[index].len,
Expand Down Expand Up @@ -623,7 +625,6 @@ void fs__write(uv_fs_t* req) {
do {
DWORD incremental_bytes;

/* WriteFile() does not advance overlapped as ReadFile() does. */
if (offset != -1) {
offset_.QuadPart = offset + bytes;
overlapped.Offset = offset_.LowPart;
Expand Down
12 changes: 8 additions & 4 deletions test/test-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static uv_fs_t utime_req;
static uv_fs_t futime_req;

static char buf[32];
static char buf2[32];
static char test_buf[] = "test-buffer\n";
static char test_buf2[] = "second-buffer\n";
static uv_buf_t iov;
Expand Down Expand Up @@ -2200,12 +2201,15 @@ TEST_IMPL(fs_write_multiple_bufs) {
uv_fs_req_cleanup(&open_req1);

memset(buf, 0, sizeof(buf));
iov = uv_buf_init(buf, sizeof(buf));
r = uv_fs_read(loop, &read_req, open_req1.result, &iov, 1, -1, NULL);
memset(buf2, 0, sizeof(buf2));
/* Read the strings back to separate buffers. */
iovs[0] = uv_buf_init(buf, sizeof(test_buf));
iovs[1] = uv_buf_init(buf2, sizeof(test_buf2));
r = uv_fs_read(loop, &read_req, open_req1.result, iovs, 2, 0, NULL);
ASSERT(r >= 0);
ASSERT(read_req.result >= 0);
ASSERT(memcmp(buf, test_buf, sizeof(test_buf)) == 0);
ASSERT(strcmp(buf + sizeof(test_buf), test_buf2) == 0);
ASSERT(strcmp(buf, test_buf) == 0);
ASSERT(strcmp(buf2, test_buf2) == 0);
uv_fs_req_cleanup(&read_req);

iov = uv_buf_init(buf, sizeof(buf));
Expand Down

0 comments on commit 5ac921b

Please sign in to comment.