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

@@ -114,11 +114,8 @@ g_socket_output_stream_write (GOutputStream *stream,
{
GSocketOutputStream *onput_stream = G_SOCKET_OUTPUT_STREAM (stream);
if (!g_socket_condition_wait (onput_stream->priv->socket,
G_IO_OUT, cancellable, error))
return -1;
return g_socket_send (onput_stream->priv->socket, buffer, count, error);
return g_socket_send (onput_stream->priv->socket, buffer, count,
cancellable, error);
}
static gboolean
@@ -128,22 +125,18 @@ g_socket_output_stream_write_ready (GSocket *socket,
{
GSimpleAsyncResult *simple;
GError *error = NULL;
gssize result;
simple = stream->priv->result;
stream->priv->result = NULL;
if (!g_cancellable_set_error_if_cancelled (stream->priv->cancellable,
&error))
{
gssize result;
result = g_socket_send (stream->priv->socket,
stream->priv->buffer,
stream->priv->count,
&error);
if (result >= 0)
g_simple_async_result_set_op_res_gssize (simple, result);
}
result = g_socket_send (stream->priv->socket,
stream->priv->buffer,
stream->priv->count,
stream->priv->cancellable,
&error);
if (result >= 0)
g_simple_async_result_set_op_res_gssize (simple, result);
if (error)
{