fix RageFileSink error handling

This commit is contained in:
Chris Danford
2004-06-06 08:34:58 +00:00
parent 349acbd121
commit b13b4fa221
2 changed files with 29 additions and 34 deletions
+8 -14
View File
@@ -6,11 +6,6 @@
void RageFileStore::StoreInitialize(const NameValuePairs &parameters) void RageFileStore::StoreInitialize(const NameValuePairs &parameters)
{ {
const char *fileName; const char *fileName;
@@ -28,7 +23,7 @@ void RageFileStore::StoreInitialize(const NameValuePairs &parameters)
unsigned long RageFileStore::MaxRetrievable() const unsigned long RageFileStore::MaxRetrievable() const
{ {
if( !m_file.IsOpen() ) if( !m_file.IsGood() )
return 0; return 0;
return m_file.GetFileSize() - m_file.Tell(); return m_file.GetFileSize() - m_file.Tell();
@@ -36,7 +31,7 @@ unsigned long RageFileStore::MaxRetrievable() const
unsigned int RageFileStore::TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel, bool blocking) unsigned int RageFileStore::TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel, bool blocking)
{ {
if( !m_file.IsOpen() ) if( !m_file.IsGood() )
{ {
transferBytes = 0; transferBytes = 0;
return 0; return 0;
@@ -48,7 +43,7 @@ unsigned int RageFileStore::TransferTo2(BufferedTransformation &target, unsigned
if (m_waiting) if (m_waiting)
goto output; goto output;
while( size && !m_file.AtEOF() ) while( size && m_file.IsGood() )
{ {
{ {
unsigned int spaceSize = 1024; unsigned int spaceSize = 1024;
@@ -66,7 +61,7 @@ output:
transferBytes += m_len; transferBytes += m_len;
} }
if (!m_file.AtEOF()) if (!m_file.IsGood() && !m_file.AtEOF())
throw ReadErr(); throw ReadErr();
return 0; return 0;
@@ -75,7 +70,7 @@ output:
unsigned int RageFileStore::CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end, const std::string &channel, bool blocking) const unsigned int RageFileStore::CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end, const std::string &channel, bool blocking) const
{ {
if( !m_file.IsOpen() ) if( !m_file.IsGood() )
return 0; return 0;
if (begin == 0 && end == 1) if (begin == 0 && end == 1)
@@ -83,16 +78,15 @@ unsigned int RageFileStore::CopyRangeTo2(BufferedTransformation &target, unsigne
int current = m_file.Tell(); int current = m_file.Tell();
byte result; byte result;
m_file.Read( &result, 1 ); m_file.Read( &result, 1 );
m_file.Seek( current );
if (m_file.AtEOF()) // GCC workaround: 2.95.2 doesn't have char_traits<char>::eof() if (m_file.AtEOF()) // GCC workaround: 2.95.2 doesn't have char_traits<char>::eof()
{ {
m_file.Seek( current );
return 0; return 0;
} }
else else
{ {
unsigned int blockedBytes = target.ChannelPut(channel, byte(result), blocking); unsigned int blockedBytes = target.ChannelPut(channel, byte(result), blocking);
begin += 1-blockedBytes; begin += 1-blockedBytes;
m_file.Seek( current );
return blockedBytes; return blockedBytes;
} }
} }
@@ -155,7 +149,7 @@ bool RageFileSink::IsolatedFlush(bool hardFlush, bool blocking)
throw Err("FileSink: output stream not opened"); throw Err("FileSink: output stream not opened");
m_file.Flush(); m_file.Flush();
if( !m_file.GetError().empty() ) if( !m_file.IsGood() )
throw WriteErr(); throw WriteErr();
return false; return false;
@@ -171,7 +165,7 @@ unsigned int RageFileSink::Put2(const byte *inString, unsigned int length, int m
if (messageEnd) if (messageEnd)
m_file.Flush(); m_file.Flush();
if( !m_file.GetError().empty() ) if( !m_file.IsGood() )
throw WriteErr(); throw WriteErr();
return 0; return 0;
+1
View File
@@ -47,6 +47,7 @@ public:
bool AtEOF() const { return m_EOF; } bool AtEOF() const { return m_EOF; }
CString GetError() const { return m_Error; } CString GetError() const { return m_Error; }
void ClearError() { m_Error = ""; } void ClearError() { m_Error = ""; }
bool IsGood() const { return IsOpen() && !AtEOF() && m_Error.empty(); }
int Tell() const { return m_FilePos; } int Tell() const { return m_FilePos; }
int Seek( int offset ); int Seek( int offset );