Commit e6f5a50c authored by Sebastian Dröge's avatar Sebastian Dröge

Implement GOutputStream::writev_fn() and...

Implement GOutputStream::writev_fn() and GPollableOutputStream::writev_nonblocking() for GSocketOutputStream
parent 9ae40d98
......@@ -125,13 +125,42 @@ g_socket_output_stream_write (GOutputStream *stream,
GCancellable *cancellable,
GError **error)
{
GSocketOutputStream *onput_stream = G_SOCKET_OUTPUT_STREAM (stream);
GSocketOutputStream *output_stream = G_SOCKET_OUTPUT_STREAM (stream);
return g_socket_send_with_blocking (onput_stream->priv->socket,
return g_socket_send_with_blocking (output_stream->priv->socket,
buffer, count, TRUE,
cancellable, error);
}
static gboolean
g_socket_output_stream_writev (GOutputStream *stream,
const GOutputVector *vectors,
gsize n_vectors,
gsize *bytes_written,
GCancellable *cancellable,
GError **error)
{
GSocketOutputStream *output_stream = G_SOCKET_OUTPUT_STREAM (stream);
GPollableReturn res;
/* Clamp the number of vectors if more given than we can write in one go.
* The caller has to handle short writes anyway.
*/
if (n_vectors > G_MAXINT)
n_vectors = G_MAXINT;
res = g_socket_send_message_with_timeout (output_stream->priv->socket, NULL,
vectors, n_vectors,
NULL, 0, G_SOCKET_MSG_NONE,
-1, bytes_written,
cancellable, error);
/* we have a non-zero timeout so this can't happen */
g_assert (res != G_POLLABLE_RETURN_WOULD_BLOCK);
return res == G_POLLABLE_RETURN_OK;
}
static gboolean
g_socket_output_stream_pollable_is_writable (GPollableOutputStream *pollable)
{
......@@ -153,6 +182,27 @@ g_socket_output_stream_pollable_write_nonblocking (GPollableOutputStream *polla
NULL, error);
}
static GPollableReturn
g_socket_output_stream_pollable_writev_nonblocking (GPollableOutputStream *pollable,
const GOutputVector *vectors,
gsize n_vectors,
gsize *bytes_written,
GError **error)
{
GSocketOutputStream *output_stream = G_SOCKET_OUTPUT_STREAM (pollable);
/* Clamp the number of vectors if more given than we can write in one go.
* The caller has to handle short writes anyway.
*/
if (n_vectors > G_MAXINT)
n_vectors = G_MAXINT;
return g_socket_send_message_with_timeout (output_stream->priv->socket,
NULL, vectors, n_vectors,
NULL, 0, G_SOCKET_MSG_NONE, 0,
bytes_written, NULL, error);
}
static GSource *
g_socket_output_stream_pollable_create_source (GPollableOutputStream *pollable,
GCancellable *cancellable)
......@@ -191,6 +241,7 @@ g_socket_output_stream_class_init (GSocketOutputStreamClass *klass)
gobject_class->set_property = g_socket_output_stream_set_property;
goutputstream_class->write_fn = g_socket_output_stream_write;
goutputstream_class->writev_fn = g_socket_output_stream_writev;
g_object_class_install_property (gobject_class, PROP_SOCKET,
g_param_spec_object ("socket",
......@@ -214,6 +265,7 @@ g_socket_output_stream_pollable_iface_init (GPollableOutputStreamInterface *ifac
iface->is_writable = g_socket_output_stream_pollable_is_writable;
iface->create_source = g_socket_output_stream_pollable_create_source;
iface->write_nonblocking = g_socket_output_stream_pollable_write_nonblocking;
iface->writev_nonblocking = g_socket_output_stream_pollable_writev_nonblocking;
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment