Skip to content

Commit

Permalink
FIX: dinit-iostream: Don't buffer message if the size of message is l…
Browse files Browse the repository at this point in the history
…arger than the buffer.

Signed-off-by: Mobin Aydinfar <[email protected]>
  • Loading branch information
mobin-2008 committed Oct 21, 2024
1 parent 074ee79 commit 9d6bb3d
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/dinit-iostream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,13 @@ ssize_t ostream::put(const char *msg, size_t count) noexcept
// io_error was set by flush_nx() call
return -1;
}
while (count > static_cast<size_t>(buf->get_free())) {
int prev_freespace = buf->get_free();
buf->append(msg, prev_freespace);
msg += prev_freespace;
output_count += prev_freespace;
count -= prev_freespace;
bool r = flush_nx();
if (!r) {
// io_error was set by flush_nx() call
return (output_count > 0) ? output_count : -1;
}
// It's better to write the whole message.
ssize_t res = bp_sys::write(get_fd(), msg, count);
// Note: Set io_error on both -1 and partial write.
if (res < count) {
io_error = errno;
}
buf->append(msg, count);
return output_count + count;
return res;
}
while (count > static_cast<size_t>(buf->get_free())) {
// If we haven't enough storage for caputring the message Firstly we try to fill buffer as
Expand Down

0 comments on commit 9d6bb3d

Please sign in to comment.