Re: io watch callback and condition modification



Szalai Ferenc <szferi angel elte hu> writes:

> Discussion myself :)
> 
> > It creates an io watch in the default main loop context using 
> > g_io_add_watch_full function with an condition (G_IO_IN | G_IO_ERR |
> > G_IO_HUP) and callback function (do_read). 
> > The question is: How can I change normally the callback function (eg.:
> > do_write) and condition (eg.: G_IO_OUT | G_IO_ERR) without removeing and
> > reattaching the watch 
> > form the context? 
> There is one problem why this can't do:
> In giounix.c and giowin32.c module there is a GIO[Unix,Win32]Watch
> structure which have a condition element. In g_main_context_check the
> source's check function evaluate the following expression:
> 
> ((poll_condition | buffer_condition) & watch->condition)
> 
> Where the watch->condition can't modified from outside of glib. But it
> is necessary in case described above.
> 
> So I suggest two possible modification to solve this problem:
> 1. Change watch->condition in g_io_[unix,win32]_[check,
> prepare,dispatch, finalize] function to watch->pollfd.events
> 
> 2. Or EXTEND the glib API with eg: g_io_set_watch_condition function
> which modify the appropriate pollfd.events and watch->condition
> variables to a requested value.
> (I have a patch for secound one.)
> 
> I think this feature will useful in any cases when you design a server
> application using glib.
> 
> I waiting for any comment.

Why can't you simply remove the watch and add a new one? 

Trying to handle mutation of an active source is probably going
add a fair bit of thread safety and reentrancy complexity.

Regards,
                                        Owen



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