gtk - If I have two instances of Glib::IOChannel, they block until both written. What is the correct way to do this? -
I have modified the example found to use two io channels I have written both channels before any callback Is not called. After this he is personally asked to write to FIFO. Am i missing something
- Start the testing program in a shell window.
- Encoding "ABC" in the second shell window, type testfifo1 -> nothing happens.
- encode "DEF" in the third shell window testfifo2 type -> Now I get the "ABC" and "Diaf" is
- Write a fee it is served immediately.
EDIT: The solution, as indicated below, was the lack of non-blocking Gormley.
read_fd1 = open ("testfifo1", O_RDONLY | O_NONBLOCK); ... read_fd2 = Open ("testfifo2", O_RDONLY | O_NONBLOCK);
This change immediately responds to the code given below.
Code:
#include> Gtkmm / main h & gt; # Include & lt; Fcntl.h & gt; # Include & lt; Iostream & gt; Int read_fd1, read_fd2; GLib :: RefPtr & LT; GLib :: IOChannel & gt; Iochannel1, iochannel2; // Use "echo" Hello "gt; testfifo & lt; 1; 2 & gt;", "Q" bool Maiklack leave with 1 (Glib :: IOCondition io_condition) {glib :: slipping buf; Iochannel1- & gt; Read_line (buf); Std :: cout & lt; & Lt; "Io1:" & lt; & Lt; Buf; If (buf == "Q \ n") Gtk :: Main :: quit (); Back true; } Bool MichaelBlack2 (GLib :: IOCondition io_condition) {Glib :: Brain Buff; Iochannel2- & gt; Read_line (buf); Std :: cout & lt; & Lt; "I2:" & lt; & Lt; Buf; If (buf == "Q \ n") Gtk :: Main :: quit (); Back true; } Int main (int argc, char * argv []) {// General GTK :: main object Gtk :: main app (argc, argv); If (( "testfifo1", F_OK) == -1) (if (mkfifo ( "testfifo1", 0666)! = 0) return -1;} if (( "testfifo2", F_OK), == -1) ( If (mkfifo ( "testfifo2", 0666)! = 0) return -1;} Read_fd1 = open ( "testfifo1", O_RDONLY); if (read_fd1 == -1) return -1; Read_fd2 = open ( "testfifo2", O_RDONLY); if (read_fd2 == -1) return -1; Glib :: Signl_o (). connect (Sigc :: Ptr_fun (MyCallbackl), Read_fdl, Glb :: IO_IN); Glib :: Signl_o (). connect ( sigc :: ptr_fun (MyCallback2), read_fd2, Glb :: IO_IN); Iochannel1 = Glib :: IOChannel :: create_from_fd (read_fd1); Iochannel2 = Glib :: IOChannel :: create_from_fd (read_fd2); app.run (); if ( Unlink ("testfifo1")) std :: cerr & lt; "error in deleting fifo1" & lt;
Both statements block the program from the main loop until both FIFOs are open to write. Block until both sides are connected
iochannel1 = Glib :: IOChannel :: create_from_fd (read_fd1); Iochannel2 = Grib :: IOChannel :: create_from_fd (read_fd2);
Comments
Post a Comment