Add GCancellables to GSocket ops

Currently, to implement cancellability correctly, all synchronous
calls to GSocket must be preceded by a g_socket_condition_wait() call,
(even though GSocket does this internally as well) and all
asynchronous calls must do occasional manual
g_cancellable_is_cancelled() checks. Since it's trivial to do these
checks inside GSocket instead, and we don't particularly want to
encourage people to use the APIs non-cancellably, move the
cancellation support into GSocket and simplify the existing callers.

http://bugzilla.gnome.org/show_bug.cgi?id=586797
This commit is contained in:
Dan Winship
2009-06-23 17:42:01 -04:00
parent fc2b3ee560
commit 53beca955e
10 changed files with 119 additions and 109 deletions

View File

@@ -175,17 +175,9 @@ g_tcp_connection_close (GIOStream *stream,
{
while (TRUE)
{
if (!g_socket_condition_wait (socket,
G_IO_IN, cancellable, error))
{
had_error = TRUE;
error = NULL;
break;
}
my_error = NULL;
ret = g_socket_receive (socket, buffer, sizeof (buffer),
&my_error);
cancellable, &my_error);
if (ret < 0)
{
if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
@@ -265,15 +257,8 @@ close_read_ready (GSocket *socket,
char buffer[1024];
gssize ret;
if (g_cancellable_set_error_if_cancelled (data->cancellable,
&error))
{
async_close_finish (data, error, TRUE);
g_error_free (error);
return FALSE;
}
ret = g_socket_receive (socket, buffer, sizeof (buffer), &error);
ret = g_socket_receive (socket, buffer, sizeof (buffer),
data->cancellable, &error);
if (ret < 0)
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))