watching a file descriptor in gtk3




Hi all,

I need to monitor a Unix file descriptor for input within my gtk3 program. I believe that I need to somehow be using g_source_add_unix_fd() and friends but am finding the documentation confusing. Are there any simple examples which show how to do this anywhere? (I looked but could not find, apologies for any oversight on my part.)

I am porting an old Motif app which used

        XtAppAddInput( ... fd ... callbackproc ...)

to register an input handler callbackproc() to be called whenever there was input pending on fd. Whatever I use to replace this should NOT block for any user-perceivable amount of time when checking fd for pending input, which will typically be very small (under 80 bytes) and occurring between a few times per second and a few times per hour.

Absent a working understanding of how to use g_source_add_unix_fd(), etc., my inclination is to just use g_idle_add_full() and do my own non-blocking select() inside my callback. Seems like g_source_add_unix_fd() is perhaps better suited to this task, but I can't figure out what I need to do vs. what glib can do without me, i.e., do I really need to create and attach my own GSource and code my own entire set of GSourceFuncs? That would seem to be a hugely complicated effort compared to the simple XtAppAddInput() call, or even to coding my own select() stuff inside a g_idle_add_full() callback. Monitoring a few stray file descriptors within a gtk3 program would seem to be a not-unusual need, so I am hoping someone will tell me that there is an existing GSource somewhere that I can just add my own fd into, but that is not at all obvious from the documentation.

Thanks!

Roger Davis
Univ. of Hawaii



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