Re: Reading From A Pipe



On Tue, 2010-05-11 at 19:37 +0000, pub wrote:
> 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()

My suggestion would be to try running the code through a debugger.  I
find this a lot easier than guessing at what is happening (unless
something is blatantly clear from a quick look at the code).  Perhaps
others can more quickly see the problem than I can right now.

-- 
José



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]