Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: Pecan on February 02, 2008, 06:25:33 pm

Title: Possible PipedProcess copy/paste err?
Post by: Pecan on February 02, 2008, 06:25:33 pm
I was looking at PipedProcess today and ran across this.

Is the double "= GetErrorStream();" a result of the copy/paste imp again?

Should one of them be GetOutputSteam(); or the like?

Code
void PipedProcess::ForfeitStreams()
{
    char buf[4096];
    if (IsErrorAvailable())
    {
        wxInputStream *in = GetErrorStream();
        while(in->Read(&buf, sizeof(buf)).LastRead())
            ;
    }
    if (IsInputAvailable())
    {
        wxInputStream *in = GetErrorStream();
        while(in->Read(&buf, sizeof(buf)).LastRead())
            ;
    }
}

Title: Re: Possible PipedProcess copy/paste err?
Post by: MortenMacFly on February 02, 2008, 07:39:14 pm
Is the double "= GetErrorStream();" a result of the copy/paste imp again?
I'd say so, yes! Hence I wonder why it is working anyways... is the cout/cerr stream possibly combined?!
Title: Re: Possible PipedProcess copy/paste err?
Post by: thomas on February 02, 2008, 09:33:41 pm
It works because only the error stream matters. But yes, it looks like a copy error.
Title: Re: Possible PipedProcess copy/paste err?
Post by: MortenMacFly on February 02, 2008, 10:02:56 pm
It works because only the error stream matters. But yes, it looks like a copy error.
So Lieven... seems it's best if you fix this? ;-)
Title: Re: Possible PipedProcess copy/paste err?
Post by: thomas on February 03, 2008, 01:18:35 pm
It really doesn't matter, even though it's wrong. But go ahead and fix it if you want :)
The HasInputStream branch won't be taken, since the stream is already closed. Only the error stream cannot be closed programmatically which is why it must be drained, else the program might hang if you kill a process that has more data in the error stream than will fit in the buffer. However, killing doesn't work under Windows anyway, and under Linux,  the buffer size should not be a problem.