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 669810 - socket/win32: flush pending read before signaling HUP
socket/win32: flush pending read before signaling HUP
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-02-10 15:09 UTC by Marc-Andre Lureau
Modified: 2012-02-10 18:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio/tests: add /socket/close_graceful test (3.54 KB, patch)
2012-02-10 15:09 UTC, Marc-Andre Lureau
committed Details | Review
socket/win32: flush pending read before signaling HUP (1.80 KB, patch)
2012-02-10 15:09 UTC, Marc-Andre Lureau
committed Details | Review
gio/tests: add /socket/close_graceful test (3.62 KB, patch)
2012-02-10 16:37 UTC, Marc-Andre Lureau
committed Details | Review
socket/win32: flush pending read before signaling HUP (1.83 KB, patch)
2012-02-10 16:37 UTC, Marc-Andre Lureau
committed Details | Review

Description Marc-Andre Lureau 2012-02-10 15:09:44 UTC
Unix and Windows gio GSocket behaves differently when the socket is
closed by the peer. On Unix, the client receives pending data before
receiving HUP. But on Windows, the HUP may come before, resulting in
unreliable and racy code. We should have same behaviour on all
platforms.

According to MSDN documentation: "an application should check for
remaining data upon receipt of FD_CLOSE to avoid any possibility of
losing data."
Comment 1 Marc-Andre Lureau 2012-02-10 15:09:47 UTC
Created attachment 207262 [details] [review]
gio/tests: add /socket/close_graceful test

Add a test to check that remaining data is read before the close
event is received.
Comment 2 Marc-Andre Lureau 2012-02-10 15:09:50 UTC
Created attachment 207263 [details] [review]
socket/win32: flush pending read before signaling HUP

Unix and Windows gio GSocket behaves differently when the socket is
closed by the peer. On Unix, the client receives pending data before
receiving HUP. But on Windows, the HUP may come before, resulting in
unreliable and racy code. We should have same behaviour on all
platforms.

According to MSDN documentation: "an application should check for
remaining data upon receipt of FD_CLOSE to avoid any possibility of
losing data."
Comment 3 Dan Winship 2012-02-10 15:59:31 UTC
Comment on attachment 207262 [details] [review]
gio/tests: add /socket/close_graceful test

looks good. can you just add a comment to test_close_graceful() pointing out that it's doing the same thing as what g_tcp_connection_set_graceful_disconnect() does?
Comment 4 Dan Winship 2012-02-10 15:59:36 UTC
Comment on attachment 207263 [details] [review]
socket/win32: flush pending read before signaling HUP

>+      int r, error, buffer;
>+
>+      WSASetLastError (0);
>+      r = recv (socket->priv->fd, &buffer, sizeof (buffer), MSG_PEEK);
>+      error = WSAGetLastError ();
>+      WSASetLastError (0);

For consistency with the rest of gsocket.c, use "errsv" as the variable for the error code, and call get_socket_errno() rather than calling WSAGetLastError() directly. Also, you shouldn't need the calls to WSASetLastError(). Just rearrange the checks so that they only look at the error code if r < 0.
Comment 5 Marc-Andre Lureau 2012-02-10 16:37:47 UTC
Created attachment 207269 [details] [review]
gio/tests: add /socket/close_graceful test

Add a test to check that remaining data is read before the close
event is received.
Comment 6 Marc-Andre Lureau 2012-02-10 16:37:50 UTC
Created attachment 207270 [details] [review]
socket/win32: flush pending read before signaling HUP

Unix and Windows gio GSocket behaves differently when the socket is
closed by the peer. On Unix, the client receives pending data before
receiving HUP. But on Windows, the HUP may come before, resulting in
unreliable and racy code. We should have same behaviour on all
platforms.

According to MSDN documentation: "an application should check for
remaining data upon receipt of FD_CLOSE to avoid any possibility of
losing data."
Comment 7 Marc-Andre Lureau 2012-02-10 18:07:57 UTC
Attachment 207262 [details] pushed as 6ca817c - gio/tests: add /socket/close_graceful test
Attachment 207263 [details] pushed as 704a2ca - socket/win32: flush pending read before signaling HUP
Attachment 207269 [details] pushed as 6ca817c - gio/tests: add /socket/close_graceful test
Attachment 207270 [details] pushed as 704a2ca - socket/win32: flush pending read before signaling HUP