[glib: 10/15] Implement GOutputStream::writev_fn() and GPollableOutputStream::writev_nonblocking() for GSocketOutp
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 10/15] Implement GOutputStream::writev_fn() and GPollableOutputStream::writev_nonblocking() for GSocketOutp
- Date: Thu, 24 Jan 2019 14:43:54 +0000 (UTC)
commit e6f5a50cd77c27bb77a524c6c1239ecc88f8fda7
Author: Sebastian Dröge <sebastian centricular com>
Date: Fri Sep 14 10:33:17 2018 +0300
Implement GOutputStream::writev_fn() and GPollableOutputStream::writev_nonblocking() for
GSocketOutputStream
gio/gsocketoutputstream.c | 56 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 54 insertions(+), 2 deletions(-)
---
diff --git a/gio/gsocketoutputstream.c b/gio/gsocketoutputstream.c
index de1f4226b..fcca56efc 100644
--- a/gio/gsocketoutputstream.c
+++ b/gio/gsocketoutputstream.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]