mirror of
https://github.com/mpv-player/mpv
synced 2025-01-18 13:01:24 +00:00
stream: Make stream_write_buffer() check for short writes
None of the calling sites to stream_write_buffer were checking the return value to see if all bytes got written (nothing in current code actually calls it any more after MEncoder was removed). 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@google.com> git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32881 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
7fe2856fd9
commit
f8c32fc953
@ -28,6 +28,7 @@
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <strings.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@ -326,6 +327,7 @@ int stream_write_buffer(stream_t *s, unsigned char *buf, int len) {
|
||||
if(rd < 0)
|
||||
return -1;
|
||||
s->pos += rd;
|
||||
assert(rd == len && "stream_write_buffer(): unexpected short write");
|
||||
return rd;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len)
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -56,8 +56,16 @@ static int fill_buffer(stream_t *s, char* buffer, int max_len){
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -100,8 +100,16 @@ static int fill_buffer(stream_t *s, char* buffer, int max_len){
|
||||
}
|
||||
|
||||
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){
|
||||
|
Loading…
Reference in New Issue
Block a user