After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 603309 - GSocketOutputStream broken on Windows (?)
GSocketOutputStream broken on Windows (?)
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2009-11-29 16:09 UTC by Dan Winship
Modified: 2010-06-22 19:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GSocketInput/OutputStream: fix non-blocking on Windows (7.80 KB, patch)
2010-04-26 14:53 UTC, Dan Winship
committed Details | Review

Description Dan Winship 2009-11-29 16:09:16 UTC
The GSocket docs warn:

 * When working in non-blocking mode applications should always be able to
 * handle getting a %G_IO_ERROR_WOULD_BLOCK error even when some other
 * function said that I/O was possible. This can easily happen in case
 * of a race condition in the application, but it can also happen for other
 * reasons. For instance, on Windows a socket is always seen as writable
 * until a write returns %G_IO_ERROR_WOULD_BLOCK.

however, GSocketOutputStream assumes that if g_socket_condition_check(G_IO_OUT) returns TRUE, that a following g_socket_send() will either succeed or return a fatal error. This is wrong, right? (GSocketInputStream behaves the same way, though the docs don't explicitly warn against that...)

It seems like the correct behavior, according to the docs, is to not use g_socket_condition_check() at all, but rather to to just immediately attempt to g_socket_send(), and if it fails with G_IO_ERROR_WOULD_BLOCK, then create a source, wait for it to trigger, and try again (and deal with the possibility of G_IO_ERROR_WOULD_BLOCK *again* even after the source triggers).

It almost seems like calling g_socket_condition_check() is *always* wrong...

I'll write the patch, I just want to confirm my understanding.
Comment 1 Dan Winship 2010-04-26 14:53:40 UTC
Created attachment 159608 [details] [review]
GSocketInput/OutputStream: fix non-blocking on Windows

The GSocket docs point out that g_socket_send/g_socket_receive may
return G_IO_ERROR_WOULD_BLOCK even if g_socket_condition_check claimed
that they wouldn't. Fix the socket streams to check for that.
Comment 2 Dan Winship 2010-06-22 19:20:56 UTC
Attachment 159608 [details] pushed as e0ff84e - GSocketInput/OutputStream: fix non-blocking on Windows