Skip to content

Commit 45279b7

Browse files
authored
Handle partial write in FifoPosix (#214)
1 parent 79df9a1 commit 45279b7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pkgs/io_file/test/fifo_posix.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,22 @@ class FifoPosix implements Fifo {
4343
subscription.resume();
4444
}
4545

46+
void write(int fd, Uint8List data) {
47+
var offset = 0;
48+
while (offset < data.length) {
49+
final wrote = stdlibc.write(fd, data.buffer.asUint8List(offset));
50+
if (wrote == -1) {
51+
throw AssertionError('write failed: ${stdlibc.errno}');
52+
}
53+
offset += wrote;
54+
}
55+
}
56+
4657
subscription = receivePort.listen(
4758
(message) => switch (message) {
48-
Uint8List data => stdlibc.write(fd, data),
49-
59+
Uint8List data => write(fd, data),
5060
Duration d => pause(d),
5161
null => stdlibc.close(fd),
52-
5362
final other => throw UnsupportedError('unexpected message: $other'),
5463
},
5564
);

0 commit comments

Comments
 (0)