filesink/fdsink: Write 1 iovec directly without copying if there's no writev() support
authorSebastian Dröge <sebastian@centricular.com>
Fri, 20 Mar 2020 16:48:52 +0000 (18:48 +0200)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 26 Mar 2020 11:31:03 +0000 (11:31 +0000)
plugins/elements/gstelements_private.c
plugins/elements/gstelements_private.h

index b9a5517..98a6705 100644 (file)
@@ -167,7 +167,7 @@ gst_writev (gint fd, const struct iovec *iov, gint iovcnt, gsize total_bytes)
      * cases, and it's not clear how that can be reconciled with the
      * possibility of short writes, so in any case we might want to
      * simplify this later or just remove it. */
-    if (total_bytes <= FDSINK_MAX_MALLOC_SIZE) {
+    if (iovcnt > 1 && total_bytes <= FDSINK_MAX_MALLOC_SIZE) {
       gchar *mem, *p;
 
       if (total_bytes <= FDSINK_MAX_ALLOCA_SIZE)
@@ -440,7 +440,7 @@ gst_writev_buffer (GstObject * sink, gint fd, GstPoll * fdset,
 }
 
 GstFlowReturn
-gst_write_mem (GstObject * sink, gint fd, GstPoll * fdset,
+gst_writev_mem (GstObject * sink, gint fd, GstPoll * fdset,
     const guint8 * data, guint size,
     guint64 * bytes_written, guint64 skip,
     gint max_transient_error_timeout, guint64 current_position,
@@ -475,6 +475,10 @@ gst_write_mem (GstObject * sink, gint fd, GstPoll * fdset,
     if (bytes_written)
       *bytes_written += bytes_written_local;
 
+    /* All done, no need for bookkeeping */
+    if (bytes_written_local == left)
+      break;
+
     /* skip partially written vector data */
     if (bytes_written_local < left) {
       vec.iov_len -= bytes_written_local;
index 98f6942..0352943 100644 (file)
@@ -48,7 +48,7 @@ GstFlowReturn  gst_writev_buffer_list (GstObject * sink, gint fd, GstPoll * fdse
                                        gboolean * flushing);
 
 G_GNUC_INTERNAL
-GstFlowReturn  gst_write_mem          (GstObject * sink, gint fd, GstPoll * fdset,
+GstFlowReturn  gst_writev_mem         (GstObject * sink, gint fd, GstPoll * fdset,
                                        const guint8 *data, guint size,
                                        guint64 * bytes_written, guint64 skip,
                                        gint max_transient_error_timeout, guint64 current_position,