Re: Threads, sockets and windows
- From: Vladimir <kv11111 mail ru>
- To: gtk-list gnome org
- Subject: Re: Threads, sockets and windows
- Date: Wed, 09 Aug 2006 13:14:01 +0300
Hello,
> If I recall correctly, one good rule of thumb is to read as much can
> from a GIOChannel when you get the callback that it is readable, until
> you get G_IO_STATUS_AGAIN.
Can I just use g_io_channel_unix_new(socket) to create GIOChannel for
windows socket ?
The main problem in my program is that I need a very low response time for
network packets. GMainLoop is not suitable for me since GIOFunc gets called
too late, especially when some GUI action is in progress. So I'm using a
separate thread for network, and not not using GMainLoop in that thread.
Now I'm trying to select between two possibilities: direct usage of
WSAEventSelect, or creation of two more threads just to watch socket and
pipe and pass messages to the network thread through g_async_queue.
And yes, I do know about testing linux and windows versions simultaneously,
but I've just did not have windows available before now. After
network-related part I'll have to port audio IO part (written in ALSA).
Thanks a lot for your reply !
Tor Lillqvist wrote:
> Armin Burgmeier writes:
> > A probably better approach would be to let glib poll your sockets via
> > creating GIOChannels and using g_io_add_watch to watch for events to
> > occur.
>
> Yep, and this then will in fact use the WSAEventSelect mechanism on
> Windows. (In GLib >= 2.8)
>
> Please note, though, that there are slight differences in semantic
> details when watching socket events using GLib on Unix vs Windows. For
> instance watched sockets automatically become non-blocking on
> Windows. (This is a side-effect of using the WSAEventSelect
> mechanism.) Code that works (at least most of the time...) on Linux
> doesn't necessarily work on Windows, and vice versa. It's best to test
> continuously on both platforms during development, and not just
> attempty a port to Windows after having done all the coding and design
> decisions.
>
> If I recall correctly, one good rule of thumb is to read as much can
> from a GIOChannel when you get the callback that it is readable, until
> you get G_IO_STATUS_AGAIN. And, use the GIOChannel API to read/write
> from them, don't use read()/write()/send()/recv()
> directly. (Especially so as read()/write() don't work on sockets in
> Windows, they work only on the "file descriptors" returbned by
> open().)
>
> --tml
--
Vladimir
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]