1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

The cFile class has been partially deprecated

This commit is contained in:
Klaus Schmidinger 2021-05-20 10:13:43 +02:00
parent c8566fab77
commit c02c081d91
3 changed files with 29 additions and 5 deletions

View File

@ -9663,7 +9663,7 @@ Video Disk Recorder Revision History
- EXPIRELATENCY now only applies to VPS timers. - EXPIRELATENCY now only applies to VPS timers.
- Deleting expired timers is now triggered immediately after the timers are modified. - Deleting expired timers is now triggered immediately after the timers are modified.
2021-05-19: 2021-05-20:
- Now using a separate fixed value for internal EPG linger time. This fixes problems with - Now using a separate fixed value for internal EPG linger time. This fixes problems with
spawned timers jumping to the next event in case Setup.EPGLinger is very small. (reported spawned timers jumping to the next event in case Setup.EPGLinger is very small. (reported
@ -9683,3 +9683,8 @@ Video Disk Recorder Revision History
plugin insists in using "using namespace std;" you can still define plugin insists in using "using namespace std;" you can still define
DISABLE_TEMPLATES_COLLIDING_WITH_STL before including any VDR header files. DISABLE_TEMPLATES_COLLIDING_WITH_STL before including any VDR header files.
- Removed 'register' from libsi/util.c to avoid a warning with ISO-C++17. - Removed 'register' from libsi/util.c to avoid a warning with ISO-C++17.
- The cFile class has been partially deprecated:
+ The handling of file handles was not thread-safe.
+ It was only actually used in svdrp.c.
+ cFile::Ready() now processes only its own file descriptor by calling FileReady()
instead of AnyFileReady().

16
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.c 5.3 2021/01/19 20:38:28 kls Exp $ * $Id: tools.c 5.4 2021/05/20 10:13:43 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -1633,8 +1633,10 @@ bool cFileNameList::Load(const char *Directory, bool DirsOnly)
// --- cFile ----------------------------------------------------------------- // --- cFile -----------------------------------------------------------------
#if DEPRECATED_CFILE
bool cFile::files[FD_SETSIZE] = { false }; bool cFile::files[FD_SETSIZE] = { false };
int cFile::maxFiles = 0; int cFile::maxFiles = 0;
#endif
cFile::cFile(void) cFile::cFile(void)
{ {
@ -1659,6 +1661,7 @@ bool cFile::Open(int FileDes)
if (FileDes >= 0) { if (FileDes >= 0) {
if (!IsOpen()) { if (!IsOpen()) {
f = FileDes; f = FileDes;
#if DEPRECATED_CFILE
if (f >= 0) { if (f >= 0) {
if (f < FD_SETSIZE) { if (f < FD_SETSIZE) {
if (f >= maxFiles) if (f >= maxFiles)
@ -1672,27 +1675,31 @@ bool cFile::Open(int FileDes)
else else
esyslog("ERROR: file descriptor %d is larger than FD_SETSIZE (%d)", f, FD_SETSIZE); esyslog("ERROR: file descriptor %d is larger than FD_SETSIZE (%d)", f, FD_SETSIZE);
} }
#endif
} }
else else
esyslog("ERROR: attempt to re-open file descriptor %d", FileDes); esyslog("ERROR: attempt to re-open file descriptor %d", FileDes);
} }
return false; return IsOpen();
} }
void cFile::Close(void) void cFile::Close(void)
{ {
if (f >= 0) { if (f >= 0) {
close(f); close(f);
#if DEPRECATED_CFILE
files[f] = false; files[f] = false;
#endif
f = -1; f = -1;
} }
} }
bool cFile::Ready(bool Wait) bool cFile::Ready(bool Wait)
{ {
return f >= 0 && AnyFileReady(f, Wait ? 1000 : 0); return f >= 0 && FileReady(f, Wait ? 1000 : 0);
} }
#if DEPRECATED_CFILE
bool cFile::AnyFileReady(int FileDes, int TimeoutMs) bool cFile::AnyFileReady(int FileDes, int TimeoutMs)
{ {
fd_set set; fd_set set;
@ -1710,6 +1717,7 @@ bool cFile::AnyFileReady(int FileDes, int TimeoutMs)
timeout.tv_usec = (TimeoutMs % 1000) * 1000; timeout.tv_usec = (TimeoutMs % 1000) * 1000;
return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && (FileDes < 0 || FD_ISSET(FileDes, &set)); return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && (FileDes < 0 || FD_ISSET(FileDes, &set));
} }
#endif
bool cFile::FileReady(int FileDes, int TimeoutMs) bool cFile::FileReady(int FileDes, int TimeoutMs)
{ {
@ -1726,6 +1734,7 @@ bool cFile::FileReady(int FileDes, int TimeoutMs)
return select(FD_SETSIZE, &set, NULL, NULL, (TimeoutMs >= 0) ? &timeout : NULL) > 0 && FD_ISSET(FileDes, &set); return select(FD_SETSIZE, &set, NULL, NULL, (TimeoutMs >= 0) ? &timeout : NULL) > 0 && FD_ISSET(FileDes, &set);
} }
#if DEPRECATED_CFILE
bool cFile::FileReadyForWriting(int FileDes, int TimeoutMs) bool cFile::FileReadyForWriting(int FileDes, int TimeoutMs)
{ {
fd_set set; fd_set set;
@ -1738,6 +1747,7 @@ bool cFile::FileReadyForWriting(int FileDes, int TimeoutMs)
timeout.tv_usec = TimeoutMs * 1000; timeout.tv_usec = TimeoutMs * 1000;
return select(FD_SETSIZE, NULL, &set, NULL, &timeout) > 0 && FD_ISSET(FileDes, &set); return select(FD_SETSIZE, NULL, &set, NULL, &timeout) > 0 && FD_ISSET(FileDes, &set);
} }
#endif
// --- cSafeFile ------------------------------------------------------------- // --- cSafeFile -------------------------------------------------------------

11
tools.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.h 5.4 2021/05/19 11:50:24 kls Exp $ * $Id: tools.h 5.5 2021/05/20 10:13:43 kls Exp $
*/ */
#ifndef __TOOLS_H #ifndef __TOOLS_H
@ -451,10 +451,15 @@ public:
struct dirent *Next(void); struct dirent *Next(void);
}; };
#ifndef DEPRECATED_CFILE
#define DEPRECATED_CFILE 0
#endif
class cFile { class cFile {
private: private:
#if DEPRECATED_CFILE
static bool files[]; static bool files[];
static int maxFiles; static int maxFiles;
#endif
int f; int f;
public: public:
cFile(void); cFile(void);
@ -465,9 +470,13 @@ public:
void Close(void); void Close(void);
bool IsOpen(void) { return f >= 0; } bool IsOpen(void) { return f >= 0; }
bool Ready(bool Wait = true); bool Ready(bool Wait = true);
#if DEPRECATED_CFILE
static bool AnyFileReady(int FileDes = -1, int TimeoutMs = 1000); static bool AnyFileReady(int FileDes = -1, int TimeoutMs = 1000);
#endif
static bool FileReady(int FileDes, int TimeoutMs = 1000); static bool FileReady(int FileDes, int TimeoutMs = 1000);
#if DEPRECATED_CFILE
static bool FileReadyForWriting(int FileDes, int TimeoutMs = 1000); static bool FileReadyForWriting(int FileDes, int TimeoutMs = 1000);
#endif
}; };
class cSafeFile { class cSafeFile {