Re: [gnet] Iterating the event loop within a callback



On Sat, 2004-05-01 at 21:17, Tim Müller wrote:
> What you are doing (while events pending do main iteration after the 
> gnet_conn_readline) won't work in most cases, because it assumes that the 
> data of the next line is already available, which won't be true in most cases 
> (and then events pending will be FALSE while waiting for more data to arrive, 
> and your loop exits).

I understand what you are saying.  You are right.

> In any case, what you are doing is not really the best way to do things, in my 
> humble opinion. Even if you made it work [1], it would probably lead to code 
> that is fairly hard to understand. Personally, I would do something similar 
> to what I did in the attached code.
> 
> Cheers
>  -Tim
> 
> [1] You can probably get it to work by creating a new glib main loop for the 
> default context (NULL), and then running it after changing the callback and 
> calling gnet_conn_readline(). Then in your extra_data callback, you simply 
> call g_main_loop_quit() and you're back in the other callback where you 
> called g_main_loop_run(). But as I said, this is rather ugly IMHO.

Ugly, yes.  But it just might be what I have to have.  Because I'm
operating within the asynchronous framework, this is the only way to
accomplish what I'm trying to accomplish.  I can do a lot of state
saving stuff, but that would be just as unclean.  Part of the problem
comes from having 2 different sockets, and callbacks for reads on one
socket sometimes require data from the other socket.  Probably threaded
would be good, but so far the gnet framework has proven easier and less
error-prone.

I will take your suggestions under advisement.

Michael






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