|
@@ -60,10 +60,6 @@ KResultOr<ssize_t> Process::sys$writev(int fd, Userspace<const struct iovec*> io
|
|
|
KResultOr<ssize_t> Process::do_write(FileDescription& description, const UserOrKernelBuffer& data, size_t data_size)
|
|
|
{
|
|
|
ssize_t total_nwritten = 0;
|
|
|
- if (!description.is_blocking()) {
|
|
|
- if (!description.can_write())
|
|
|
- return EAGAIN;
|
|
|
- }
|
|
|
|
|
|
if (description.should_append() && description.file().is_seekable()) {
|
|
|
auto seek_result = description.seek(0, SEEK_END);
|
|
@@ -72,11 +68,12 @@ KResultOr<ssize_t> Process::do_write(FileDescription& description, const UserOrK
|
|
|
}
|
|
|
|
|
|
while ((size_t)total_nwritten < data_size) {
|
|
|
- if (!description.can_write()) {
|
|
|
+ while (!description.can_write()) {
|
|
|
if (!description.is_blocking()) {
|
|
|
- // Short write: We can no longer write to this non-blocking description.
|
|
|
- VERIFY(total_nwritten > 0);
|
|
|
- return total_nwritten;
|
|
|
+ if (total_nwritten > 0)
|
|
|
+ return total_nwritten;
|
|
|
+ else
|
|
|
+ return EAGAIN;
|
|
|
}
|
|
|
auto unblock_flags = Thread::FileBlocker::BlockFlags::None;
|
|
|
if (Thread::current()->block<Thread::WriteBlocker>({}, description, unblock_flags).was_interrupted()) {
|
|
@@ -87,12 +84,13 @@ KResultOr<ssize_t> Process::do_write(FileDescription& description, const UserOrK
|
|
|
}
|
|
|
auto nwritten_or_error = description.write(data.offset(total_nwritten), data_size - total_nwritten);
|
|
|
if (nwritten_or_error.is_error()) {
|
|
|
- if (total_nwritten)
|
|
|
+ if (total_nwritten > 0)
|
|
|
return total_nwritten;
|
|
|
+ if (nwritten_or_error.error() == EAGAIN)
|
|
|
+ continue;
|
|
|
return nwritten_or_error.error();
|
|
|
}
|
|
|
- if (nwritten_or_error.value() == 0)
|
|
|
- break;
|
|
|
+ VERIFY(nwritten_or_error.value() > 0);
|
|
|
total_nwritten += nwritten_or_error.value();
|
|
|
}
|
|
|
return total_nwritten;
|