Re: Sockets with GTK 2.8.9 on WIN32

2006-02-13 Thread Gabriele Greco

Daniel Atallah wrote:

That is one of the changes that were made in Glib 2.8.x.  All of the
win32 GIOChannel stuff was changed such that it'll leave your sockets
in non-blocking mode.  See this bug report for more information: 
http://bugzilla.gnome.org/show_bug.cgi?id=147392
  
This seems very strange for me since glib 2.8 on Unix does not behave 
this way.


How can GTK be used as a multiplatform development system if it behave 
in different ways for the different platform it supports?

Basically, if you want your socket to be non-blocking, you have to
make it so in the input function every time it is triggered.
  
So I've to add something like this in my input function (error checking 
omitted):


#ifdef WIN32
   unsigned long par = 0;
   ioctlsocket(fd, FIONBIO, par);
#endif

This is quite ugly.

I thought that I had seen this in the documentation somewhere, but
apparently not.
  

I've not found anything related to GLIB 2.6 - 2.8 differences at least at:

http://www.gtk.org/api/

(incompatible differences seems related to 2.0 - 2.2 migration)

Bye,
Gabry


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Sockets with GTK 2.8.9 on WIN32

2006-02-13 Thread Tor Lillqvist
Gabriele Greco writes:
  This seems very strange for me since glib 2.8 on Unix does not behave 
  this way.

Well, Windows isn't Unix, so is it really that surprising that some
things are fundamentally different?

With hindsight it's easy to say that the affected APIs and
abstractions in GLib should perhaps have been designed differently so
that any Unix/Windows differences could have been better hidden. But,
we have to make use of what we have now.

Actually, I think that the original thoughts were that the affected
GLib APIs (GPollFDs, GMainLoop, etc) could have been much more
platform specific. Owen says in bug #120299:

I don't think usage and contents of GPollFD needs to be or
should be portable across Win32/Unix, though changing how
it works is probably an API change on Win32.

My original conception was that GMainLoop would be significantly
different on different operating systems, though GPollFD *
crept into more of the API (g_main_context_query()) for
GTK+-2.x.

That many things then turned out to be implementable on Windows
without requiring ifdefs in GLib-using code was an unexpected positive
surprise. Or something like that...

  How can GTK be used as a multiplatform development system if it behave 
  in different ways for the different platform it supports?

You just have to take those things that behave differently into
account in your code.

Trust me, the implementation of watched GIOChannels for sockets on
Windows in GLib before 2.8 had a wholly different and more serious set
of problems and Unix/Windows differences. Those caused a lot of
problems when porting various GNOME platform libraries to Windows. See
discussion for instance in bugs #120299 and #147392. In the old
implementation there was a separate thread running per watched socket.

  So I've to add something like this in my input function (error checking 
  omitted):

  #ifdef WIN32
  unsigned long par = 0;
  ioctlsocket(fd, FIONBIO, par);
  #endif

Actually I don't think that will work. As long as a socket is being
watched (it has an event selection for it (WSAEventSelect()) in force)
you cannot turn the non-blockingness off.

Anyway, as you use GLib mainloop functionality and watched GIOchannels
in the first place, isn't your intention to avoid blocking calls in
your code? You perhaps want to handle reading requests from and
sending replies to multiple sockets in parallel with minimum delay?
Otherwise you could just use blocking recv() and send() all the time
without bothering with GIOChannels and GMainLoops, couldn't you?

So shouldn't you be using non-blocking mode on Unix, too, then? Aren't
you otherwise just knowing your recv()/send() calls won't block
(because they never do in your test environment), and when they then
occasionally *do* block, perhaps indefinitely, in the end-user
environment, you are in trouble?

  I've not found anything related to GLIB 2.6 - 2.8 differences at least at:
  
  http://www.gtk.org/api/

Yeah, the documentation needs to have a mention about it added.

--tml

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Sockets with GTK 2.8.9 on WIN32

2006-02-10 Thread Daniel Atallah
On 2/10/06, Gabriele Greco [EMAIL PROTECTED] wrote:
 I've a problem on an application on WIN32 with GTK 2.8.x that works
 flawlessly with GTK 2.6.x (always on win32) or GTK 2.8.x (on unix).

 It seems that with 2.8.9 (the installer version got from gimp-win home)
 the sockets are handled as non blocking also if you don't specify this.

 It's a wanted behaviour?

 Specifically I often receive 0 if I call recv() in my gdk_input_add(
 GDK_INPUT_READ ) call, this happens on GTK 2.6 and early only when the
 connection is closed by the remote peer.

 With GTK 2.8, and only on WIN32, I often receive 0 from recv and an
 error code of WSAEWOULDBLOCK.

 This is a problem since my code often rely on the fact socket calls are
 blocking...

That is one of the changes that were made in Glib 2.8.x.  All of the
win32 GIOChannel stuff was changed such that it'll leave your sockets
in non-blocking mode.  See this bug report for more information: 
http://bugzilla.gnome.org/show_bug.cgi?id=147392

Basically, if you want your socket to be non-blocking, you have to
make it so in the input function every time it is triggered.

I thought that I had seen this in the documentation somewhere, but
apparently not.

-D
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list