GNOME Bugzilla – Bug 603309
GSocketOutputStream broken on Windows (?)
Last modified: 2010-06-22 19:20:58 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.
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.
Attachment 159608 [details] pushed as e0ff84e - GSocketInput/OutputStream: fix non-blocking on Windows