Re: [gnet] gnet conn callback problem
- From: David Helder <dhelder umich edu>
- To: Pinky666 email si
- Cc: gnet gnetlibrary org
- Subject: Re: [gnet] gnet conn callback problem
- Date: Mon, 6 Jan 2003 14:33:32 -0500 (EST)
Pinky,
I'm not sure if it's a GNet bug or not. Conn's are *not* thread safe, so
that could be the problem. If you use the Conn in one thread only, there
won't be a problem. So I'd try moving the conn_client_func into thread 2.
David
On Wed, 25 Dec 2002 Pinky666 email si wrote:
> Hi, I have a little problem with callbacks. Here is a pseudo code snip:
>
> static void new_conn_cb(GServer* server, GServerStatus status, GConn* conn, gpointer ptr) { // new connection callback
> if (status == GNET_SERVER_STATUS_CONNECT) {
> ...
> conn->user_data = NULL;
> conn->func=&conn_client_func; // setup socket callback now (it is same as the one provided in examples, ob_client_func)
> ...
> } else {
> g_log(__FILE__,G_LOG_LEVEL_DEBUG,"Connection attempt error");
> }
> }
>
> Thread1(main thread) = 1-
> Thread2(client thread) = 2-
>
> 1-
> ...
> gnet_init();
> main_loop = g_main_loop_new(NULL,FALSE);
> ...
> addr = gnet_inetaddr_new_any ();
> gnet_inetaddr_set_port (addr, port);
> TCPserver=gnet_server_new(addr,TRUE,new_conn_cb,NULL); // create new TCP server
> ...
> Creates thread 2 and runs it
> ...
> g_main_loop_run(main_loop); // "stops" here
> ...
> 2-
> ...
> waits for connection
> ...
>
> Then I connect to it...
>
> 1?-
> it executes new_conn_cb with GNET_SERVER_STATUS_CONNECT,
> then I send a message to thread2
> 2-
> ...wakes up...
> gnet_conn_write(conn,g_strdup(txt1->str),txt1->len,0); // send greetings1
> gnet_conn_write(conn,g_strdup(txt2->str),txt2->len,0); // send greetings2
> ...
> 1?-
> executes callback conn_client_func ("ob_client_func") with GNET_CONN_STATUS_WRITE
>
> Until here is all as it ?should? be; create gnet_server, setup callback and wait for connection.
> When connection arrives, update connection's callback address so we can receive GNET_CONN_STATUS_WRITE,
> If I write to it and I receive back CONN_STATUS_WRITE. CONN_STATUS_READ also works fine.
>
> BUT,
> The problem is, that I receive only one STATUS_WRITE callback, for first greeting. I also see it in telnet, but
> only the first one, nothing more even if I do gnet_conn_write 1000x times.
> It is very rare that I get both writes acknowledged by a 2 callbacks. If that happens all is working just fine: every
> gnet_conn_write generates a callback and displays text in telnet client.
>
> Any idea, why it "hungs" after first gnet_conn_write?
>
> ... if anyone needs detailed code of this matter I can send to him or post it to the mailing list
>
> Thanks,
--
__ _ __ David Helder - dhelder umich edu
___/ /__ __ __(_)__/ / <http://www.eecs.umich.edu/~dhelder>
/ _ / _ `/ |/ / / _ / DiaWebLog: <http://www.diaweblog.org>
|_,_/|_,_/|___/_/|_,_/ Paper CD Case: <http://www.papercdcase.com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]