summaryrefslogtreecommitdiff
path: root/gio
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2011-08-27 09:59:02 -0400
committerDan Winship <danw@gnome.org>2011-08-27 12:28:03 -0400
commitcef679d004b9fe89ae08519861e235818dd57b46 (patch)
tree9fc4baa0ae0827f3b0c04f4031fa6d2381e1a45c /gio
parent60f23ecbbc7d65eb5188875dc2c50a5f793a82a4 (diff)
GSocket: fix GIOCondition on timed-out socket operation
The docs for g_socket_set_timeout() claimed that if an async operation timed out, the GIOCondition passed to the source callback would be G_IO_IN or G_IO_OUT (thus prompting the caller to call g_socket_receive/send and get a G_IO_ERROR_TIMED_OUT), but in fact it ended up being 0, and gio/tests/socket.c was erroneously testing for that instead of the correct value. Fix this.
Diffstat (limited to 'gio')
-rw-r--r--gio/gsocket.c3
-rw-r--r--gio/tests/socket.c4
2 files changed, 4 insertions, 3 deletions
diff --git a/gio/gsocket.c b/gio/gsocket.c
index f1ba5dd25..77d2d2c81 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -2439,7 +2439,6 @@ socket_source_prepare (GSource *source,
if (*timeout < 0)
{
socket_source->socket->priv->timed_out = TRUE;
- socket_source->pollfd.revents = socket_source->condition & (G_IO_IN | G_IO_OUT);
*timeout = 0;
return TRUE;
}
@@ -2476,6 +2475,8 @@ socket_source_dispatch (GSource *source,
#ifdef G_OS_WIN32
socket_source->pollfd.revents = update_condition (socket_source->socket);
#endif
+ if (socket_source->socket->priv->timed_out)
+ socket_source->pollfd.revents |= socket_source->condition & (G_IO_IN | G_IO_OUT);
return (*func) (socket_source->socket,
socket_source->pollfd.revents & socket_source->condition,
diff --git a/gio/tests/socket.c b/gio/tests/socket.c
index 87b426ef7..2b8ea6270 100644
--- a/gio/tests/socket.c
+++ b/gio/tests/socket.c
@@ -178,7 +178,7 @@ test_ip_async_timed_out (GSocket *client,
if (data->family == G_SOCKET_FAMILY_IPV4)
{
- g_assert_cmpint (cond, ==, 0);
+ g_assert_cmpint (cond, ==, G_IO_IN);
len = g_socket_receive (client, buf, sizeof (buf), NULL, &error);
g_assert_cmpint (len, ==, -1);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT);
@@ -554,7 +554,7 @@ main (int argc,
g_test_add_func ("/socket/ipv4_sync", test_ipv4_sync);
g_test_add_func ("/socket/ipv4_async", test_ipv4_async);
g_test_add_func ("/socket/ipv6_sync", test_ipv6_sync);
- g_test_add_func ("/socket/ipv6_sync", test_ipv6_async);
+ g_test_add_func ("/socket/ipv6_async", test_ipv6_async);
#ifdef G_OS_UNIX
g_test_add_func ("/socket/unix-from-fd", test_unix_from_fd);
g_test_add_func ("/socket/unix-connection", test_unix_connection);