GCancellable *cancellable,
GError **error)
{
+ return g_socket_receive_with_blocking (socket, buffer, size,
+ socket->priv->blocking,
+ cancellable, error);
+}
+
+/**
+ * g_socket_receive_with_blocking:
+ * @socket: a #GSocket
+ * @buffer: a buffer to read data into (which should be at least @size
+ * bytes long).
+ * @size: the number of bytes you want to read from the socket
+ * @blocking: whether to do blocking or non-blocking I/O
+ * @cancellable: a %GCancellable or %NULL
+ * @error: #GError for error reporting, or %NULL to ignore.
+ *
+ * This behaves exactly the same as g_socket_receive(), except that
+ * the choice of blocking or non-blocking behavior is determined by
+ * the @blocking argument rather than by @socket's properties.
+ *
+ * Returns: Number of bytes read, or -1 on error
+ *
+ * Since: 2.26
+ */
+gssize
+g_socket_receive_with_blocking (GSocket *socket,
+ gchar *buffer,
+ gsize size,
+ gboolean blocking,
+ GCancellable *cancellable,
+ GError **error)
+{
gssize ret;
g_return_val_if_fail (G_IS_SOCKET (socket) && buffer != NULL, FALSE);
while (1)
{
- if (socket->priv->blocking &&
+ if (blocking &&
!g_socket_condition_wait (socket,
G_IO_IN, cancellable, error))
return -1;
if (errsv == EINTR)
continue;
- if (socket->priv->blocking)
+ if (blocking)
{
#ifdef WSAEWOULDBLOCK
if (errsv == WSAEWOULDBLOCK)
GCancellable *cancellable,
GError **error)
{
+ return g_socket_send_with_blocking (socket, buffer, size,
+ socket->priv->blocking,
+ cancellable, error);
+}
+
+/**
+ * g_socket_send_with_blocking:
+ * @socket: a #GSocket
+ * @buffer: the buffer containing the data to send.
+ * @size: the number of bytes to send
+ * @blocking: whether to do blocking or non-blocking I/O
+ * @cancellable: a %GCancellable or %NULL
+ * @error: #GError for error reporting, or %NULL to ignore.
+ *
+ * This behaves exactly the same as g_socket_send(), except that
+ * the choice of blocking or non-blocking behavior is determined by
+ * the @blocking argument rather than by @socket's properties.
+ *
+ * Returns: Number of bytes written (which may be less than @size), or -1
+ * on error
+ *
+ * Since: 2.26
+ */
+gssize
+g_socket_send_with_blocking (GSocket *socket,
+ const gchar *buffer,
+ gsize size,
+ gboolean blocking,
+ GCancellable *cancellable,
+ GError **error)
+{
gssize ret;
g_return_val_if_fail (G_IS_SOCKET (socket) && buffer != NULL, FALSE);
while (1)
{
- if (socket->priv->blocking &&
+ if (blocking &&
!g_socket_condition_wait (socket,
G_IO_OUT, cancellable, error))
return -1;
win32_unset_event_mask (socket, FD_WRITE);
#endif
- if (socket->priv->blocking)
+ if (blocking)
{
#ifdef WSAEWOULDBLOCK
if (errsv == WSAEWOULDBLOCK)
{
GSocketInputStream *input_stream = G_SOCKET_INPUT_STREAM (stream);
- return g_socket_receive (input_stream->priv->socket, buffer, count,
- cancellable, error);
+ return g_socket_receive_with_blocking (input_stream->priv->socket,
+ buffer, count, TRUE,
+ cancellable, error);
}
static gboolean
GError *error = NULL;
gssize result;
- result = g_socket_receive (stream->priv->socket,
- stream->priv->buffer,
- stream->priv->count,
- stream->priv->cancellable,
- &error);
+ result = g_socket_receive_with_blocking (stream->priv->socket,
+ stream->priv->buffer,
+ stream->priv->count,
+ FALSE,
+ stream->priv->cancellable,
+ &error);
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
return TRUE;
{
GSocketOutputStream *onput_stream = G_SOCKET_OUTPUT_STREAM (stream);
- return g_socket_send (onput_stream->priv->socket, buffer, count,
- cancellable, error);
+ return g_socket_send_with_blocking (onput_stream->priv->socket,
+ buffer, count, TRUE,
+ cancellable, error);
}
static gboolean
GError *error = NULL;
gssize result;
- result = g_socket_send (stream->priv->socket,
- stream->priv->buffer,
- stream->priv->count,
- stream->priv->cancellable,
- &error);
+ result = g_socket_send_with_blocking (stream->priv->socket,
+ stream->priv->buffer,
+ stream->priv->count,
+ FALSE,
+ stream->priv->cancellable,
+ &error);
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
return TRUE;