using GLib; using Gtk; using Posix; public class test_iochannel: Object { private IOChannel io_read; private IOChannel io_write; private int pipes[2]; private int msg_tosend; private uint timer; public bool timer_func() { var msg=""; size_t v; switch(msg_tosend) { case 0: msg="First string\n"; break; case 1: msg="Second string\nSecond string b\n"; break; case 2: msg="Third string\nThird string b\n\rThird string c\n"; break; case 3: msg="Fourth string\nFourth string b\n\r"; break; case 4: msg="Fifth string\n"; break; default: break; } GLib.stdout.printf("Sending %s\n",msg); this.io_write.write_chars((char[])msg,out v); this.io_write.flush(); msg_tosend++; return (true); } public test_iochannel() { msg_tosend=0; Posix.pipe(pipes); this.io_read = new IOChannel.unix_new(pipes[0]); this.io_write = new IOChannel.unix_new(pipes[1]); this.io_read.add_watch(IOCondition.HUP|IOCondition.IN,gio_in); this.timer=GLib.Timeout.add(1000,this.timer_func); } private bool gio_in(IOChannel gio, IOCondition condition) { IOStatus ret; string msg=""; size_t len; size_t pos; if((condition & IOCondition.HUP) == IOCondition.HUP) { return false; } GLib.stdout.printf("data\n"); try { ret = gio.read_line(out msg, out len,out pos); GLib.stdout.printf("Received: %s (%llu)\n",msg,len); } catch(IOChannelError e) { GLib.stdout.printf("Error channel\n"); } catch(ConvertError e) { GLib.stdout.printf("Error conversion\n"); } return(true); } } int main(string[] args) { Gtk.init (ref args); var test=new test_iochannel(); Gtk.main (); return 0; }