Skip to content

Commit

Permalink
fix #1 - Windows scattered sync read/write incorrectly implemented
Browse files Browse the repository at this point in the history
- must break on partial reads/writes so that newly arriving data/buffer-space
  in between read/write calls doesn't lead to gaps in scatter buffers
  • Loading branch information
MartinNowak committed Aug 19, 2018
1 parent 9f32c59 commit 289244b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/std/io/driver/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ shared @safe @nogc:
{
size_t total;
foreach (b; bufs)
total += read(f, b);
{
immutable len = read(f, b);
total += len;
if (len < b.length)
break;
}
return total;
}
}
Expand Down Expand Up @@ -179,7 +184,12 @@ shared @safe @nogc:
{
size_t total;
foreach (b; bufs)
total += write(f, b);
{
immutable len = write(f, b);
total += len;
if (len < b.length)
break;
}
return total;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/std/io/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ struct File
assert(f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]) == buf.length);
}

@("partial reads")
unittest
{
auto f = File("LICENSE.txt");
ubyte[256] buf = void;
auto len = f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]);
while (len == buf.length)
len = f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]);
assert(len < buf.length);
}

/**
Write buffer content to file.
Expand Down

0 comments on commit 289244b

Please sign in to comment.