[MPlayer-cvslog] r32881 - in trunk/stream: stream.c stream_ffmpeg.c stream_file.c stream_smb.c

ranma subversion at mplayerhq.hu
Thu Feb 10 22:25:38 CET 2011


Author: ranma
Date: Thu Feb 10 22:25:38 2011
New Revision: 32881

Log:
Fix stream_write_buffer to make sure all requested bytes are written

None of the calling sites to stream_write_buffer are checking the
return value to see if all bytes got written.

This was causing (very occasionally) problems with mencoder when using output
pipes AND running under a sandbox or when being straced (ptrace is the culprit)
Theoretically this problem can happen without pipes or ptrace.

Only stream_file, stream_smb and stream_ffmpeg implement
write_buffer and ffmpeg already handles this internally.

Original patch by Sang-Uok Kum.

Signed-off-by: Tobias Diedrich <ranma at google.com>

Modified:
   trunk/stream/stream.c
   trunk/stream/stream_ffmpeg.c
   trunk/stream/stream_file.c
   trunk/stream/stream_smb.c

Modified: trunk/stream/stream.c
==============================================================================
--- trunk/stream/stream.c	Thu Feb 10 20:20:36 2011	(r32880)
+++ trunk/stream/stream.c	Thu Feb 10 22:25:38 2011	(r32881)
@@ -28,6 +28,7 @@
 #endif
 #include <fcntl.h>
 #include <strings.h>
+#include <assert.h>
 
 #include "config.h"
 
@@ -331,6 +332,7 @@ int stream_write_buffer(stream_t *s, uns
   if(rd < 0)
     return -1;
   s->pos += rd;
+  assert(rd == len && "stream_write_buffer(): unexpected short write");
   return rd;
 }
 

Modified: trunk/stream/stream_ffmpeg.c
==============================================================================
--- trunk/stream/stream_ffmpeg.c	Thu Feb 10 20:20:36 2011	(r32880)
+++ trunk/stream/stream_ffmpeg.c	Thu Feb 10 22:25:38 2011	(r32881)
@@ -33,6 +33,7 @@ static int fill_buffer(stream_t *s, char
 
 static int write_buffer(stream_t *s, char *buffer, int len)
 {
+    /* url_write retries internally on short writes and EAGAIN */
     int r = url_write(s->priv, buffer, len);
     return (r <= 0) ? -1 : r;
 }

Modified: trunk/stream/stream_file.c
==============================================================================
--- trunk/stream/stream_file.c	Thu Feb 10 20:20:36 2011	(r32880)
+++ trunk/stream/stream_file.c	Thu Feb 10 22:25:38 2011	(r32881)
@@ -57,8 +57,16 @@ static int fill_buffer(stream_t *s, char
 }
 
 static int write_buffer(stream_t *s, char* buffer, int len) {
-  int r = write(s->fd,buffer,len);
-  return (r <= 0) ? -1 : r;
+  int r;
+  int wr = 0;
+  while (wr < len) {
+    r = write(s->fd,buffer,len);
+    if (r <= 0)
+      return -1;
+    wr += r;
+    buffer += r;
+  }
+  return len;
 }
 
 static int seek(stream_t *s,off_t newpos) {

Modified: trunk/stream/stream_smb.c
==============================================================================
--- trunk/stream/stream_smb.c	Thu Feb 10 20:20:36 2011	(r32880)
+++ trunk/stream/stream_smb.c	Thu Feb 10 22:25:38 2011	(r32881)
@@ -101,8 +101,16 @@ static int fill_buffer(stream_t *s, char
 }
 
 static int write_buffer(stream_t *s, char* buffer, int len) {
-  int r = smbc_write(s->fd,buffer,len);
-  return (r <= 0) ? -1 : r;
+  int r;
+  int wr = 0;
+  while (wr < len) {
+    r = smbc_write(s->fd,buffer,len);
+    if (r <= 0)
+      return -1;
+    wr += r;
+    buffer += r;
+  }
+  return len;
 }
 
 static void close_f(stream_t *s){


More information about the MPlayer-cvslog mailing list