Re: Threads, sockets and windows

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

 



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

_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux