[vlc-devel] commit: access_out_file: fix non-atomic write and error handling ( Rémi Denis-Courmont )
git version control
git at videolan.org
Thu Jun 12 18:52:20 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Thu Jun 12 19:54:10 2008 +0300| [ce5d66353521887ee67482d2a13178ee240216f1]
access_out_file: fix non-atomic write and error handling
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ce5d66353521887ee67482d2a13178ee240216f1
---
modules/access_output/file.c | 39 +++++++++++++++++++++++++++++----------
1 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/modules/access_output/file.c b/modules/access_output/file.c
index 9cf4d98..6399548 100644
--- a/modules/access_output/file.c
+++ b/modules/access_output/file.c
@@ -173,8 +173,13 @@ static void Close( vlc_object_t * p_this )
*****************************************************************************/
static ssize_t Read( sout_access_out_t *p_access, block_t *p_buffer )
{
- return read( (intptr_t)p_access->p_sys, p_buffer->p_buffer,
- p_buffer->i_buffer );
+ ssize_t val;
+
+ do
+ val = read( (intptr_t)p_access->p_sys, p_buffer->p_buffer,
+ p_buffer->i_buffer );
+ while (val == -1 && errno == EINTR);
+ return val;
}
/*****************************************************************************
@@ -186,15 +191,29 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
while( p_buffer )
{
- block_t *p_next = p_buffer->p_next;;
-
- i_write += write( (intptr_t)p_access->p_sys,
- p_buffer->p_buffer, p_buffer->i_buffer );
- block_Release( p_buffer );
-
- p_buffer = p_next;
+ ssize_t val = write ((intptr_t)p_access->p_sys,
+ p_buffer->p_buffer, p_buffer->i_buffer);
+ if (val == -1)
+ {
+ if (errno == EINTR)
+ continue;
+ block_ChainRelease (p_buffer);
+ return -1;
+ }
+
+ if ((size_t)val >= p_buffer->i_buffer)
+ {
+ block_t *p_next = p_buffer->p_next;
+ block_Release (p_buffer);
+ p_buffer = p_next;
+ }
+ else
+ {
+ p_buffer->p_buffer += val;
+ p_buffer->i_buffer -= val;
+ }
+ i_write += val;
}
-
return i_write;
}
More information about the vlc-devel
mailing list