Monitoring I/O in gtkmm/WIN32



Can I use Monitoring I/O in WIN32 platform.?
I used the example in http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch18s02.html Because the mkfifo funtion doesn't exist I've replaced by a pipe() function but when I run the program I have continuosly the next error

(pru.exe:4293252359): GLib-WARNING **: gmain.c:429: MsgWaitForMultipleObjects()
failed: The handle is invalid.

The test program is :

#define GLIBMM_EXCEPTIONS_ENABLED
#include <gtkmm/main.h>
#include "gtkmmconfig.h" //For HAVE_MKFIFO
#include <fcntl.h>
#include <iostream>
#include <unistd.h> //The SUN Forte compiler puts F_OK here.
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

int read_fd;
int fd[2];

Glib::RefPtr<Glib::IOChannel> iochannel;
/*  send to the fifo with:  echo "Hello" > testfifo
 quit the program with:  echo "Q" > testfifo
*/

// this will be our signal handler for read operations
// it will print out the message sent to the fifo
// and quit the program if the message was 'Q'.
bool MyCallback(Glib::IOCondition io_condition)
{

 if ((io_condition & Glib::IO_IN) == 0) {
   std::cerr << "Invalid fifo response" << std::endl;
 }
 else {
  Glib::ustring buf;

  #ifdef GLIBMM_EXCEPTIONS_ENABLED
  iochannel->read_line(buf);
  #else
  std::auto_ptr<Glib::Error> ex;
  iochannel->read_line(buf, ex);
  if(ex.get())
    std::cerr << "Error: " << ex->what() << std::endl;
  #endif //GLIBMM_EXCEPTIONS_ENABLED
  std::cout << buf;
  if (buf == "Q\n")
      Gtk::Main::quit ();

 }
 return true;
}


int main(int argc, char *argv[])
{
 // the usual Gtk::Main object
 Gtk::Main app(argc, argv);
{

 if( pipe(fd) < 0 )
 {
     printf("Error pipe errno %d\n",errno);
     return 0;
 }
 read_fd = fd[0];
 printf("pipe read %d\n",read_fd);
 if (read_fd == -1)
 {
   std::cerr << "error opening fifo" << std::endl;
   return -1;
 }

 // connect the signal handler
Glib::signal_io().connect(sigc::ptr_fun(MyCallback), read_fd, Glib::IO_IN);

 // Creates a iochannel from the file descriptor
 iochannel = Glib::IOChannel::create_from_fd(read_fd);

 // and last but not least - run the application main loop
 app.run();
 return 0;
}

What is wrong?




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