Is it possible to use glib event loops for IPC?
Is it po开发者_运维百科ssible to use glib event loops and glib io channels for IPC in one parent - many child process model?
Parent and children must be able to send each other 'commands'.
Can you point me to some tutorials or examples?
Yes. But it doesn't contain a complete IPC solution in itself and is probably not perfectly compatible with every IPC implementation out there. With parent and children I guess you mean server and clients? Generally you open some sort of network connection or create pipe for communication and you get a file descriptor (even if you use a high level library that hides this). You can pass this file descriptor to glib and get a callback then data is available for reading (or the connection closed). Some popular IPC methods like CORBA and DBUS already has glib integration so you don't even need to bother with file descriptors and such. The glib event loop is described here. It might seem utterly complex compared to just using poll() directly but on the other hand it is very portable.
The basic usage is to create a source with g_source_new() and add it to your main context with g_source_attach() and then add your file descriptor to the source with g_source_add_poll().
If you havn't decided on glib yet you might want to check out libevent with does the same thing as glib but is (IMHO) much easier to use. It is also significantly better at handling 1000+ simultanious clients (at least in Linux, other operating systems may not even support that). But on the other hand it's not as portable and will probably only work on fairly posix compatible systems.
精彩评论