Re: Reading From A Pipe
- From: pub <pub inbox hughes net>
- To: gtkmm-list gnome org
- Subject: Re: Reading From A Pipe
- Date: Tue, 11 May 2010 19:37:48 +0000 (GMT)
int pipefd2[2]; /* Read pipe from child */
Glib::RefPtr<Glib::IOChannel> readChannel;
//Instantiate
Playback playback;
// Connect the signal handler
Glib::signal_io().connect(sigc::mem_fun(playback, &Playback::readpipe), pipefd2[r], Glib::IO_IN);
// Create a writeChannel from the file descriptor
writeChannel = Glib::IOChannel::create_from_fd(pipefd1[w]);
// Create a readChannel from the file descriptor
readChannel = Glib::IOChannel::create_from_fd(pipefd2[r]);
app.run(playback);
// Read From Pipe
bool Playback::readpipe(Glib::IOCondition read_condition)
{
static int linecount; // Total lines expected
static int count; // Count of lines received
if ((read_condition & Glib::IO_IN) == 0)
{
std::cerr << "Exxx: Invalid read response" << std::endl;
}
else
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
readChannel->read_line(readbuffer);
#else
std::auto_ptr<Glib::Error> ex;
readChannel->read_line(readbuffer, ex);
if(ex.get())
std::cerr << "Exxx: " << ex->what() << std::endl;
#endif //GLIBMM_EXCEPTIONS_ENABLED
/* Append message read from pipe to textbuffer */
m_msg->insert(m_msg->end(), readbuffer);
}
return true;
} //End of readpipe()
On May 11, 2010, José Alburquerque <jaalburquerque cox net> wrote:
On Tue, 2010-05-11 at 18:23 +0000, pub wrote:
>
> I am trying to read a line from a pipe. After several different tests,
> I get the same results.
> The child is a program that sends 8 lines up the pipe to the Gtkmm
> application.
>
> The first line is read and displayed. Only one line!
>
> The second time, 8 more lines are sent up the pipe.
> I get the 7 remaining lines from the first group of lines plus only
> the first line of the second group. 8 lines total.
>
> Then 8 more lines are displayed in the same pattern, 7 from the
> preceeding group and only the first from the new group.
> This pattern continues until the child stops sending.
>
> It seems like the receive end of the pipe does not show that there is
> remaining lines of data.
>
> Can someone help?
What API specifically are you having trouble with?
--
José
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]