[gnet] gnet conn callback problem



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,





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