aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-02-16 13:14:09 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-02-16 14:25:17 +0000
commitfbad2377e0c40aa09db756c5b49e2420f79d06fe (patch)
treef864416e59a17990bff3d34e3c9da2c4c2767d8c
parent444541a7b98f105d0273a38035f0ecbe6b0db058 (diff)
downloadpaludis-fbad2377e0c40aa09db756c5b49e2420f79d06fe.tar.gz
paludis-fbad2377e0c40aa09db756c5b49e2420f79d06fe.tar.xz
Use fewer writes when passing input
-rw-r--r--paludis/util/system.cc30
1 files changed, 15 insertions, 15 deletions
diff --git a/paludis/util/system.cc b/paludis/util/system.cc
index 918fba9..ca9ff8e 100644
--- a/paludis/util/system.cc
+++ b/paludis/util/system.cc
@@ -815,6 +815,7 @@ paludis::run_command(const Command & cmd)
internal_command_reader->clear_write_fd();
std::string pipe_command_buffer, internal_command_buffer;
+ std::string input_stream_pending;
while (true)
{
fd_set read_fds, write_fds;
@@ -906,27 +907,26 @@ paludis::run_command(const Command & cmd)
if (cmd.input_stream() && (-1 != input_stream->write_fd())
&& FD_ISSET(input_stream->write_fd(), &write_fds))
{
- bool eof(! cmd.input_stream()->good());
-
- while (! eof)
+ while ((! input_stream_pending.empty()) || cmd.input_stream()->good())
{
- char c;
- if (cmd.input_stream()->get(c).good())
+ if (input_stream_pending.empty() && cmd.input_stream()->good())
{
- int w(write(input_stream->write_fd(), &c, 1));
- if (0 == w || (-1 == w && (errno == EAGAIN || errno == EWOULDBLOCK)))
- {
- cmd.input_stream()->unget();
- break;
- }
- else if (-1 == w)
- throw RunCommandError("write failed: " + stringify(strerror(errno)));
+ cmd.input_stream()->read(buf, 1024);
+ input_stream_pending.assign(buf, cmd.input_stream()->gcount());
}
+
+ int w(write(input_stream->write_fd(), input_stream_pending.c_str(),
+ input_stream_pending.length()));
+
+ if (0 == w || (-1 == w && (errno == EAGAIN || errno == EWOULDBLOCK)))
+ break;
+ else if (-1 == w)
+ throw RunCommandError("write failed: " + stringify(strerror(errno)));
else
- eof = true;
+ input_stream_pending.erase(0, w);
}
- if (eof)
+ if (input_stream_pending.empty() && ! cmd.input_stream()->good())
{
if (0 != close(input_stream->write_fd()))
throw RunCommandError("close failed: " + stringify(strerror(errno)));