Saturday, 15 February 2014

sockets - How to attach GIOChannel for different context instead of default context? -



sockets - How to attach GIOChannel for different context instead of default context? -

i writing 1 simple server , client application uses socket communication. in client side have created giochannel listening socket events such read, write, exception..etc. client provides asynchronous apis.

i have written 1 sample application testing code creates g_main_loop , creates 1 giochannel keyboard events.

mainloop = g_main_loop_new(null, false); channel = g_io_channel_unix_new(0); g_test_io_watch_id = g_io_add_watch(channel, (giocondition)(g_io_in | g_io_err | g_io_hup | g_io_nval), test_thread, null); g_main_loop_run(mainloop);

it working fine if dont loop or block main thread in callback function test_thread. illustration when phone call asynchronous api of client set sleep in sample programme time , expecting asynchronous message server time main thread wakes up. not happening, client socket getting read event reading asynchronous message server after main thread called api returns.

from got know both keyboad events , socket events registered same default context , can not notified main event dispatcher same time.

i have create programme such way socket reading @ client side should not dependent on default context of g_main_loop sync , async both happen seperate threads.

i found apis through gnome docs adding giochannel default context. have add together giochannel created socket reading different context.

can suggest me how or there improve alternative available handling socket reading asynchronously using glib.

thank you.

sockets asynchronous

No comments:

Post a Comment