Re: [gnet] gnet_tcp_socket_server_accept_async problem



On Thu, 2006-09-07 at 12:33 +0200, Michele "O-Zone" Pinassi wrote:

Hi,

> void main() {
> ...
> gMainContext = (GMainContext *)g_main_context_new();
> gMainLoop = (GMainLoop *)g_main_loop_new(gMainContext,FALSE);
> gServerSock = gnet_tcp_socket_server_new_with_port(Modem->socket);
> ...
> gnet_tcp_socket_server_accept_async(gServerSock, clientAccept, NULL);
> ...
> g_main_run(gMainLoop);
>
> The program compile and run BUT, on telnet connection to socket, the function 
> clientAccept will not be called !!!
> 
> Suggestions ? Thanks !

The problem is this: internally, GNet does a g_io_add_watch() on the
server socket to watch for incoming connections. This attaches a IO
watch source to the _default main context_, ie. not your main context.
The loop you're running will only iterate your main context, so the io
watch that GNet added will never run.

Easy solution: skip the

 gMainContext = (GMainContext *)g_main_context_new();

and replace with

 gMainContext = NULL;

A context of NULL is used to refers to the default main context in GLib,
so that will make sure your main loop iterates the same context GLib
uses internally.

If you aren't using the default main context on purpose for some reason,
then you're a bit out of luck at the moment, GNet currently doesn't have
API to tell it to use some other main context for this kind of stuff
(not sure it's really needed either).

Hope this helps.

 Cheers
  -Tim






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