1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

Fix race condition of file io

This commit is contained in:
Antti Seppälä 2007-09-16 18:04:15 +00:00
parent 8f6fe0cd2a
commit d2548271e9

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: protocolfile.c,v 1.4 2007/09/16 17:31:38 rahrenbe Exp $ * $Id: protocolfile.c,v 1.5 2007/09/16 18:04:15 ajhseppa Exp $
*/ */
#include <fcntl.h> #include <fcntl.h>
@ -78,8 +78,18 @@ int cIptvProtocolFile::Read(unsigned char* *BufferAddr)
// Rewind if EOF // Rewind if EOF
if (feof(fileStream)) if (feof(fileStream))
rewind(fileStream); rewind(fileStream);
// Read the file stream
return fread(readBuffer, sizeof(unsigned char), readBufferLen, fileStream); // Sleep before reading the file stream to prevent aggressive busy looping
cCondWait::SleepMs(50);
// This check is to prevent a race condition where file may be switched off
// during the sleep and buffers are disposed. Check here that the plugin is
// still active before accessing the buffers
if (fileActive)
return fread(readBuffer, sizeof(unsigned char), readBufferLen,
fileStream);
else
return -1;
} }
bool cIptvProtocolFile::Open(void) bool cIptvProtocolFile::Open(void)