Skip to content

Handle partial write in FifoPosix #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkgs/io_file/test/fifo_posix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ class FifoPosix implements Fifo {
subscription.resume();
}

void write(int fd, Uint8List data) {
var offset = 0;
while (offset < data.length) {
final wrote = stdlibc.write(fd, data.buffer.asUint8List(offset));
if (wrote == -1) {
throw AssertionError('write failed: ${stdlibc.errno}');
}
offset += wrote;
}
}

subscription = receivePort.listen(
(message) => switch (message) {
Uint8List data => stdlibc.write(fd, data),

Uint8List data => write(fd, data),
Duration d => pause(d),
null => stdlibc.close(fd),

final other => throw UnsupportedError('unexpected message: $other'),
},
);
Expand Down
Loading