I'm looking for some tips on understanding how to make socket writes work
in a main loop. In my past non-glib socket programs, I have had to do some
write logic similar to:

1) attempt to write n bytes
2) if all n bytes were written, great
3) if some or all bytes were non written, that must mean OS buffers are
full, so establish an event loop callback for when writes are again
4) inside that callback repeat step 1

So in the world of glib, in step 3 I could do a g_io_create_watch(channel,
G_IO_OUT), but what do I do when the write finally finishes? In other
words, how do I stop the io watch for G_IO_OUT until its needed again? How
bad would it be to just call g_io_create_watch(), g_source_attach(), and
g_source_set_callback() every time a write didn't complete - plus
g_source_destroy() when it finally finishes? Is that idea? 



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