mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-14 05:16:18 +01:00
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:
parent
fc2b3ee560
commit
53beca955e
@ -1332,6 +1332,7 @@ g_socket_speaks_ipv4 (GSocket *socket)
|
|||||||
/**
|
/**
|
||||||
* g_socket_accept:
|
* g_socket_accept:
|
||||||
* @socket: a #GSocket.
|
* @socket: a #GSocket.
|
||||||
|
* @cancellable: a %GCancellable or %NULL
|
||||||
* @error: #GError for error reporting, or %NULL to ignore.
|
* @error: #GError for error reporting, or %NULL to ignore.
|
||||||
*
|
*
|
||||||
* Accept incoming connections on a connection-based socket. This removes
|
* Accept incoming connections on a connection-based socket. This removes
|
||||||
@ -1352,6 +1353,7 @@ g_socket_speaks_ipv4 (GSocket *socket)
|
|||||||
*/
|
*/
|
||||||
GSocket *
|
GSocket *
|
||||||
g_socket_accept (GSocket *socket,
|
g_socket_accept (GSocket *socket,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GSocket *new_socket;
|
GSocket *new_socket;
|
||||||
@ -1366,7 +1368,7 @@ g_socket_accept (GSocket *socket,
|
|||||||
{
|
{
|
||||||
if (socket->priv->blocking &&
|
if (socket->priv->blocking &&
|
||||||
!g_socket_condition_wait (socket,
|
!g_socket_condition_wait (socket,
|
||||||
G_IO_IN, NULL, error))
|
G_IO_IN, cancellable, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((ret = accept (socket->priv->fd, NULL, 0)) < 0)
|
if ((ret = accept (socket->priv->fd, NULL, 0)) < 0)
|
||||||
@ -1442,6 +1444,7 @@ g_socket_accept (GSocket *socket,
|
|||||||
* g_socket_connect:
|
* g_socket_connect:
|
||||||
* @socket: a #GSocket.
|
* @socket: a #GSocket.
|
||||||
* @address: a #GSocketAddress specifying the remote address.
|
* @address: a #GSocketAddress specifying the remote address.
|
||||||
|
* @cancellable: a %GCancellable or %NULL
|
||||||
* @error: #GError for error reporting, or %NULL to ignore.
|
* @error: #GError for error reporting, or %NULL to ignore.
|
||||||
*
|
*
|
||||||
* Connect the socket to the specified remote address.
|
* Connect the socket to the specified remote address.
|
||||||
@ -1468,6 +1471,7 @@ g_socket_accept (GSocket *socket,
|
|||||||
gboolean
|
gboolean
|
||||||
g_socket_connect (GSocket *socket,
|
g_socket_connect (GSocket *socket,
|
||||||
GSocketAddress *address,
|
GSocketAddress *address,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage buffer;
|
struct sockaddr_storage buffer;
|
||||||
@ -1498,10 +1502,11 @@ g_socket_connect (GSocket *socket,
|
|||||||
{
|
{
|
||||||
if (socket->priv->blocking)
|
if (socket->priv->blocking)
|
||||||
{
|
{
|
||||||
g_socket_condition_wait (socket, G_IO_OUT, NULL, NULL);
|
if (g_socket_condition_wait (socket, G_IO_OUT, cancellable, error))
|
||||||
|
{
|
||||||
if (g_socket_check_connect_result (socket, error))
|
if (g_socket_check_connect_result (socket, error))
|
||||||
break;
|
break;
|
||||||
else
|
}
|
||||||
g_prefix_error (error, _("Error connecting: "));
|
g_prefix_error (error, _("Error connecting: "));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1570,6 +1575,7 @@ g_socket_check_connect_result (GSocket *socket,
|
|||||||
* @buffer: a buffer to read data into (which should be at least @size
|
* @buffer: a buffer to read data into (which should be at least @size
|
||||||
* bytes long).
|
* bytes long).
|
||||||
* @size: the number of bytes you want to read from the socket
|
* @size: the number of bytes you want to read from the socket
|
||||||
|
* @cancellable: a %GCancellable or %NULL
|
||||||
* @error: #GError for error reporting, or %NULL to ignore.
|
* @error: #GError for error reporting, or %NULL to ignore.
|
||||||
*
|
*
|
||||||
* Receive data (up to @size bytes) from a socket. This is mainly used by
|
* Receive data (up to @size bytes) from a socket. This is mainly used by
|
||||||
@ -1603,6 +1609,7 @@ gssize
|
|||||||
g_socket_receive (GSocket *socket,
|
g_socket_receive (GSocket *socket,
|
||||||
gchar *buffer,
|
gchar *buffer,
|
||||||
gsize size,
|
gsize size,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gssize ret;
|
gssize ret;
|
||||||
@ -1612,11 +1619,14 @@ g_socket_receive (GSocket *socket,
|
|||||||
if (!check_socket (socket, error))
|
if (!check_socket (socket, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||||
|
return -1;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (socket->priv->blocking &&
|
if (socket->priv->blocking &&
|
||||||
!g_socket_condition_wait (socket,
|
!g_socket_condition_wait (socket,
|
||||||
G_IO_IN, NULL, error))
|
G_IO_IN, cancellable, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((ret = recv (socket->priv->fd, buffer, size, 0)) < 0)
|
if ((ret = recv (socket->priv->fd, buffer, size, 0)) < 0)
|
||||||
@ -1661,6 +1671,7 @@ g_socket_receive (GSocket *socket,
|
|||||||
* @buffer: a buffer to read data into (which should be at least @size
|
* @buffer: a buffer to read data into (which should be at least @size
|
||||||
* bytes long).
|
* bytes long).
|
||||||
* @size: the number of bytes you want to read from the socket
|
* @size: the number of bytes you want to read from the socket
|
||||||
|
* @cancellable: a %GCancellable or %NULL
|
||||||
* @error: #GError for error reporting, or %NULL to ignore.
|
* @error: #GError for error reporting, or %NULL to ignore.
|
||||||
*
|
*
|
||||||
* Receive data (up to @size bytes) from a socket.
|
* Receive data (up to @size bytes) from a socket.
|
||||||
@ -1680,6 +1691,7 @@ g_socket_receive_from (GSocket *socket,
|
|||||||
GSocketAddress **address,
|
GSocketAddress **address,
|
||||||
gchar *buffer,
|
gchar *buffer,
|
||||||
gsize size,
|
gsize size,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GInputVector v;
|
GInputVector v;
|
||||||
@ -1691,6 +1703,7 @@ g_socket_receive_from (GSocket *socket,
|
|||||||
address,
|
address,
|
||||||
&v, 1,
|
&v, 1,
|
||||||
NULL, 0, NULL,
|
NULL, 0, NULL,
|
||||||
|
cancellable,
|
||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1699,6 +1712,7 @@ g_socket_receive_from (GSocket *socket,
|
|||||||
* @socket: a #GSocket
|
* @socket: a #GSocket
|
||||||
* @buffer: the buffer containing the data to send.
|
* @buffer: the buffer containing the data to send.
|
||||||
* @size: the number of bytes to send
|
* @size: the number of bytes to send
|
||||||
|
* @cancellable: a %GCancellable or %NULL
|
||||||
* @error: #GError for error reporting, or %NULL to ignore.
|
* @error: #GError for error reporting, or %NULL to ignore.
|
||||||
*
|
*
|
||||||
* Tries to send @size bytes from @buffer on the socket. This is
|
* Tries to send @size bytes from @buffer on the socket. This is
|
||||||
@ -1725,6 +1739,7 @@ gssize
|
|||||||
g_socket_send (GSocket *socket,
|
g_socket_send (GSocket *socket,
|
||||||
const gchar *buffer,
|
const gchar *buffer,
|
||||||
gsize size,
|
gsize size,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gssize ret;
|
gssize ret;
|
||||||
@ -1734,11 +1749,14 @@ g_socket_send (GSocket *socket,
|
|||||||
if (!check_socket (socket, error))
|
if (!check_socket (socket, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||||
|
return -1;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (socket->priv->blocking &&
|
if (socket->priv->blocking &&
|
||||||
!g_socket_condition_wait (socket,
|
!g_socket_condition_wait (socket,
|
||||||
G_IO_OUT, NULL, error))
|
G_IO_OUT, cancellable, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((ret = send (socket->priv->fd, buffer, size, 0)) < 0)
|
if ((ret = send (socket->priv->fd, buffer, size, 0)) < 0)
|
||||||
@ -1782,6 +1800,7 @@ g_socket_send (GSocket *socket,
|
|||||||
* @address: a #GSocketAddress, or %NULL
|
* @address: a #GSocketAddress, or %NULL
|
||||||
* @buffer: the buffer containing the data to send.
|
* @buffer: the buffer containing the data to send.
|
||||||
* @size: the number of bytes to send
|
* @size: the number of bytes to send
|
||||||
|
* @cancellable: a %GCancellable or %NULL
|
||||||
* @error: #GError for error reporting, or %NULL to ignore.
|
* @error: #GError for error reporting, or %NULL to ignore.
|
||||||
*
|
*
|
||||||
* Tries to send @size bytes from @buffer to @address. If @address is
|
* Tries to send @size bytes from @buffer to @address. If @address is
|
||||||
@ -1800,6 +1819,7 @@ g_socket_send_to (GSocket *socket,
|
|||||||
GSocketAddress *address,
|
GSocketAddress *address,
|
||||||
const gchar *buffer,
|
const gchar *buffer,
|
||||||
gsize size,
|
gsize size,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GOutputVector v;
|
GOutputVector v;
|
||||||
@ -1811,7 +1831,9 @@ g_socket_send_to (GSocket *socket,
|
|||||||
address,
|
address,
|
||||||
&v, 1,
|
&v, 1,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
0, error);
|
0,
|
||||||
|
cancellable,
|
||||||
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2491,6 +2513,7 @@ g_socket_condition_wait (GSocket *socket,
|
|||||||
* %NULL.
|
* %NULL.
|
||||||
* @num_messages: number of elements in @messages, or -1.
|
* @num_messages: number of elements in @messages, or -1.
|
||||||
* @flags: an int containing #GSocketMsgFlags flags
|
* @flags: an int containing #GSocketMsgFlags flags
|
||||||
|
* @cancellable: a %GCancellable or %NULL
|
||||||
* @error: #GError for error reporting, or %NULL to ignore.
|
* @error: #GError for error reporting, or %NULL to ignore.
|
||||||
*
|
*
|
||||||
* Send data to @address on @socket. This is the most complicated and
|
* Send data to @address on @socket. This is the most complicated and
|
||||||
@ -2544,6 +2567,7 @@ g_socket_send_message (GSocket *socket,
|
|||||||
GSocketControlMessage **messages,
|
GSocketControlMessage **messages,
|
||||||
gint num_messages,
|
gint num_messages,
|
||||||
gint flags,
|
gint flags,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GOutputVector one_vector;
|
GOutputVector one_vector;
|
||||||
@ -2552,6 +2576,9 @@ g_socket_send_message (GSocket *socket,
|
|||||||
if (!check_socket (socket, error))
|
if (!check_socket (socket, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (num_vectors == -1)
|
if (num_vectors == -1)
|
||||||
{
|
{
|
||||||
for (num_vectors = 0;
|
for (num_vectors = 0;
|
||||||
@ -2650,7 +2677,7 @@ g_socket_send_message (GSocket *socket,
|
|||||||
{
|
{
|
||||||
if (socket->priv->blocking &&
|
if (socket->priv->blocking &&
|
||||||
!g_socket_condition_wait (socket,
|
!g_socket_condition_wait (socket,
|
||||||
G_IO_OUT, NULL, error))
|
G_IO_OUT, cancellable, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
result = sendmsg (socket->priv->fd, &msg, flags);
|
result = sendmsg (socket->priv->fd, &msg, flags);
|
||||||
@ -2718,7 +2745,7 @@ g_socket_send_message (GSocket *socket,
|
|||||||
{
|
{
|
||||||
if (socket->priv->blocking &&
|
if (socket->priv->blocking &&
|
||||||
!g_socket_condition_wait (socket,
|
!g_socket_condition_wait (socket,
|
||||||
G_IO_OUT, NULL, error))
|
G_IO_OUT, cancellable, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (address)
|
if (address)
|
||||||
@ -2772,6 +2799,7 @@ g_socket_send_message (GSocket *socket,
|
|||||||
* @num_messages: a pointer which will be filled with the number of
|
* @num_messages: a pointer which will be filled with the number of
|
||||||
* elements in @messages, or %NULL
|
* elements in @messages, or %NULL
|
||||||
* @flags: a pointer to an int containing #GSocketMsgFlags flags
|
* @flags: a pointer to an int containing #GSocketMsgFlags flags
|
||||||
|
* @cancellable: a %GCancellable or %NULL
|
||||||
* @error: a #GError pointer, or %NULL
|
* @error: a #GError pointer, or %NULL
|
||||||
*
|
*
|
||||||
* Receive data from a socket. This is the most complicated and
|
* Receive data from a socket. This is the most complicated and
|
||||||
@ -2842,6 +2870,7 @@ g_socket_receive_message (GSocket *socket,
|
|||||||
GSocketControlMessage ***messages,
|
GSocketControlMessage ***messages,
|
||||||
gint *num_messages,
|
gint *num_messages,
|
||||||
gint *flags,
|
gint *flags,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GInputVector one_vector;
|
GInputVector one_vector;
|
||||||
@ -2850,6 +2879,9 @@ g_socket_receive_message (GSocket *socket,
|
|||||||
if (!check_socket (socket, error))
|
if (!check_socket (socket, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (num_vectors == -1)
|
if (num_vectors == -1)
|
||||||
{
|
{
|
||||||
for (num_vectors = 0;
|
for (num_vectors = 0;
|
||||||
@ -2927,7 +2959,7 @@ g_socket_receive_message (GSocket *socket,
|
|||||||
{
|
{
|
||||||
if (socket->priv->blocking &&
|
if (socket->priv->blocking &&
|
||||||
!g_socket_condition_wait (socket,
|
!g_socket_condition_wait (socket,
|
||||||
G_IO_IN, NULL, error))
|
G_IO_IN, cancellable, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
result = recvmsg (socket->priv->fd, &msg, msg.msg_flags);
|
result = recvmsg (socket->priv->fd, &msg, msg.msg_flags);
|
||||||
@ -3055,7 +3087,7 @@ g_socket_receive_message (GSocket *socket,
|
|||||||
{
|
{
|
||||||
if (socket->priv->blocking &&
|
if (socket->priv->blocking &&
|
||||||
!g_socket_condition_wait (socket,
|
!g_socket_condition_wait (socket,
|
||||||
G_IO_IN, NULL, error))
|
G_IO_IN, cancellable, error))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
addrlen = sizeof addr;
|
addrlen = sizeof addr;
|
||||||
|
@ -104,6 +104,7 @@ gboolean g_socket_bind (GSocket
|
|||||||
GError **error);
|
GError **error);
|
||||||
gboolean g_socket_connect (GSocket *socket,
|
gboolean g_socket_connect (GSocket *socket,
|
||||||
GSocketAddress *address,
|
GSocketAddress *address,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gboolean g_socket_check_connect_result (GSocket *socket,
|
gboolean g_socket_check_connect_result (GSocket *socket,
|
||||||
GError **error);
|
GError **error);
|
||||||
@ -114,26 +115,31 @@ gboolean g_socket_condition_wait (GSocket
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
GSocket * g_socket_accept (GSocket *socket,
|
GSocket * g_socket_accept (GSocket *socket,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gboolean g_socket_listen (GSocket *socket,
|
gboolean g_socket_listen (GSocket *socket,
|
||||||
GError **error);
|
GError **error);
|
||||||
gssize g_socket_receive (GSocket *socket,
|
gssize g_socket_receive (GSocket *socket,
|
||||||
gchar *buffer,
|
gchar *buffer,
|
||||||
gsize size,
|
gsize size,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gssize g_socket_receive_from (GSocket *socket,
|
gssize g_socket_receive_from (GSocket *socket,
|
||||||
GSocketAddress **address,
|
GSocketAddress **address,
|
||||||
gchar *buffer,
|
gchar *buffer,
|
||||||
gsize size,
|
gsize size,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gssize g_socket_send (GSocket *socket,
|
gssize g_socket_send (GSocket *socket,
|
||||||
const gchar *buffer,
|
const gchar *buffer,
|
||||||
gsize size,
|
gsize size,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gssize g_socket_send_to (GSocket *socket,
|
gssize g_socket_send_to (GSocket *socket,
|
||||||
GSocketAddress *address,
|
GSocketAddress *address,
|
||||||
const gchar *buffer,
|
const gchar *buffer,
|
||||||
gsize size,
|
gsize size,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gssize g_socket_receive_message (GSocket *socket,
|
gssize g_socket_receive_message (GSocket *socket,
|
||||||
GSocketAddress **address,
|
GSocketAddress **address,
|
||||||
@ -142,6 +148,7 @@ gssize g_socket_receive_message (GSocket
|
|||||||
GSocketControlMessage ***messages,
|
GSocketControlMessage ***messages,
|
||||||
gint *num_messages,
|
gint *num_messages,
|
||||||
gint *flags,
|
gint *flags,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gssize g_socket_send_message (GSocket *socket,
|
gssize g_socket_send_message (GSocket *socket,
|
||||||
GSocketAddress *address,
|
GSocketAddress *address,
|
||||||
@ -150,6 +157,7 @@ gssize g_socket_send_message (GSocket
|
|||||||
GSocketControlMessage **messages,
|
GSocketControlMessage **messages,
|
||||||
gint num_messages,
|
gint num_messages,
|
||||||
gint flags,
|
gint flags,
|
||||||
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
gboolean g_socket_close (GSocket *socket,
|
gboolean g_socket_close (GSocket *socket,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
@ -528,7 +528,7 @@ g_socket_client_connect (GSocketClient *client,
|
|||||||
socket = create_socket (client, address, &last_error);
|
socket = create_socket (client, address, &last_error);
|
||||||
if (socket != NULL)
|
if (socket != NULL)
|
||||||
{
|
{
|
||||||
if (g_socket_connect (socket, address, &last_error))
|
if (g_socket_connect (socket, address, cancellable, &last_error))
|
||||||
connection = g_socket_connection_factory_create_connection (socket);
|
connection = g_socket_connection_factory_create_connection (socket);
|
||||||
|
|
||||||
g_object_unref (socket);
|
g_object_unref (socket);
|
||||||
@ -776,7 +776,7 @@ g_socket_client_enumerator_callback (GObject *object,
|
|||||||
if (socket != NULL)
|
if (socket != NULL)
|
||||||
{
|
{
|
||||||
g_socket_set_blocking (socket, FALSE);
|
g_socket_set_blocking (socket, FALSE);
|
||||||
if (g_socket_connect (socket, address, &tmp_error))
|
if (g_socket_connect (socket, address, data->cancellable, &tmp_error))
|
||||||
{
|
{
|
||||||
data->current_socket = socket;
|
data->current_socket = socket;
|
||||||
g_socket_client_async_connect_complete (data);
|
g_socket_client_async_connect_complete (data);
|
||||||
|
@ -112,11 +112,8 @@ g_socket_input_stream_read (GInputStream *stream,
|
|||||||
{
|
{
|
||||||
GSocketInputStream *input_stream = G_SOCKET_INPUT_STREAM (stream);
|
GSocketInputStream *input_stream = G_SOCKET_INPUT_STREAM (stream);
|
||||||
|
|
||||||
if (!g_socket_condition_wait (input_stream->priv->socket,
|
return g_socket_receive (input_stream->priv->socket, buffer, count,
|
||||||
G_IO_IN, cancellable, error))
|
cancellable, error);
|
||||||
return -1;
|
|
||||||
|
|
||||||
return g_socket_receive (input_stream->priv->socket, buffer, count, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -126,22 +123,18 @@ g_socket_input_stream_read_ready (GSocket *socket,
|
|||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
GSimpleAsyncResult *simple;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
gssize result;
|
||||||
|
|
||||||
simple = stream->priv->result;
|
simple = stream->priv->result;
|
||||||
stream->priv->result = NULL;
|
stream->priv->result = NULL;
|
||||||
|
|
||||||
if (!g_cancellable_set_error_if_cancelled (stream->priv->cancellable,
|
|
||||||
&error))
|
|
||||||
{
|
|
||||||
gssize result;
|
|
||||||
|
|
||||||
result = g_socket_receive (stream->priv->socket,
|
result = g_socket_receive (stream->priv->socket,
|
||||||
stream->priv->buffer,
|
stream->priv->buffer,
|
||||||
stream->priv->count,
|
stream->priv->count,
|
||||||
|
stream->priv->cancellable,
|
||||||
&error);
|
&error);
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
g_simple_async_result_set_op_res_gssize (simple, result);
|
g_simple_async_result_set_op_res_gssize (simple, result);
|
||||||
}
|
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
@ -628,7 +628,7 @@ g_socket_listener_accept_socket (GSocketListener *listener,
|
|||||||
g_main_loop_unref (loop);
|
g_main_loop_unref (loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(socket = g_socket_accept (accept_socket, error)))
|
if (!(socket = g_socket_accept (accept_socket, cancellable, error)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (source_object)
|
if (source_object)
|
||||||
@ -695,14 +695,10 @@ accept_ready (GSocket *accept_socket,
|
|||||||
{
|
{
|
||||||
struct AcceptAsyncData *data = _data;
|
struct AcceptAsyncData *data = _data;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!g_cancellable_set_error_if_cancelled (data->cancellable,
|
|
||||||
&error))
|
|
||||||
{
|
|
||||||
GSocket *socket;
|
GSocket *socket;
|
||||||
GObject *source_object;
|
GObject *source_object;
|
||||||
|
|
||||||
socket = g_socket_accept (accept_socket, &error);
|
socket = g_socket_accept (accept_socket, data->cancellable, &error);
|
||||||
if (socket)
|
if (socket)
|
||||||
{
|
{
|
||||||
g_simple_async_result_set_op_res_gpointer (data->simple, socket,
|
g_simple_async_result_set_op_res_gpointer (data->simple, socket,
|
||||||
@ -713,9 +709,7 @@ accept_ready (GSocket *accept_socket,
|
|||||||
source_quark,
|
source_quark,
|
||||||
g_object_ref (source_object), g_object_unref);
|
g_object_ref (source_object), g_object_unref);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
if (error)
|
|
||||||
{
|
{
|
||||||
g_simple_async_result_set_from_error (data->simple, error);
|
g_simple_async_result_set_from_error (data->simple, error);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
@ -114,11 +114,8 @@ g_socket_output_stream_write (GOutputStream *stream,
|
|||||||
{
|
{
|
||||||
GSocketOutputStream *onput_stream = G_SOCKET_OUTPUT_STREAM (stream);
|
GSocketOutputStream *onput_stream = G_SOCKET_OUTPUT_STREAM (stream);
|
||||||
|
|
||||||
if (!g_socket_condition_wait (onput_stream->priv->socket,
|
return g_socket_send (onput_stream->priv->socket, buffer, count,
|
||||||
G_IO_OUT, cancellable, error))
|
cancellable, error);
|
||||||
return -1;
|
|
||||||
|
|
||||||
return g_socket_send (onput_stream->priv->socket, buffer, count, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -128,22 +125,18 @@ g_socket_output_stream_write_ready (GSocket *socket,
|
|||||||
{
|
{
|
||||||
GSimpleAsyncResult *simple;
|
GSimpleAsyncResult *simple;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
gssize result;
|
||||||
|
|
||||||
simple = stream->priv->result;
|
simple = stream->priv->result;
|
||||||
stream->priv->result = NULL;
|
stream->priv->result = NULL;
|
||||||
|
|
||||||
if (!g_cancellable_set_error_if_cancelled (stream->priv->cancellable,
|
|
||||||
&error))
|
|
||||||
{
|
|
||||||
gssize result;
|
|
||||||
|
|
||||||
result = g_socket_send (stream->priv->socket,
|
result = g_socket_send (stream->priv->socket,
|
||||||
stream->priv->buffer,
|
stream->priv->buffer,
|
||||||
stream->priv->count,
|
stream->priv->count,
|
||||||
|
stream->priv->cancellable,
|
||||||
&error);
|
&error);
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
g_simple_async_result_set_op_res_gssize (simple, result);
|
g_simple_async_result_set_op_res_gssize (simple, result);
|
||||||
}
|
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
@ -175,17 +175,9 @@ g_tcp_connection_close (GIOStream *stream,
|
|||||||
{
|
{
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
if (!g_socket_condition_wait (socket,
|
|
||||||
G_IO_IN, cancellable, error))
|
|
||||||
{
|
|
||||||
had_error = TRUE;
|
|
||||||
error = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
my_error = NULL;
|
my_error = NULL;
|
||||||
ret = g_socket_receive (socket, buffer, sizeof (buffer),
|
ret = g_socket_receive (socket, buffer, sizeof (buffer),
|
||||||
&my_error);
|
cancellable, &my_error);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
|
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];
|
char buffer[1024];
|
||||||
gssize ret;
|
gssize ret;
|
||||||
|
|
||||||
if (g_cancellable_set_error_if_cancelled (data->cancellable,
|
ret = g_socket_receive (socket, buffer, sizeof (buffer),
|
||||||
&error))
|
data->cancellable, &error);
|
||||||
{
|
|
||||||
async_close_finish (data, error, TRUE);
|
|
||||||
g_error_free (error);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = g_socket_receive (socket, buffer, sizeof (buffer), &error);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
|
||||||
|
@ -86,8 +86,7 @@ g_unix_connection_send_fd (GUnixConnection *connection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_object_get (connection, "socket", &socket, NULL);
|
g_object_get (connection, "socket", &socket, NULL);
|
||||||
if (!g_socket_condition_wait (socket, G_IO_OUT, cancellable, error) ||
|
if (g_socket_send_message (socket, NULL, NULL, 0, &scm, 1, 0, cancellable, error) != 1)
|
||||||
g_socket_send_message (socket, NULL, NULL, 0, &scm, 1, 0, error) != 1)
|
|
||||||
/* XXX could it 'fail' with zero? */
|
/* XXX could it 'fail' with zero? */
|
||||||
{
|
{
|
||||||
g_object_unref (socket);
|
g_object_unref (socket);
|
||||||
@ -133,9 +132,8 @@ g_unix_connection_receive_fd (GUnixConnection *connection,
|
|||||||
g_return_val_if_fail (G_IS_UNIX_CONNECTION (connection), -1);
|
g_return_val_if_fail (G_IS_UNIX_CONNECTION (connection), -1);
|
||||||
|
|
||||||
g_object_get (connection, "socket", &socket, NULL);
|
g_object_get (connection, "socket", &socket, NULL);
|
||||||
if (!g_socket_condition_wait (socket, G_IO_IN, cancellable, error) ||
|
if (g_socket_receive_message (socket, NULL, NULL, 0,
|
||||||
g_socket_receive_message (socket, NULL, NULL, 0,
|
&scms, &nscm, NULL, cancellable, error) != 1)
|
||||||
&scms, &nscm, NULL, error) != 1)
|
|
||||||
/* XXX it _could_ 'fail' with zero. */
|
/* XXX it _could_ 'fail' with zero. */
|
||||||
{
|
{
|
||||||
g_object_unref (socket);
|
g_object_unref (socket);
|
||||||
|
@ -172,7 +172,7 @@ main (int argc,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_socket_connect (socket, address, &error))
|
if (g_socket_connect (socket, address, cancellable, &error))
|
||||||
break;
|
break;
|
||||||
g_printerr ("%s: Connection to %s failed: %s, trying next\n", argv[0], socket_address_to_string (address), error->message);
|
g_printerr ("%s: Connection to %s failed: %s, trying next\n", argv[0], socket_address_to_string (address), error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
@ -215,9 +215,11 @@ main (int argc,
|
|||||||
ensure_condition (socket, "send", cancellable, G_IO_OUT);
|
ensure_condition (socket, "send", cancellable, G_IO_OUT);
|
||||||
if (use_udp)
|
if (use_udp)
|
||||||
size = g_socket_send_to (socket, address,
|
size = g_socket_send_to (socket, address,
|
||||||
buffer, to_send, &error);
|
buffer, to_send,
|
||||||
|
cancellable, &error);
|
||||||
else
|
else
|
||||||
size = g_socket_send (socket, buffer, to_send, &error);
|
size = g_socket_send (socket, buffer, to_send,
|
||||||
|
cancellable, &error);
|
||||||
|
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
{
|
{
|
||||||
@ -252,9 +254,11 @@ main (int argc,
|
|||||||
ensure_condition (socket, "receive", cancellable, G_IO_IN);
|
ensure_condition (socket, "receive", cancellable, G_IO_IN);
|
||||||
if (use_udp)
|
if (use_udp)
|
||||||
size = g_socket_receive_from (socket, &src_address,
|
size = g_socket_receive_from (socket, &src_address,
|
||||||
buffer, sizeof buffer, &error);
|
buffer, sizeof buffer,
|
||||||
|
cancellable, &error);
|
||||||
else
|
else
|
||||||
size = g_socket_receive (socket, buffer, sizeof buffer, &error);
|
size = g_socket_receive (socket, buffer, sizeof buffer,
|
||||||
|
cancellable, &error);
|
||||||
|
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
{
|
{
|
||||||
|
@ -170,7 +170,7 @@ main (int argc,
|
|||||||
g_print ("listening on port %d...\n", port);
|
g_print ("listening on port %d...\n", port);
|
||||||
|
|
||||||
ensure_condition (socket, "accept", cancellable, G_IO_IN);
|
ensure_condition (socket, "accept", cancellable, G_IO_IN);
|
||||||
new_socket = g_socket_accept (socket, &error);
|
new_socket = g_socket_accept (socket, cancellable, &error);
|
||||||
if (!new_socket)
|
if (!new_socket)
|
||||||
{
|
{
|
||||||
g_printerr ("Error accepting socket: %s\n",
|
g_printerr ("Error accepting socket: %s\n",
|
||||||
@ -211,9 +211,11 @@ main (int argc,
|
|||||||
ensure_condition (recv_socket, "receive", cancellable, G_IO_IN);
|
ensure_condition (recv_socket, "receive", cancellable, G_IO_IN);
|
||||||
if (use_udp)
|
if (use_udp)
|
||||||
size = g_socket_receive_from (recv_socket, &address,
|
size = g_socket_receive_from (recv_socket, &address,
|
||||||
buffer, sizeof buffer, &error);
|
buffer, sizeof buffer,
|
||||||
|
cancellable, &error);
|
||||||
else
|
else
|
||||||
size = g_socket_receive (recv_socket, buffer, sizeof buffer, &error);
|
size = g_socket_receive (recv_socket, buffer, sizeof buffer,
|
||||||
|
cancellable, &error);
|
||||||
|
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
{
|
{
|
||||||
@ -243,9 +245,10 @@ main (int argc,
|
|||||||
ensure_condition (recv_socket, "send", cancellable, G_IO_OUT);
|
ensure_condition (recv_socket, "send", cancellable, G_IO_OUT);
|
||||||
if (use_udp)
|
if (use_udp)
|
||||||
size = g_socket_send_to (recv_socket, address,
|
size = g_socket_send_to (recv_socket, address,
|
||||||
buffer, to_send, &error);
|
buffer, to_send, cancellable, &error);
|
||||||
else
|
else
|
||||||
size = g_socket_send (recv_socket, buffer, to_send, &error);
|
size = g_socket_send (recv_socket, buffer, to_send,
|
||||||
|
cancellable, &error);
|
||||||
|
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user